Add flag to sudo_parseln() to disable line continuation support.

This commit is contained in:
Todd C. Miller
2016-09-01 10:50:39 -06:00
parent 852fe25bc1
commit 2a4ba64c84
2 changed files with 10 additions and 4 deletions

View File

@@ -140,6 +140,7 @@
/* sudo_parseln() flags */ /* sudo_parseln() flags */
#define PARSELN_COMM_BOL 1 /* comments only at begining of line */ #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. * Macros to quiet gcc's warn_unused_result attribute.

View File

@@ -50,10 +50,11 @@ sudo_parseln_v2(char **bufp, size_t *bufsizep, unsigned int *lineno, FILE *fp, i
size_t linesize = 0, total = 0; size_t linesize = 0, total = 0;
ssize_t len; ssize_t len;
char *cp, *line = NULL; char *cp, *line = NULL;
bool continued; bool continued, comment;
debug_decl(sudo_parseln, SUDO_DEBUG_UTIL) debug_decl(sudo_parseln, SUDO_DEBUG_UTIL)
do { do {
comment = false;
continued = false; continued = false;
len = getline(&line, &linesize, fp); len = getline(&line, &linesize, fp);
if (len == -1) 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)) { if (cp == line || !ISSET(flags, PARSELN_COMM_BOL)) {
*cp = '\0'; *cp = '\0';
len = (ssize_t)(cp - line); 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 */ /* Trim leading and trailing whitespace */