]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
added a new status that signals: no error, but nothing was read
authorMiek Gieben <miekg@NLnetLabs.nl>
Thu, 6 Apr 2006 08:44:26 +0000 (08:44 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Thu, 6 Apr 2006 08:44:26 +0000 (08:44 +0000)
adjust zone reader to check for this

error.c
ldns/error.h
parse.c
rr.c
zone.c

diff --git a/error.c b/error.c
index 029aef81d0a450d2f9a2039d3ea8cb1a36910ff0..dc196ff755df0dff6511b4c8cd93c5c0001d63bf 100644 (file)
--- a/error.c
+++ b/error.c
@@ -68,6 +68,7 @@ ldns_lookup_table ldns_error_str[] = {
        { LDNS_STATUS_SYNTAX_VERSION_ERR, "Syntax error, version mismatch" },
        { LDNS_STATUS_SYNTAX_ALG_ERR, "Syntax error, algorithm unknown or non parseable" },
        { LDNS_STATUS_SYNTAX_ERR, "Syntax error, could not parse the RR" },
+       { LDNS_STATUS_SYNTAX_EMPTY, "An empty line was returned" },
        { LDNS_STATUS_SYNTAX_TTL, "A $TTL directive was seen in a zone" },
        { 0, NULL }
 };
index 40702bff39d776f1f16cafa5a86871cf574814e6..de3d28c54e3dc8787c27bc597bd93135793b8d7b 100644 (file)
@@ -73,6 +73,7 @@ enum ldns_enum_status
         LDNS_STATUS_SYNTAX_ALG_ERR,
         LDNS_STATUS_SYNTAX_KEYWORD_ERR,
         LDNS_STATUS_SYNTAX_TTL,
+        LDNS_STATUS_SYNTAX_EMPTY,
         LDNS_STATUS_SYNTAX_ERR
 };
 typedef enum ldns_enum_status ldns_status;
diff --git a/parse.c b/parse.c
index 655af17acad8e6398123b712e79b2584b5c5158a..52089795621f81635d82768cb4f315a1966957ac 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -102,7 +102,7 @@ ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *li
 
                /* check if we hit the delim */
                for (d = del; *d; d++) {
-                       if (c == *d && i >= 1) {
+                       if (c == *d && i > 0) {
                                goto tokenread;
                        }
                }
@@ -115,11 +115,11 @@ ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *li
                        return -1;
                }
        }
+       *t = '\0';
        if (c == EOF) {
-               return -1;
+               return 0;
        }
 
-       *t = '\0';
        if (i == 0) {
                /* nothing read */
                return -1;
diff --git a/rr.c b/rr.c
index 516eef5e53e6ab27d0119e6611a362dfc60f18db..2c18dba7b3a6ac9df0686e9b42b3c05b3dd4fe47 100644 (file)
--- a/rr.c
+++ b/rr.c
@@ -475,6 +475,7 @@ ldns_rr_new_frm_fp_l(ldns_rr **newrr, FILE *fp, uint16_t *default_ttl, ldns_rdf
        uint16_t ttl;
        ldns_rdf *tmp;
        ldns_status s;
+       ssize_t size;
 
        s = LDNS_STATUS_ERR;
        if (default_ttl) {
@@ -493,7 +494,7 @@ ldns_rr_new_frm_fp_l(ldns_rr **newrr, FILE *fp, uint16_t *default_ttl, ldns_rdf
        }
 
         /* read an entire line in from the file */
-        if (ldns_fget_token_l(fp, line, LDNS_PARSE_SKIP_SPACE, LDNS_MAX_LINELEN, line_nr) == -1) {
+        if ((size = ldns_fget_token_l(fp, line, LDNS_PARSE_SKIP_SPACE, LDNS_MAX_LINELEN, line_nr)) == -1) {
                LDNS_FREE(line);
                /* if last line was empty, we are now at feof, which is not
                 * always a parse error (happens when for instance last line
@@ -506,6 +507,13 @@ ldns_rr_new_frm_fp_l(ldns_rr **newrr, FILE *fp, uint16_t *default_ttl, ldns_rdf
                 return LDNS_STATUS_SYNTAX_ERR;
         }
 
+       /* we can have the situation, where we've read ok, but still got
+        * no bytes to play with, in this case size is 0 
+        */
+       if (size == 0) {
+               return LDNS_STATUS_SYNTAX_EMPTY;
+       }
+       
        if ((keyword = strstr(line, "$ORIGIN "))) {
                if (*origin) {
                        ldns_rdf_free(*origin);
diff --git a/zone.c b/zone.c
index 9117231a3c4bf870060447fc3b67b7a275247833..c032023af7b72561d177015dd1f2ac0fec932de8 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -209,6 +209,7 @@ ldns_zone_new_frm_fp_l(ldns_zone **z, FILE *fp, ldns_rdf *origin, uint16_t ttl,
                        /*my_origin = ldns_rr_owner(rr);*/
                        my_ttl    = ldns_rr_ttl(rr);
                        my_class  = ldns_rr_get_class(rr);
+               case LDNS_STATUS_SYNTAX_EMPTY:
                case LDNS_STATUS_SYNTAX_TTL:
                        /* the function set the ttl */
                        break;