Sfoglia il codice sorgente

fix for segfault when no nrpe_user specified issue#146

Bryan Heden 8 anni fa
parent
commit
cebaf156d5
2 ha cambiato i file con 22 aggiunte e 11 eliminazioni
  1. 7 0
      CHANGELOG.md
  2. 15 11
      src/utils.c

+ 7 - 0
CHANGELOG.md

@@ -1,6 +1,13 @@
 NRPE Changelog
 ==============
 
+[3.2.1]
+-------------------
+**FIXES**
+* Change seteuid error messages to warning/debug (Bryan Heden)
+* Fix segfault when no nrpe_user is specified (Stephen Smoogen, Bryan Heden)
+
+
 [3.2.0](https://github.com/NagiosEnterprises/nrpe/releases/tag/nrpe-3.2.0) - 2017-06-26
 ---------------------------------------------------------------------------------------
 **ENHANCEMENTS**

+ 15 - 11
src/utils.c

@@ -328,17 +328,21 @@ int clean_environ(const char *keep_env_vars, const char *nrpe_user)
 
 	setenv("PATH", path, 1);
 	setenv("IFS", " \t\n", 1);
-	setenv("LOGNAME", nrpe_user, 0);
-	setenv("USER", nrpe_user, 0);
-
-	pw = (struct passwd *)getpwnam(nrpe_user);
-	if (pw == NULL) {
-		char	*end = NULL;
-		uid_t	uid = strtol(nrpe_user, &end, 10);
-		if (uid > 0)
-			pw = (struct passwd *)getpwuid(uid);
-		if (pw == NULL || *end != '\0')
-			return OK;
+
+	if (nrpe_user != NULL) {
+		
+		setenv("LOGNAME", nrpe_user, 0);
+		setenv("USER", nrpe_user, 0);
+
+		pw = (struct passwd *)getpwnam(nrpe_user);
+		if (pw == NULL) {
+			char	*end = NULL;
+			uid_t	uid = strtol(nrpe_user, &end, 10);
+			if (uid > 0)
+				pw = (struct passwd *)getpwuid(uid);
+			if (pw == NULL || *end != '\0')
+				return OK;
+		}
 	}
 
 	setenv("HOME", pw->pw_dir, 0);