Browse Source

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 năm trước cách đây
mục cha
commit
53d14c718a
1 tập tin đã thay đổi với 4 bổ sung1 xóa
  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);