Skip to content

Commit bce9332

Browse files
committed
proc: proc_skip_spaces() shouldn't think it is working on C strings
proc_skip_spaces() seems to think it is working on C strings, and ends up being just a wrapper around skip_spaces() with a really odd calling convention. Instead of basing it on skip_spaces(), it should have looked more like proc_skip_char(), which really is the exact same function (except it skips a particular character, rather than whitespace). So use that as inspiration, odd coding and all. Now the calling convention actually makes sense and works for the intended purpose. Reported-and-tested-by: Kyle Zeng <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e6cfaf3 commit bce9332

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

kernel/sysctl.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,14 @@ int proc_dostring(struct ctl_table *table, int write,
267267
ppos);
268268
}
269269

270-
static size_t proc_skip_spaces(char **buf)
270+
static void proc_skip_spaces(char **buf, size_t *size)
271271
{
272-
size_t ret;
273-
char *tmp = skip_spaces(*buf);
274-
ret = tmp - *buf;
275-
*buf = tmp;
276-
return ret;
272+
while (*size) {
273+
if (!isspace(**buf))
274+
break;
275+
(*size)--;
276+
(*buf)++;
277+
}
277278
}
278279

279280
static void proc_skip_char(char **buf, size_t *size, const char v)
@@ -520,7 +521,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
520521
bool neg;
521522

522523
if (write) {
523-
left -= proc_skip_spaces(&p);
524+
proc_skip_spaces(&p, &left);
524525

525526
if (!left)
526527
break;
@@ -547,7 +548,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
547548
if (!write && !first && left && !err)
548549
proc_put_char(&buffer, &left, '\n');
549550
if (write && !err && left)
550-
left -= proc_skip_spaces(&p);
551+
proc_skip_spaces(&p, &left);
551552
if (write && first)
552553
return err ? : -EINVAL;
553554
*lenp -= left;
@@ -589,7 +590,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
589590
if (left > PAGE_SIZE - 1)
590591
left = PAGE_SIZE - 1;
591592

592-
left -= proc_skip_spaces(&p);
593+
proc_skip_spaces(&p, &left);
593594
if (!left) {
594595
err = -EINVAL;
595596
goto out_free;
@@ -609,7 +610,7 @@ static int do_proc_douintvec_w(unsigned int *tbl_data,
609610
}
610611

611612
if (!err && left)
612-
left -= proc_skip_spaces(&p);
613+
proc_skip_spaces(&p, &left);
613614

614615
out_free:
615616
if (err)
@@ -1074,7 +1075,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
10741075
if (write) {
10751076
bool neg;
10761077

1077-
left -= proc_skip_spaces(&p);
1078+
proc_skip_spaces(&p, &left);
10781079
if (!left)
10791080
break;
10801081

@@ -1103,7 +1104,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
11031104
if (!write && !first && left && !err)
11041105
proc_put_char(&buffer, &left, '\n');
11051106
if (write && !err)
1106-
left -= proc_skip_spaces(&p);
1107+
proc_skip_spaces(&p, &left);
11071108
if (write && first)
11081109
return err ? : -EINVAL;
11091110
*lenp -= left;

0 commit comments

Comments
 (0)