Przeglądaj źródła

lib/parse_ini.c - check inifile before access

Added check to verifiy inifile was not null post fopen(). Should be caught by other checks though.
Spenser Reinhardt 11 lat temu
rodzic
commit
53d14c718a
1 zmienionych plików z 4 dodań i 1 usunięć
  1. 4 1
      lib/parse_ini.c

+ 4 - 1
lib/parse_ini.c

@@ -141,12 +141,15 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){
                                 die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file."), strerror(errno));
                 }
 
+		/* before attempting access, let's make sure inifile is not null, this should never be the case though */
+		if (inifile == NULL)
+			die(STATE_UNKNOWN, "%s %s\n", _("Can't read config file:"), strerror(errno));
                 /* inifile points to an open FILE our ruid/rgid can access, parse its contents. */
                 if (read_defaults(inifile, i.stanza, &defaults) == FALSE)
                         die(STATE_UNKNOWN,"%s%s%s%s'\n", _("Invalid section '"), i.stanza, _("' in config file '"), i.file);
 
                 if (inifile != stdin) fclose(inifile);
-        }
+        } 
 
 	if (i.file != NULL) {
 		free(i.file);