From: Miek Gieben Date: Thu, 6 Apr 2006 08:44:26 +0000 (+0000) Subject: added a new status that signals: no error, but nothing was read X-Git-Tag: release-1.1.0~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f79a8d5d13d0a7d22511684ee83c27ca98aead9;p=thirdparty%2Fldns.git added a new status that signals: no error, but nothing was read adjust zone reader to check for this --- diff --git a/error.c b/error.c index 029aef81..dc196ff7 100644 --- 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 } }; diff --git a/ldns/error.h b/ldns/error.h index 40702bff..de3d28c5 100644 --- a/ldns/error.h +++ b/ldns/error.h @@ -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 655af17a..52089795 100644 --- 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 516eef5e..2c18dba7 100644 --- 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 9117231a..c032023a 100644 --- 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;