• Oleg Nesterov's avatar
    argv_split(): teach it to handle mutable strings · 095d141b
    Oleg Nesterov authored
    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: 's avatarOleg Nesterov <oleg@redhat.com>
    Cc: Andi Kleen <andi@firstfloor.org>
    Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
    095d141b
argv_split.c 2.07 KB