]> granicus.if.org Git - sudo/commitdiff
Add flag to sudo_parseln() to disable line continuation support.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 1 Sep 2016 16:50:39 +0000 (10:50 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 1 Sep 2016 16:50:39 +0000 (10:50 -0600)
include/sudo_util.h
lib/util/parseln.c

index 7495b84ab89a330470ccc70fef869f3f7af08d8f..4e8f4cb5e9bab5a8bea217be4523bc218fafe5e7 100644 (file)
 
 /* 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.
index 6f3eac4cd28c1139633d9dbd7f453bd206bd6e41..ec2a0d35d597f6cbe2e99412716e29eca3eb01d5 100644 (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;
     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 */