]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Strip trailing whitespace from $ORIGIN and $TTL
authorWillem Toorop <willem@nlnetlabs.nl>
Fri, 3 Oct 2014 12:25:27 +0000 (14:25 +0200)
committerWillem Toorop <willem@nlnetlabs.nl>
Fri, 3 Oct 2014 12:25:27 +0000 (14:25 +0200)
rr.c

diff --git a/rr.c b/rr.c
index c6f7eeb55fe56e79e761209b4f902dbb5662030c..5e7476ee24a10e139f98775503cf98ebb9351d88 100644 (file)
--- a/rr.c
+++ b/rr.c
@@ -670,16 +670,15 @@ ldns_rr_new_question_frm_str(ldns_rr **newrr, const char *str,
                                            true);
 }
 
-static int
-ldns_rr_is_whitespace_line(char* line, ssize_t line_len)
+static char *
+ldns_strip_ws(char *line)
 {
-       ssize_t i;
-       for (i = 0; i < line_len; i++) {
-               if (!isspace((int)line[i])) {
-                       return 0;
-               }
-       }
-       return 1;
+       char *s = line, *e;
+
+       for (s = line; *s && isspace(*s); s++);
+       for (e = strchr(s, 0); e-2 > s && isspace(e[-1]) && e[-2] != '\\'; e--);
+       *e = 0;
+       return s;
 }
 
 ldns_status
@@ -698,7 +697,6 @@ ldns_rr_new_frm_fp_l(ldns_rr **newrr, FILE *fp, uint32_t *default_ttl, ldns_rdf
        ldns_rdf *tmp;
        ldns_status s;
        ssize_t size;
-       int offset = 0;
 
        if (default_ttl) {
                ttl = *default_ttl;
@@ -734,11 +732,8 @@ ldns_rr_new_frm_fp_l(ldns_rr **newrr, FILE *fp, uint32_t *default_ttl, ldns_rdf
                        ldns_rdf_deep_free(*origin);
                        *origin = NULL;
                }
-               offset = 8;
-               while (isspace(line[offset])) {
-                       offset++;
-               }
-               tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, line + offset);
+               tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,
+                               ldns_strip_ws(line + 8));
                if (!tmp) {
                        /* could not parse what next to $ORIGIN */
                        LDNS_FREE(line);
@@ -747,17 +742,14 @@ ldns_rr_new_frm_fp_l(ldns_rr **newrr, FILE *fp, uint32_t *default_ttl, ldns_rdf
                *origin = tmp;
                s = LDNS_STATUS_SYNTAX_ORIGIN;
        } else if (strncmp(line, "$TTL", 4) == 0 && isspace(line[4])) {
-               offset = 5;
-               while (isspace(line[offset])) {
-                       offset++;
-               }
                if (default_ttl) {
-                       *default_ttl = ldns_str2period(line + offset, &endptr);
+                       *default_ttl = ldns_str2period(
+                                       ldns_strip_ws(line + 5), &endptr);
                }
                s = LDNS_STATUS_SYNTAX_TTL;
        } else if (strncmp(line, "$INCLUDE", 8) == 0) {
                s = LDNS_STATUS_SYNTAX_INCLUDE;
-       } else if (ldns_rr_is_whitespace_line(line, size)) {
+       } else if (!*ldns_strip_ws(line)) {
                LDNS_FREE(line);
                return LDNS_STATUS_SYNTAX_EMPTY;
        } else {