Blame SOURCES/autofs-5.1.4-covarity-fixes-1.patch

d5dcad
autofs-5.1.4 - covarity fixes 1
d5dcad
d5dcad
From: Ian Kent <raven@themaw.net>
d5dcad
d5dcad
* remove conditional close of nullfd.
d5dcad
* fix memory leak of local_domain in lib/macros.c:macro_init().
d5dcad
* check for NULL prior to several assignments in lib/master_parse.y.
d5dcad
* fix memory leak in lib/mounts.c:add_std_amd_vars().
d5dcad
* add missing break in lib/rpc_subs.c:rpc_get_netid().
d5dcad
* fix variable scope problem in modules/amd_parse.c:make_selector().
d5dcad
* fix selector itself not freed in lib/parse_subs.c:free_selector().
d5dcad
* fix possible memory leak in modules/lookup_ldap.c:parse_ldap_config().
d5dcad
* fix possible memory leak in modules/lookup_ldap.c:decode_percent_hack().
d5dcad
* fix usage of decode_percent_hack() in modules/lookup_ldap.c.
d5dcad
* initialize enc_key1 and enc_key2 in modules/lookup_ldap.c:lookup_one().
d5dcad
* fix double alloc of map_type in modules/parse_amd.c:make_default_entry().
d5dcad
* fix double alloc of map_type in modules/parse_amd.c:get_defaults_entry().
d5dcad
* fix possible memory leak in modules/parse_sun.c:parse_reinit().
d5dcad
* initialize myoptions and ro_loc in modules/parse_sun.c:mount_subtree().
d5dcad
* initialize myoptions and loc in modules/parse_sun.c:parse_mount().
d5dcad
d5dcad
Signed-off-by: Ian Kent <raven@themaw.net>
d5dcad
---
d5dcad
 CHANGELOG             |    1 +
d5dcad
 lib/log.c             |    3 +--
d5dcad
 lib/macros.c          |    1 +
d5dcad
 lib/master_parse.y    |   28 ++++++++++++++++++++++++++++
d5dcad
 lib/mounts.c          |    4 +++-
d5dcad
 lib/parse_subs.c      |    1 +
d5dcad
 lib/rpc_subs.c        |    1 +
d5dcad
 modules/amd_parse.y   |    4 ++--
d5dcad
 modules/lookup_ldap.c |   27 ++++++++++++++++++++++-----
d5dcad
 modules/parse_amd.c   |    4 ++--
d5dcad
 modules/parse_sun.c   |   10 +++++++++-
d5dcad
 11 files changed, 71 insertions(+), 13 deletions(-)
d5dcad
d5dcad
--- autofs-5.1.4.orig/lib/log.c
d5dcad
+++ autofs-5.1.4/lib/log.c
d5dcad
@@ -336,8 +336,7 @@ void log_to_syslog(void)
d5dcad
 		exit(1);
d5dcad
 	}
d5dcad
 
d5dcad
-	if (nullfd > 2)
d5dcad
-		close(nullfd);
d5dcad
+	close(nullfd);
d5dcad
 
d5dcad
 	return;
d5dcad
 }
d5dcad
--- autofs-5.1.4.orig/lib/macros.c
d5dcad
+++ autofs-5.1.4/lib/macros.c
d5dcad
@@ -137,6 +137,7 @@ void macro_init(void)
d5dcad
 
d5dcad
 	macro_init_done = 1;
d5dcad
 	macro_unlock();
d5dcad
+	free(local_domain);
d5dcad
 	return;
d5dcad
 }
d5dcad
 
d5dcad
--- autofs-5.1.4.orig/lib/master_parse.y
d5dcad
+++ autofs-5.1.4/lib/master_parse.y
d5dcad
@@ -157,6 +157,8 @@ line:
d5dcad
 
d5dcad
 		trim_maptype($2);
d5dcad
 
d5dcad
+		if (path)
d5dcad
+			free(path);
d5dcad
 		path = master_strdup($1);
