Skip to content

Commit

Permalink
ksmbd-tools: handle unset ret
Browse files Browse the repository at this point in the history
If g_mapped_file_get_length returns 0 or SIZE_MAX, the loop does not get
executed and ret does not get set

Move the assignment out of the loop and change to while loop.

Found with GCC's -fanalyzer.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jan 9, 2025
1 parent bafd28e commit 20b61e8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tools/config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <glib.h>
#include <string.h>
#include <stdint.h>
#include <glib/gstdio.h>
#include <sys/stat.h>
#include <sys/types.h>
Expand Down Expand Up @@ -238,9 +239,13 @@ static int __mmap_parse_file(const char *path, process_entry_fn *process_entry)
goto out_unref;
}

for (len = g_mapped_file_get_length(file);
len > 0 && len != (size_t)-1;
len -= delim - contents + 1, contents = delim + 1) {
len = g_mapped_file_get_length(file);
if (len == 0 || len == SIZE_MAX) {
ret = -EINVAL;
goto out_close;
}

while (len > 0) {
g_autofree char *entry = NULL;

delim = memchr(contents, '\n', len) ?: contents + len;
Expand All @@ -250,6 +255,7 @@ static int __mmap_parse_file(const char *path, process_entry_fn *process_entry)
process_entry == process_subauth_entry ||
process_entry == process_lock_entry)
goto out_unref;
len -= delim - contents + 1, contents = delim + 1;
}

out_unref:
Expand Down

0 comments on commit 20b61e8

Please sign in to comment.