sysctl: avoid crash when -p file has unexpected input

Commit e01765d30b added is_deprecated(), which
crashed when user had input without without /proc/sys/ subdirectory.  The below
should illustrate how exactly the bug got to be trickered.

$ cat ~/foo
cause = crash
$ ./sysctl -p ~/foo
Segmentation fault

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2012-05-03 20:08:27 +02:00
parent e2987888e2
commit b2c08d1d41

View File

@ -359,6 +359,8 @@ static int WriteSetting(const char *setting)
const char *equals;
char *tmpname;
char *outname;
char *last_dot;
FILE *fp;
struct stat ts;
@ -396,7 +398,8 @@ static int WriteSetting(const char *setting)
outname[equals - name] = 0;
/* change / to . */
slashdot(outname, '/', '.');
if(is_deprecated(strrchr(outname, '.') + 1)) {
last_dot = strrchr(outname, '.');
if (last_dot != NULL && is_deprecated(last_dot + 1)) {
xwarnx(_("%s is deprecated, value not set"), outname);
goto out;
}