Bug 8084 - sysctl derefs uninitialized variable, uses feof inappropriately
Summary: sysctl derefs uninitialized variable, uses feof inappropriately
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: procps
Version: 6.1
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Michael K. Johnson
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 1999-12-31 15:16 UTC by Jonathan Kamens
Modified: 2008-05-01 15:37 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2000-02-14 12:26:54 UTC

Attachments (Terms of Use)
still broken; here's patch for procps-2.0.6-2 (320 bytes, patch)
2000-02-14 12:26 UTC, Jonathan Kamens
no flags Details | Diff

Description Jonathan Kamens 1999-12-31 15:16:01 UTC
Sysctl will randomly decide not to load a config file when "sysctl -p" is
specified, depending on what's in memory, because it checks the wrong
variable to see if it's null.

Furthermore, it will sometimes incorrectly report an invalid line in the
file, because it uses feof() to check for EOF when feof() may not be true,
even at EOF, if stdio hasn't yet realized that it has read everything.

The patch below fixes both of these problem.

--- sysctl.c.orig	Fri Dec 31 10:09:36 1999
+++ sysctl.c	Fri Dec 31 10:11:56 1999
@@ -183,13 +183,12 @@
 int n = 0;
 char *name, *value;

-   if (!name || ((fp = fopen(filename, "r")) == NULL)) {
+   if (!filename || ((fp = fopen(filename, "r")) == NULL)) {
       fprintf(stderr, ERR_PRELOAD_FILE, filename);
       return 0;
    } /* endif */

-   while (!feof(fp)) {
-      fgets(oneline, 256, fp);
+   while (fgets(oneline, 256, fp)) {
       oneline[256] = 0;
       t = StripLeadingAndTrailingSpaces(oneline);

Comment 1 Jonathan Kamens 2000-02-14 12:26:59 UTC
Created attachment 116 [details]
still broken; here's patch for procps-2.0.6-2

Comment 2 Michael K. Johnson 2000-07-31 20:09:26 UTC
This was fixed in procps-2.0.7

Note You need to log in before you can comment on or make changes to this bug.