summaryrefslogtreecommitdiffstats
path: root/usr.sbin/autofs
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2014-08-24 12:32:26 +0000
committertrasz <trasz@FreeBSD.org>2014-08-24 12:32:26 +0000
commitfc2af2222055f2fbf5c05a1d7a37dce20dae9f59 (patch)
tree3b15016a0c4560c92e7bec9d9a3ffeb8663f6d38 /usr.sbin/autofs
parente6eca74aa401f16aa31a392ab1e3134fc4abafd1 (diff)
downloadFreeBSD-src-fc2af2222055f2fbf5c05a1d7a37dce20dae9f59.zip
FreeBSD-src-fc2af2222055f2fbf5c05a1d7a37dce20dae9f59.tar.gz
Fix handling of keys in executable maps. Previously it was broken for keys
containing whitespace. PR: 192947 MFC after: 2 weeks Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'usr.sbin/autofs')
-rw-r--r--usr.sbin/autofs/common.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/usr.sbin/autofs/common.c b/usr.sbin/autofs/common.c
index 9695db5..1d1117c 100644
--- a/usr.sbin/autofs/common.c
+++ b/usr.sbin/autofs/common.c
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
+#define _WITH_GETLINE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -213,6 +214,7 @@ node_new(struct node *parent, char *key, char *options, char *location,
TAILQ_INIT(&n->n_children);
assert(key != NULL);
+ assert(key[0] != '\0');
n->n_key = key;
if (options != NULL)
n->n_options = options;
@@ -243,6 +245,7 @@ node_new_map(struct node *parent, char *key, char *options, char *map,
TAILQ_INIT(&n->n_children);
assert(key != NULL);
+ assert(key[0] != '\0');
n->n_key = key;
if (options != NULL)
n->n_options = options;
@@ -565,6 +568,7 @@ node_path_x(const struct node *n, char *x)
return (x);
}
+ assert(n->n_key[0] != '\0');
path = separated_concat(n->n_key, x, '/');
free(x);
@@ -857,33 +861,44 @@ again:
}
/*
- * Parse output of a special map called without argument. This is just
- * a list of keys.
+ * Parse output of a special map called without argument. It is a list
+ * of keys, separated by newlines. They can contain whitespace, so use
+ * getline(3) instead of lexer used for maps.
*/
static void
parse_map_keys_yyin(struct node *parent, const char *map)
{
- char *key = NULL;
- int ret;
+ char *line = NULL, *key;
+ size_t linecap = 0;
+ ssize_t linelen;
lineno = 1;
for (;;) {
- ret = yylex();
-
- if (ret == NEWLINE)
- continue;
-
- if (ret == 0) {
+ linelen = getline(&line, &linecap, yyin);
+ if (linelen < 0) {
/*
* End of file.
*/
break;
}
+ if (linelen <= 1) {
+ /*
+ * Empty line, consisting of just the newline.
+ */
+ continue;
+ }
+
+ /*
+ * "-1" to strip the trailing newline.
+ */
+ key = strndup(line, linelen - 1);
- key = checked_strdup(yytext);
+ log_debugx("adding key \"%s\"", key);
node_new(parent, key, NULL, NULL, map, lineno);
+ lineno++;
}
+ free(line);
}
static bool
OpenPOWER on IntegriCloud