btrfs-progs: use local path buffer in path_is_in_dir()

Reported by 'gcc -fanalyzer':
common/path-utils.c:401:16: warning: use of possibly-NULL ‘curr_dir’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument]

There's an unhandled strdup() call in path_is_in_dir() so tmp could be
potentially NULL and passed down in the function. This is in the path
utilities so we assume the buffer is a path and can use the safe copy.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2024-04-04 00:29:01 +02:00
parent 9c156ab9ca
commit 2cd46f3935

View File

@ -394,10 +394,12 @@ int path_is_dir(const char *path)
*/
int path_is_in_dir(const char *parent, const char *path)
{
char *tmp = strdup(path);
char tmp[PATH_MAX];
char *curr_dir = tmp;
int ret;
strncpy_null(tmp, path);
while (strcmp(parent, curr_dir) != 0) {
if (strcmp(curr_dir, "/") == 0) {
ret = 0;
@ -408,7 +410,6 @@ int path_is_in_dir(const char *parent, const char *path)
ret = 1;
out:
free(tmp);
return ret;
}