d5dcad
 		if (!path) {
d5dcad
 			master_error("memory allocation error");
d5dcad
@@ -167,6 +169,8 @@ line:
d5dcad
 		if ((tmp = strchr($2, ',')))
d5dcad
 			*tmp++ = '\0';
d5dcad
 
d5dcad
+		if (type)
d5dcad
+			free(type);
d5dcad
 		type = master_strdup($2);
d5dcad
 		if (!type) {
d5dcad
 			master_error("memory allocation error");
d5dcad
@@ -174,6 +178,8 @@ line:
d5dcad
 			YYABORT;
d5dcad
 		}
d5dcad
 		if (tmp) {
d5dcad
+			if (format)
d5dcad
+				free(format);
d5dcad
 			format = master_strdup(tmp);
d5dcad
 			if (!format) {
d5dcad
 				master_error("memory allocation error");
d5dcad
@@ -204,6 +210,8 @@ line:
d5dcad
 
d5dcad
 mapspec: map
d5dcad
 	{
d5dcad
+		if (local_argv)
d5dcad
+			free_argv(local_argc, (const char **) local_argv);
d5dcad
 		local_argc = tmp_argc;
d5dcad
 		local_argv = tmp_argv;
d5dcad
 		tmp_argc = 0;
d5dcad
@@ -211,6 +219,8 @@ mapspec: map
d5dcad
 	}
d5dcad
 	| map options
d5dcad
 	{
d5dcad
+		if (local_argv)
d5dcad
+			free_argv(local_argc, (const char **) local_argv);
d5dcad
 		local_argc = tmp_argc;
d5dcad
 		local_argv = tmp_argv;
d5dcad
 		tmp_argc = 0;
d5dcad
@@ -288,6 +298,8 @@ map:	PATH
d5dcad
 	}
d5dcad
 	| MAPHOSTS
d5dcad
 	{
d5dcad
+		if (type)
d5dcad
+			free(type);
d5dcad
 		type = master_strdup($1 + 1);
d5dcad
 		if (!type) {
d5dcad
 			local_free_vars();
d5dcad
@@ -302,6 +314,8 @@ map:	PATH
d5dcad
 	}
d5dcad
 	| MAPNULL
d5dcad
 	{
d5dcad
+		if (type)
d5dcad
+			free(type);
d5dcad
 		type = master_strdup($1 + 1);
d5dcad
 		if (!type) {
d5dcad
 			local_free_vars();
d5dcad
@@ -310,6 +324,8 @@ map:	PATH
d5dcad
 	}
d5dcad
 	| dnattrs
d5dcad
 	{
d5dcad
+		if (type)
d5dcad
+			free(type);
d5dcad
 		type = master_strdup("ldap");
d5dcad
 		if (!type) {
d5dcad
 			local_free_vars();
d5dcad
@@ -332,6 +348,8 @@ map:	PATH
d5dcad
 		if ((tmp = strchr($1, ',')))
d5dcad
 			*tmp++ = '\0';
d5dcad
 
d5dcad
+		if (type)
d5dcad
+			free(type);
d5dcad
 		if (strcmp($1, "exec"))
d5dcad
 			type = master_strdup($1);
d5dcad
 		else
d5dcad
@@ -342,6 +360,8 @@ map:	PATH
d5dcad
 			YYABORT;
d5dcad
 		}
d5dcad
 		if (tmp) {
d5dcad
+			if (format)
d5dcad
+				free(format);
d5dcad
 			format = master_strdup(tmp);
d5dcad
 			if (!format) {
d5dcad
 				master_error("memory allocation error");
d5dcad
@@ -366,6 +386,8 @@ map:	PATH
d5dcad
 		if ((tmp = strchr($1, ',')))
d5dcad
 			*tmp++ = '\0';
d5dcad
 
d5dcad
+		if (type)
d5dcad
+			free(type);
d5dcad
 		if (strcmp($1, "exec"))
d5dcad
 			type = master_strdup($1);
d5dcad
 		else
d5dcad
@@ -376,6 +398,8 @@ map:	PATH
d5dcad
 			YYABORT;
d5dcad
 		}
d5dcad
 		if (tmp) {
d5dcad
+			if (format)
d5dcad
+				free(format);
d5dcad
 			format = master_strdup(tmp);
d5dcad
 			if (!format) {
d5dcad
 				master_error("memory allocation error");
d5dcad
@@ -400,6 +424,8 @@ map:	PATH
d5dcad
 		if ((tmp = strchr($1, ',')))
d5dcad
 			*tmp++ = '\0';
d5dcad
 
d5dcad
+		if (type)
d5dcad
+			free(type);
d5dcad
 		if (strcmp($1, "exec"))
d5dcad
 			type = master_strdup($1);
d5dcad
 		else
d5dcad
@@ -410,6 +436,8 @@ map:	PATH
d5dcad
 			YYABORT;
d5dcad
 		}
d5dcad
 		if (tmp) {
d5dcad
+			if (format)
d5dcad
+				free(format);
d5dcad
 			format = master_strdup(tmp);
d5dcad
 			if (!format) {
d5dcad
 				master_error("memory allocation error");
d5dcad
--- autofs-5.1.4.orig/lib/mounts.c
d5dcad
+++ autofs-5.1.4/lib/mounts.c
d5dcad
@@ -489,8 +489,10 @@ void add_std_amd_vars(struct substvar *s
d5dcad
 		const struct substvar *v = macro_findvar(sv, "domain", 4);
d5dcad
 		if (v && *v->val) {
d5dcad
 			tmp = strdup(v->val);
d5dcad
-			if (tmp)
d5dcad
+			if (tmp) {
d5dcad
 				macro_global_addvar("cluster", 7, tmp);
d5dcad
+				free(tmp);
d5dcad
+			}
d5dcad
 		}
d5dcad
 	}
d5dcad
 
d5dcad
--- autofs-5.1.4.orig/lib/parse_subs.c
d5dcad
+++ autofs-5.1.4/lib/parse_subs.c
d5dcad
@@ -189,6 +189,7 @@ void free_selector(struct selector *sele
d5dcad
 			free(s->func.arg2);
d5dcad
 		s = next;
d5dcad
 	}
d5dcad
+	free(selector);
d5dcad
 	return;
d5dcad
 }
d5dcad
 
d5dcad
--- autofs-5.1.4.orig/lib/rpc_subs.c
d5dcad
+++ autofs-5.1.4/lib/rpc_subs.c
d5dcad
@@ -389,6 +389,7 @@ static enum clnt_stat rpc_get_netid(cons
d5dcad
 		}
d5dcad
 
d5dcad
 		*netid = nc_netid;
d5dcad
+		break;
d5dcad
 	}
d5dcad
 	endnetconfig(handle);
d5dcad
 	free(nc_proto);
d5dcad
--- autofs-5.1.4.orig/modules/amd_parse.y
d5dcad
+++ autofs-5.1.4/modules/amd_parse.y
d5dcad
@@ -822,13 +822,13 @@ static int make_selector(char *name,
d5dcad
 		if (!value1)
d5dcad
 			tmp = NULL;
d5dcad
 		else {
d5dcad
-			char *tmp = amd_strdup(value1);
d5dcad
+			tmp = amd_strdup(value1);
d5dcad
 			if (!tmp)
d5dcad
 				goto error;
d5dcad
 		}
d5dcad
 		s->func.arg1 = tmp;
d5dcad
 	} else if (s->sel->flags & SEL_FLAG_FUNC2) {
d5dcad
-		char *tmp = amd_strdup(value1);
d5dcad
+		tmp = amd_strdup(value1);
d5dcad
 		if (!tmp)
d5dcad
 			goto error;
d5dcad
 		s->func.arg1 = tmp;
d5dcad
--- autofs-5.1.4.orig/modules/lookup_ldap.c
d5dcad
+++ autofs-5.1.4/modules/lookup_ldap.c
d5dcad
@@ -1137,6 +1137,7 @@ int parse_ldap_config(unsigned logopt, s
d5dcad
 		error(logopt,
d5dcad
 		      MODPREFIX "stat(2) failed with error %s.",
d5dcad
 		      strerror(errno));
d5dcad
+		free(auth_conf);
d5dcad
 		return 0;
d5dcad
 	}
d5dcad
 
d5dcad
@@ -1148,6 +1149,7 @@ int parse_ldap_config(unsigned logopt, s
d5dcad
 		      "Please make sure that it is owned by root, group "
d5dcad
 		      "is root, and the mode is 0600.",
d5dcad
 		      auth_conf);
d5dcad
+		free(auth_conf);
d5dcad
 		return -1;
d5dcad
 	}
d5dcad
 
d5dcad
@@ -1182,9 +1184,11 @@ int parse_ldap_config(unsigned logopt, s
d5dcad
 		goto out;
d5dcad
 	}
d5dcad
 
d5dcad
-	if (!usetls || ctxt->port == LDAPS_PORT)
d5dcad
+	if (!usetls || ctxt->port == LDAPS_PORT) {
d5dcad
 		use_tls = LDAP_TLS_DONT_USE;
d5dcad
-	else {
d5dcad
+		if (usetls)
d5dcad
+			free(usetls);
d5dcad
+	} else {
d5dcad
 		if (!strcasecmp(usetls, "yes"))
d5dcad
 			use_tls = LDAP_TLS_INIT;
d5dcad
 		else if (!strcasecmp(usetls, "no"))
d5dcad
@@ -1194,6 +1198,7 @@ int parse_ldap_config(unsigned logopt, s
d5dcad
 			      MODPREFIX
d5dcad
 			      "The usetls property must have value "
d5dcad
 			      "\"yes\" or \"no\".");
d5dcad
+			free(usetls);
d5dcad
 			ret = -1;
d5dcad
 			goto out;
d5dcad
 		}
d5dcad
@@ -1221,6 +1226,7 @@ int parse_ldap_config(unsigned logopt, s
d5dcad
 			      MODPREFIX
d5dcad
 			      "The tlsrequired property must have value "
d5dcad
 			      "\"yes\" or \"no\".");
d5dcad
+			free(tlsrequired);
d5dcad
 			ret = -1;
d5dcad
 			goto out;
d5dcad
 		}
d5dcad
@@ -1252,6 +1258,7 @@ int parse_ldap_config(unsigned logopt, s
d5dcad
 			      MODPREFIX
d5dcad
 			      "The authrequired property must have value "
d5dcad
 			      "\"yes\", \"no\", \"autodetect\", or \"simple\".");
d5dcad
+			free(authrequired);
d5dcad
 			ret = -1;
d5dcad
 			goto out;
d5dcad
 		}
d5dcad
@@ -1338,6 +1345,7 @@ auth_fail:
d5dcad
 	(void)get_property(logopt, root, "credentialcache", &client_cc);
d5dcad
 
d5dcad
 	ctxt->auth_conf = auth_conf;
d5dcad
+	auth_conf = NULL;
d5dcad
 	ctxt->use_tls = use_tls;
d5dcad
 	ctxt->tls_required = tls_required;
d5dcad
 	ctxt->auth_required = auth_required;
d5dcad
@@ -1375,8 +1383,12 @@ auth_fail:
d5dcad
 		      user, secret ? "specified" : "unspecified",
d5dcad
 		      client_princ, client_cc);
d5dcad
 	}
d5dcad
+	if (authtype)
d5dcad
+		free(authtype);
d5dcad
 out:
d5dcad
 	xmlFreeDoc(doc);
d5dcad
+	if (auth_conf)
d5dcad
+		free(auth_conf);
d5dcad
 
d5dcad
 	if (fallback)
d5dcad
 		return 0;
d5dcad
@@ -1986,7 +1998,7 @@ int lookup_read_master(struct master *ma
d5dcad
 			}
d5dcad
 		} else if (count == 1) {
d5dcad
 			dec_len = decode_percent_hack(keyValue[0], &key);
d5dcad
-			if (dec_len < 0) {
d5dcad
+			if (dec_len <= 0) {
d5dcad
 				error(logopt, MODPREFIX
d5dcad
 				      "invalid map key %s - ignoring",
d5dcad
 				      *keyValue);
d5dcad
@@ -1994,7 +2006,7 @@ int lookup_read_master(struct master *ma
d5dcad
 			}
d5dcad
 		} else {
d5dcad
 			dec_len = decode_percent_hack(keyValue[0], &key);
d5dcad
-			if (dec_len < 0) {
d5dcad
+			if (dec_len <= 0) {
d5dcad
 				error(logopt, MODPREFIX
d5dcad
 				      "invalid map key %s - ignoring",
d5dcad
 				      *keyValue);
d5dcad
@@ -2004,7 +2016,7 @@ int lookup_read_master(struct master *ma
d5dcad
 			for (i = 1; i < count; i++) {
d5dcad
 				char *k;
d5dcad
 				dec_len = decode_percent_hack(keyValue[i], &k);
d5dcad
-				if (dec_len < 0) {
d5dcad
+				if (dec_len <= 0) {
d5dcad
 					error(logopt, MODPREFIX
d5dcad
 					      "invalid map key %s - ignoring",
d5dcad
 					      *keyValue);
d5dcad
@@ -2159,6 +2171,8 @@ static int decode_percent_hack(const cha
d5dcad
 	*key = NULL;
d5dcad
 
d5dcad
 	len = get_percent_decoded_len(name);
d5dcad
+	if (!len)
d5dcad
+		return 0;
d5dcad
 	new = malloc(len + 1);
d5dcad
 	if (!new)
d5dcad
 		return -1;
d5dcad
@@ -2998,6 +3012,9 @@ static int lookup_one(struct autofs_poin
d5dcad
 	attrs[1] = info;
d5dcad
 	attrs[2] = NULL;
d5dcad
 
d5dcad
+	enc_key1 = NULL;
d5dcad
+	enc_key2 = NULL;
d5dcad
+
d5dcad
 	if (*qKey == '*' && qKey_len == 1)
d5dcad
 		*qKey = '/';
d5dcad
 	else if (!strcasecmp(class, "nisObject")) {
d5dcad
--- autofs-5.1.4.orig/modules/parse_amd.c
d5dcad
+++ autofs-5.1.4/modules/parse_amd.c
d5dcad
@@ -1879,7 +1879,7 @@ struct amd_entry *make_default_entry(str
d5dcad
 	 */
d5dcad
 	map_type = conf_amd_get_map_type(ap->path);
d5dcad
 	if (map_type)
d5dcad
-		defaults_entry->map_type = strdup(map_type);
d5dcad
+		defaults_entry->map_type = map_type;
d5dcad
 	/* The list should now be empty .... */
d5dcad
 	free_amd_entry_list(&dflts);
d5dcad
 	return defaults_entry;
d5dcad
@@ -2006,7 +2006,7 @@ static struct amd_entry *get_defaults_en
d5dcad
 			 */
d5dcad
 			char *map_type = conf_amd_get_map_type(ap->path);
d5dcad
 			if (map_type)
d5dcad
-				entry->map_type = strdup(map_type);
d5dcad
+				entry->map_type = map_type;
d5dcad
 		}
d5dcad
 		free(expand);
d5dcad
 	}
d5dcad
--- autofs-5.1.4.orig/modules/parse_sun.c
d5dcad
+++ autofs-5.1.4/modules/parse_sun.c
d5dcad
@@ -443,8 +443,10 @@ int parse_reinit(int argc, const char *c
d5dcad
 
d5dcad
 	*new = default_context;
d5dcad
 
d5dcad
-	if (do_init(argc, argv, new))
d5dcad
+	if (do_init(argc, argv, new)) {
d5dcad
+		free(new);
d5dcad
 		return 1;
d5dcad
+	}
d5dcad
 
d5dcad
 	kill_context(ctxt);
d5dcad
 
d5dcad
@@ -1143,6 +1145,9 @@ static int mount_subtree(struct autofs_p
d5dcad
 			const char *root;
d5dcad
 			int ro_len;
d5dcad
 
d5dcad
+			myoptions = NULL;
d5dcad
+			ro_loc = NULL;
d5dcad
+
d5dcad
 			rv = parse_mapent(ro->mapent,
d5dcad
 				options, &myoptions, &ro_loc, ap->logopt);
d5dcad
 			if (!rv) {
d5dcad
@@ -1524,6 +1529,9 @@ dont_expand:
d5dcad
 			p += l;
d5dcad
 			p = skipspace(p);
d5dcad
 
d5dcad
+			myoptions = NULL;
d5dcad
+			loc = NULL;
d5dcad
+
d5dcad
 			l = parse_mapent(p, options, &myoptions, &loc, ap->logopt);
d5dcad
 			if (!l) {
d5dcad
 				cache_delete_offset_list(mc, name);
d5dcad
--- autofs-5.1.4.orig/CHANGELOG
d5dcad
+++ autofs-5.1.4/CHANGELOG
d5dcad
@@ -26,6 +26,7 @@ xx/xx/2018 autofs-5.1.5
d5dcad
 - fix NFS version mask usage.
d5dcad
 - fix fd leak in rpc_do_create_client().
d5dcad
 - add-man page note about extra slashes in paths.
d5dcad
+- covarity fixes.
d5dcad
 
d5dcad
 19/12/2017 autofs-5.1.4
d5dcad
 - fix spec file url.