From: Todd C. Miller Date: Thu, 1 Sep 2016 16:50:39 +0000 (-0600) Subject: Add flag to sudo_parseln() to disable line continuation support. X-Git-Tag: SUDO_1_8_18^2~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a4ba64c84bd3075ffaf8d394635238aaae3e0c1;p=sudo Add flag to sudo_parseln() to disable line continuation support. --- diff --git a/include/sudo_util.h b/include/sudo_util.h index 7495b84ab..4e8f4cb5e 100644 --- a/include/sudo_util.h +++ b/include/sudo_util.h @@ -140,6 +140,7 @@ /* sudo_parseln() flags */ #define PARSELN_COMM_BOL 1 /* comments only at begining of line */ +#define PARSELN_CONT_IGN 2 /* ignore line continuation char */ /* * Macros to quiet gcc's warn_unused_result attribute. diff --git a/lib/util/parseln.c b/lib/util/parseln.c index 6f3eac4cd..ec2a0d35d 100644 --- a/lib/util/parseln.c +++ b/lib/util/parseln.c @@ -50,10 +50,11 @@ sudo_parseln_v2(char **bufp, size_t *bufsizep, unsigned int *lineno, FILE *fp, i size_t linesize = 0, total = 0; ssize_t len; char *cp, *line = NULL; - bool continued; + bool continued, comment; debug_decl(sudo_parseln, SUDO_DEBUG_UTIL) do { + comment = false; continued = false; len = getline(&line, &linesize, fp); if (len == -1) @@ -70,10 +71,14 @@ sudo_parseln_v2(char **bufp, size_t *bufsizep, unsigned int *lineno, FILE *fp, i if (cp == line || !ISSET(flags, PARSELN_COMM_BOL)) { *cp = '\0'; len = (ssize_t)(cp - line); + comment = true; + } + } + if (!comment && !ISSET(flags, PARSELN_CONT_IGN)) { + if (len > 0 && line[len - 1] == '\\' && (len == 1 || line[len - 2] != '\\')) { + line[--len] = '\0'; + continued = true; } - } else if (len > 0 && line[len - 1] == '\\' && (len == 1 || line[len - 2] != '\\')) { - line[--len] = '\0'; - continued = true; } /* Trim leading and trailing whitespace */