Re: [PATCH 3/3] cgroup: fix strstrip() abuse
From: Paul Menage
Date: Fri Oct 02 2009 - 18:02:01 EST
On Fri, Oct 2, 2009 at 1:41 AM, KOSAKI Motohiro
<kosaki.motohiro@xxxxxxxxxxxxxx> wrote:
> cgroup_write_X64() and cgroup_write_string() ignore the return
> value of strstrip().
> it makes small inconsistent behavior.
>
> example:
> =========================
> # cd /mnt/cgroup/hoge
> # cat memory.swappiness
> 60
> # echo "59 " > memory.swappiness
> # cat memory.swappiness
> 59
> # echo " 58" > memory.swappiness
> bash: echo: write error: Invalid argument
>
>
> This patch fixes it.
>
> Cc: Li Zefan <lizf@xxxxxxxxxxxxxx>
> Cc: Paul Menage <menage@xxxxxxxxxx>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxxxxxxx>
Acked-by: Paul Menage <menage@xxxxxxxxxx>
Thanks - although I think I'd s/abuse/misuse/ in the description.
> ---
> kernel/cgroup.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> Index: b/kernel/cgroup.c
> ===================================================================
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -1710,14 +1710,13 @@ static ssize_t cgroup_write_X64(struct c
> return -EFAULT;
>
> buffer[nbytes] = 0; /* nul-terminate */
> - strstrip(buffer);
> if (cft->write_u64) {
> - u64 val = simple_strtoull(buffer, &end, 0);
> + u64 val = simple_strtoull(strstrip(buffer), &end, 0);
> if (*end)
> return -EINVAL;
> retval = cft->write_u64(cgrp, cft, val);
> } else {
> - s64 val = simple_strtoll(buffer, &end, 0);
> + s64 val = simple_strtoll(strstrip(buffer), &end, 0);
> if (*end)
> return -EINVAL;
> retval = cft->write_s64(cgrp, cft, val);
> @@ -1753,8 +1752,7 @@ static ssize_t cgroup_write_string(struc
> }
>
> buffer[nbytes] = 0; /* nul-terminate */
> - strstrip(buffer);
> - retval = cft->write_string(cgrp, cft, buffer);
> + retval = cft->write_string(cgrp, cft, strstrip(buffer));
> if (!retval)
> retval = nbytes;
> out:
>
>
>
--
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/