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