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

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