sysctl: Don't crash file fopen fails
The commit referenced below put a setvbuf() before checking what
fopen() returned. If the file could not be opened then the file
handle was NULL at setvbuf() crashed.
setvbuf() is now called after checking what fopen() returns and only
when it was successful.
References:
procps-ng/procps#76
commit 58ae084c27
This commit is contained in:
6
sysctl.c
6
sysctl.c
@@ -222,9 +222,6 @@ static int ReadSetting(const char *restrict const name)
|
||||
|
||||
fp = fopen(tmpname, "r");
|
||||
|
||||
if (iobuf)
|
||||
setvbuf(fp, iobuf, _IOFBF, IOBUFSIZ);
|
||||
|
||||
if (!fp) {
|
||||
switch (errno) {
|
||||
case ENOENT:
|
||||
@@ -246,6 +243,9 @@ static int ReadSetting(const char *restrict const name)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (iobuf)
|
||||
setvbuf(fp, iobuf, _IOFBF, IOBUFSIZ);
|
||||
|
||||
errno = 0;
|
||||
if (fgets(inbuf, sizeof inbuf - 1, fp)) {
|
||||
/* this loop is required, see
|
||||
|
Reference in New Issue
Block a user