Re: [PATCH] sched: fix strncmp operation

From: Andrew Morton
Date: Thu Jan 06 2011 - 18:48:52 EST


On Thu, 6 Jan 2011 20:58:12 +0800
Hillf Danton <dhillf@xxxxxxxxx> wrote:

> One of the operands, buf, is incorrect, since it is stripped and the
> correct address for subsequent string comparing could change if
> leading white spaces, if any, are removed from buf.
>
> It is fixed by replacing buf with cmp.
>
> Signed-off-by: Hillf Danton <dhillf@xxxxxxxxx>
> ---
>
> --- a/kernel/sched.c 2010-11-01 19:54:12.000000000 +0800
> +++ b/kernel/sched.c 2011-01-06 20:52:02.000000000 +0800
> @@ -751,7 +751,7 @@ sched_feat_write(struct file *filp, cons
> buf[cnt] = 0;
> cmp = strstrip(buf);
>
> - if (strncmp(buf, "NO_", 3) == 0) {
> + if (strncmp(cmp, "NO_", 3) == 0) {
> neg = 1;
> cmp += 3;
> }

Just remove the strstrip(), I'd say. The kernel practically never
strips leading whitespace from sysfs input, so why do it here?


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/