Skip to content

Commit

Permalink
lsattr: fix potential 32-bit integer overflow warning
Browse files Browse the repository at this point in the history
This can't happen in practice due to MAXPATHNAMELEN constraints, but
gcc is too dumb to know that.

Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
tytso committed Feb 26, 2025
1 parent 181d1c2 commit a0ae27b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions misc/lsattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ static int lsattr_dir_proc (const char * dir_name, struct dirent * de,
{
STRUCT_STAT st;
char *path;
int dir_len = strlen(dir_name);
size_t dir_len = strlen(dir_name), name_len = strlen (de->d_name);

path = malloc(dir_len + strlen (de->d_name) + 2);
if ((dir_len > 1024 * 1024 * 1024) ||
(name_len > 1024 * 1024 * 1024))
return -1;

path = malloc(dir_len + name_len + 2);
if (!path) {
fputs(_("Couldn't allocate path variable in lsattr_dir_proc\n"),
stderr);
Expand Down

0 comments on commit a0ae27b

Please sign in to comment.