From: Sami Kerola Date: Thu, 3 May 2012 18:08:27 +0000 (+0200) Subject: sysctl: avoid crash when -p file has unexpected input X-Git-Tag: v3.3.3~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2c08d1d412aafed706fb829c24ec67feefa4b4e;p=procps-ng sysctl: avoid crash when -p file has unexpected input Commit e01765d30b7c4767868d5379fbfb36d1dc15eba4 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 --- diff --git a/sysctl.c b/sysctl.c index 92351706..cfe13985 100644 --- a/sysctl.c +++ b/sysctl.c @@ -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; }