autofs-5.1.8 - fix minus only option handling in concat_options()

From: Ian Kent <raven@themaw.net>

While a '-' alone isn't strictly valid it hadn't previously cuased a
parse error. So commit 9047e91ffa69 (autofs-5.1.7 - fix concat_options()
error handling) introduced a regression by no longer allowing this.

Fix this regression by only failing if errno is set to a non-zero value
on return from concat_options() as well as returning NULL.

Fixes: 9047e91ffa69 (autofs-5.1.7 - fix concat_options() error handling)
Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG           |    1 +
 modules/parse_sun.c |   25 +++++++++++++++++++------
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index e75f341f..f50f7c26 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -47,6 +47,7 @@
 - fix hosts map deadlock on restart.
 - fix deadlock with hosts map reload.
 - fix memory leak in update_hosts_mounts().
+- fix minus only option handling in concat_options().
 
 19/10/2021 autofs-5.1.8
 - add xdr_exports().
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
index 4d716b6f..759e580b 100644
--- a/modules/parse_sun.c
+++ b/modules/parse_sun.c
@@ -376,10 +376,16 @@ static int do_init(int argc, const char *const *argv, struct parse_context *ctxt
 	if (gbl_options) {
 		append_options = defaults_get_append_options();
 		if (append_options) {
-			char *tmp = concat_options(gbl_options, ctxt->optstr);
+			char *tmp;
+
+			errno = 0;
+			tmp = concat_options(gbl_options, ctxt->optstr);
 			if (!tmp) {
-				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
-				logerr(MODPREFIX "concat_options: %s", estr);
+				/* Ignore non-error NULL return */
+				if (errno) {
+					char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+					logerr(MODPREFIX "concat_options: %s", estr);
+				}
 				/* freed in concat_options */
 				ctxt->optstr = NULL;
 			} else
@@ -1007,9 +1013,12 @@ static int parse_mapent(const char *ent, char *g_options, char **options, char *
 				free(myoptions);
 				myoptions = newopt;
 			} else if (newopt) {
+				errno = 0;
 				tmp = concat_options(myoptions, newopt);
-				if (!tmp) {
+				/* Ignore non-error NULL return */
+				if (!tmp && errno) {
 					char *estr;
+
 					estr = strerror_r(errno, buf, MAX_ERR_BUF);
 					error(logopt, MODPREFIX
 					      "concat_options: %s", estr);
@@ -1381,8 +1390,10 @@ dont_expand:
 				free(mnt_options);
 				mnt_options = noptions;
 			} else if (noptions) {
+				errno = 0;
 				tmp = concat_options(mnt_options, noptions);
-				if (!tmp) {
+				/* Ignore non-error NULL return */
+				if (!tmp && errno) {
 					char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
 					error(ap->logopt,
 					      MODPREFIX "concat_options: %s", estr);
@@ -1406,8 +1417,10 @@ dont_expand:
 				free(options);
 				options = mnt_options;
 			} else if (mnt_options) {
+				errno = 0;
 				tmp = concat_options(options, mnt_options);
-				if (!tmp) {
+				/* Ignore non-error NULL return */
+				if (!tmp && errno) {
 					char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
 					error(ap->logopt, MODPREFIX "concat_options: %s", estr);
 					free(pmapent);
