Skip to content

Commit e6cfaf3

Browse files
committed
proc: avoid integer type confusion in get_proc_long
proc_get_long() is passed a size_t, but then assigns it to an 'int' variable for the length. Let's not do that, even if our IO paths are limited to MAX_RW_COUNT (exactly because of these kinds of type errors). So do the proper test in the rigth type. Reported-by: Kyle Zeng <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b52be55 commit e6cfaf3

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

kernel/sysctl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,12 @@ static int proc_get_long(char **buf, size_t *size,
342342
unsigned long *val, bool *neg,
343343
const char *perm_tr, unsigned perm_tr_len, char *tr)
344344
{
345-
int len;
346345
char *p, tmp[TMPBUFLEN];
346+
ssize_t len = *size;
347347

348-
if (!*size)
348+
if (len <= 0)
349349
return -EINVAL;
350350

351-
len = *size;
352351
if (len > TMPBUFLEN - 1)
353352
len = TMPBUFLEN - 1;
354353

0 commit comments

Comments
 (0)