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:
parent
e2987888e2
commit
b2c08d1d41
5
sysctl.c
5
sysctl.c
@ -359,6 +359,8 @@ static int WriteSetting(const char *setting)
|
|||||||
const char *equals;
|
const char *equals;
|
||||||
char *tmpname;
|
char *tmpname;
|
||||||
char *outname;
|
char *outname;
|
||||||
|
char *last_dot;
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct stat ts;
|
struct stat ts;
|
||||||
|
|
||||||
@ -396,7 +398,8 @@ static int WriteSetting(const char *setting)
|
|||||||
outname[equals - name] = 0;
|
outname[equals - name] = 0;
|
||||||
/* change / to . */
|
/* change / to . */
|
||||||
slashdot(outname, '/', '.');
|
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);
|
xwarnx(_("%s is deprecated, value not set"), outname);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user