Blame SOURCES/pam-1.3.1-coverity.patch

73cfcf
diff --git a/libpam/pam_handlers.c b/libpam/pam_handlers.c
73cfcf
index 106ef7c..b2e94c7 100644
73cfcf
--- a/libpam/pam_handlers.c
73cfcf
+++ b/libpam/pam_handlers.c
73cfcf
@@ -282,7 +282,6 @@ _pam_open_config_file(pam_handle_t *pamh
73cfcf
 {
73cfcf
     char *p;
73cfcf
     FILE *f;
73cfcf
-    int err = 0;
73cfcf
 
73cfcf
     /* Absolute path */
73cfcf
     if (service[0] == '/') {
73cfcf
diff --git a/libpam_misc/misc_conv.c b/libpam_misc/misc_conv.c
73cfcf
index be53f34..07dce36 100644
73cfcf
--- a/libpam_misc/misc_conv.c
73cfcf
+++ b/libpam_misc/misc_conv.c
73cfcf
@@ -211,7 +211,7 @@ static int read_string(int echo, const char *prompt, char **retstr)
73cfcf
 		    line[nc] = '\0';
73cfcf
 		}
73cfcf
 		*retstr = strdup(line);
73cfcf
-		_pam_overwrite(line);
73cfcf
+		_pam_overwrite_n(line, sizeof(line));
73cfcf
 		if (!*retstr) {
73cfcf
 		    D(("no memory for response string"));
73cfcf
 		    nc = -1;
73cfcf
@@ -244,7 +244,7 @@ static int read_string(int echo, const char *prompt, char **retstr)
73cfcf
     D(("the timer appears to have expired"));
73cfcf
 
73cfcf
     *retstr = NULL;
73cfcf
-    _pam_overwrite(line);
73cfcf
+    _pam_overwrite_n(line, sizeof(line));
73cfcf
 
73cfcf
  cleanexit:
73cfcf
 
73cfcf
diff --git a/modules/pam_access/pam_access.c b/modules/pam_access/pam_access.c
73cfcf
index 80d885d..3801862 100644
73cfcf
--- a/modules/pam_access/pam_access.c
73cfcf
+++ b/modules/pam_access/pam_access.c
73cfcf
@@ -806,7 +806,7 @@ pam_sm_authenticate (pam_handle_t *pamh, int flags UNUSED,
73cfcf
     const char *user=NULL;
73cfcf
     const void *void_from=NULL;
73cfcf
     const char *from;
73cfcf
-    const char const *default_config = PAM_ACCESS_CONFIG;
73cfcf
+    const char * const default_config = PAM_ACCESS_CONFIG;
73cfcf
     struct passwd *user_pw;
73cfcf
     char hostname[MAXHOSTNAMELEN + 1];
73cfcf
     int rv;
73cfcf
diff --git a/modules/pam_limits/pam_limits.c b/modules/pam_limits/pam_limits.c
73cfcf
index 4bc4ae7..f8476b4 100644
73cfcf
--- a/modules/pam_limits/pam_limits.c
73cfcf
+++ b/modules/pam_limits/pam_limits.c
73cfcf
@@ -342,7 +342,7 @@ static const char *lnames[RLIM_NLIMITS] = {
73cfcf
 #endif
73cfcf
 };
73cfcf
 
73cfcf
-static int str2rlimit(char *name) {
73cfcf
+static int str2rlimit(const char *name) {
73cfcf
     int i;
73cfcf
     if (!name || *name == '\0')
73cfcf
         return -1;
73cfcf
@@ -352,7 +352,7 @@ static int str2rlimit(char *name) {
73cfcf
     return -1;
73cfcf
 }
73cfcf
 
73cfcf
-static rlim_t str2rlim_t(char *value) {
73cfcf
+static rlim_t str2rlim_t(const char *value) {
73cfcf
     unsigned long long rlimit = 0;
73cfcf
 
73cfcf
     if (!value) return (rlim_t)rlimit;
73cfcf
@@ -384,7 +384,7 @@ static void parse_kernel_limits(pam_handle_t *pamh, struct pam_limit_s *pl, int
73cfcf
     FILE *limitsfile;
73cfcf
     const char *proclimits = "/proc/1/limits";
73cfcf
     char line[256];
73cfcf
-    char *units, *hard, *soft, *name;
73cfcf
+    const char *units, *hard, *soft, *name;
73cfcf
 
73cfcf
     if (!(limitsfile = fopen(proclimits, "r"))) {
73cfcf
         pam_syslog(pamh, LOG_WARNING, "Could not read %s (%s), using PAM defaults", proclimits, strerror(errno));
73cfcf
diff --git a/modules/pam_loginuid/pam_loginuid.c b/modules/pam_loginuid/pam_loginuid.c
73cfcf
index 96bfd98..66d202c 100644
73cfcf
--- a/modules/pam_loginuid/pam_loginuid.c
73cfcf
+++ b/modules/pam_loginuid/pam_loginuid.c
73cfcf
@@ -64,7 +64,7 @@ static int set_loginuid(pam_handle_t *pamh, uid_t uid)
73cfcf
 	fd = open("/proc/self/uid_map", O_RDONLY);
73cfcf
 	if (fd >= 0) {
73cfcf
 		count = pam_modutil_read(fd, uid_map, sizeof(uid_map));
73cfcf
-		if (strncmp(uid_map, host_uid_map, count) != 0)
73cfcf
+		if (count <= 0 || strncmp(uid_map, host_uid_map, count) != 0)
73cfcf
 			rc = PAM_IGNORE;
73cfcf
 		close(fd);
73cfcf
 	}
73cfcf
diff --git a/modules/pam_mkhomedir/mkhomedir_helper.c b/modules/pam_mkhomedir/mkhomedir_helper.c
73cfcf
index 9e204c1..4b8d6b7 100644
73cfcf
--- a/modules/pam_mkhomedir/mkhomedir_helper.c
73cfcf
+++ b/modules/pam_mkhomedir/mkhomedir_helper.c
73cfcf
@@ -232,6 +232,8 @@ create_homedir(const struct passwd *pwd,
73cfcf
       {
73cfcf
          pam_syslog(NULL, LOG_DEBUG,
73cfcf
 		    "unable to open or stat src file %s: %m", newsource);
73cfcf
+         if (srcfd >= 0)
73cfcf
+            close(srcfd);
73cfcf
          closedir(d);
73cfcf
 
73cfcf
 #ifndef PATH_MAX
73cfcf
diff --git a/modules/pam_namespace/pam_namespace.c b/modules/pam_namespace/pam_namespace.c
73cfcf
index f541f89..85f5efa 100644
73cfcf
--- a/modules/pam_namespace/pam_namespace.c
73cfcf
+++ b/modules/pam_namespace/pam_namespace.c
73cfcf
@@ -1418,6 +1418,7 @@ static int create_instance(struct polydir_s *polyptr, char *ipath, struct stat *
73cfcf
     if (fstat(fd, &newstatbuf) < 0) {
73cfcf
         pam_syslog(idata->pamh, LOG_ERR, "Error stating %s, %m",
73cfcf
 		ipath);
73cfcf
+	close(fd);
73cfcf
 	rmdir(ipath);
73cfcf
         return PAM_SESSION_ERR;
73cfcf
     }
73cfcf
diff --git a/modules/pam_pwhistory/opasswd.c b/modules/pam_pwhistory/opasswd.c
73cfcf
index e6cf346..813f579 100644
73cfcf
--- a/modules/pam_pwhistory/opasswd.c
73cfcf
+++ b/modules/pam_pwhistory/opasswd.c
73cfcf
@@ -326,6 +326,9 @@ save_old_pass (pam_handle_t *pamh, const char *user, uid_t uid,
73cfcf
 	n = strlen (buf);
73cfcf
 #endif /* HAVE_GETLINE / HAVE_GETDELIM */
73cfcf
 
73cfcf
+	if (n < 1)
73cfcf
+	  break;
73cfcf
+
73cfcf
 	cp = buf;
73cfcf
 	save = strdup (buf); /* Copy to write the original data back.  */
73cfcf
 	if (save == NULL)
73cfcf
@@ -336,9 +339,6 @@ save_old_pass (pam_handle_t *pamh, const char *user, uid_t uid,
73cfcf
 	    goto error_opasswd;
73cfcf
           }
73cfcf
 
73cfcf
-	if (n < 1)
73cfcf
-	  break;
73cfcf
-
73cfcf
 	tmp = strchr (cp, '#');  /* remove comments */
73cfcf
 	if (tmp)
73cfcf
 	  *tmp = '\0';
73cfcf
diff --git a/modules/pam_rootok/pam_rootok.c b/modules/pam_rootok/pam_rootok.c
73cfcf
index 17baabe..a9d9140 100644
73cfcf
--- a/modules/pam_rootok/pam_rootok.c
73cfcf
+++ b/modules/pam_rootok/pam_rootok.c
73cfcf
@@ -66,14 +66,17 @@ log_callback (int type, const char *fmt, ...)
73cfcf
     int audit_fd;
73cfcf
     va_list ap;
73cfcf
 
73cfcf
-    va_start(ap, fmt);
73cfcf
 #ifdef HAVE_LIBAUDIT
73cfcf
     audit_fd = audit_open();
73cfcf
 
73cfcf
     if (audit_fd >= 0) {
73cfcf
 	char *buf;
73cfcf
+	int ret;
73cfcf
 
73cfcf
-	if (vasprintf (&buf, fmt, ap) < 0)
73cfcf
+	va_start(ap, fmt);
73cfcf
+	ret = vasprintf (&buf, fmt, ap);
73cfcf
+	va_end(ap);
73cfcf
+	if (ret < 0)
73cfcf
 		return 0;
73cfcf
 	audit_log_user_avc_message(audit_fd, AUDIT_USER_AVC, buf, NULL, NULL,
73cfcf
 				   NULL, 0);
73cfcf
@@ -83,6 +86,7 @@ log_callback (int type, const char *fmt, ...)
73cfcf
     }
73cfcf
 
73cfcf
 #endif
73cfcf
+    va_start(ap, fmt);
73cfcf
     vsyslog (LOG_USER | LOG_INFO, fmt, ap);
73cfcf
     va_end(ap);
73cfcf
     return 0;
73cfcf
diff --git a/modules/pam_sepermit/pam_sepermit.c b/modules/pam_sepermit/pam_sepermit.c
73cfcf
index c653290..f37af0f 100644
73cfcf
--- a/modules/pam_sepermit/pam_sepermit.c
73cfcf
+++ b/modules/pam_sepermit/pam_sepermit.c
73cfcf
@@ -353,7 +353,7 @@ sepermit_match(pam_handle_t *pamh, const char *cfgfile, const char *user,
73cfcf
 		if (*sense == PAM_SUCCESS) {
73cfcf
 			if (ignore)
73cfcf
 				*sense = PAM_IGNORE;
73cfcf
-			if (geteuid() == 0 && exclusive && get_loginuid(pamh) == -1)
73cfcf
+			if (geteuid() == 0 && exclusive && get_loginuid(pamh) == (uid_t)-1)
73cfcf
 				if (sepermit_lock(pamh, user, debug) < 0)
73cfcf
 					*sense = PAM_AUTH_ERR;
73cfcf
 		}