Skip to content

Commit d631094

Browse files
atenartPaolo Abeni
authored andcommitted
net: sysctl: remove always-true condition
Before adding a new line at the end of the temporary buffer in dump_cpumask, a length check is performed to ensure there is space for it. len = min(sizeof(kbuf) - 1, *lenp); len = scnprintf(kbuf, len, ...); if (len < *lenp) kbuf[len++] = '\n'; Note that the check is currently logically wrong, the written length is compared against the output buffer, not the temporary one. However this has no consequence as this is always true, even if fixed: scnprintf includes a null char at the end of the buffer but the returned length do not include it and there is always space for overriding it with a newline. Remove the condition. Signed-off-by: Antoine Tenart <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 6886c14 commit d631094

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/core/sysctl_net_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
6969
return;
7070
}
7171

72-
if (len < *lenp)
73-
kbuf[len++] = '\n';
72+
/* scnprintf writes a trailing null char not counted in the returned
73+
* length, override it with a newline.
74+
*/
75+
kbuf[len++] = '\n';
7476
memcpy(buffer, kbuf, len);
7577
*lenp = len;
7678
*ppos += len;

0 commit comments

Comments
 (0)