]> git.karo-electronics.de Git - karo-tx-linux.git/commit
argv_split(): teach it to handle mutable strings
authorOleg Nesterov <oleg@redhat.com>
Wed, 20 Mar 2013 04:07:45 +0000 (15:07 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 21 Mar 2013 05:34:03 +0000 (16:34 +1100)
commitffb0580ab1823868a81607e2b5db511736cf9cb2
tree77ec2bfa75be06c5a08493b0f7623038e252f2f6
parent4076b8b2788c457f6bd0e0bb6070879faa10477f
argv_split(): teach it to handle mutable strings

argv_split() allocates argv[count_argc(str)] array and assumes that it
will find the same number of arguments later.  This is obviously wrong if
this string can be changed, say, by sysctl.

With this patch argv_split() kstrndup's the whole string and does not
split it, we simply replace the spaces with zeroes and keep the allocated
memory in argv[-1] for argv_free(arg).

We do not use argv[0] because:

- str can be all-spaces or empty. In fact this case is fine,
  we could kfree() it before return, but:

- str can have a space at the start, and we can not rely on
  kstrndup(skip_spaces(str)) because it can equally race if
  this string is mutable.

Also, simplify count_argc() and kill the no longer used skip_arg().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/argv_split.c