From: Miek Gieben Date: Wed, 6 Apr 2005 08:43:06 +0000 (+0000) Subject: aah, the joy of return codes X-Git-Tag: release-0.50~165 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=81c45fb92acbfbb55ac93bdd203d6248a865dbe4;p=thirdparty%2Fldns.git aah, the joy of return codes --- diff --git a/parse.c b/parse.c index 4d17dc2b..aa770c08 100644 --- a/parse.c +++ b/parse.c @@ -196,7 +196,6 @@ ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit) del = delim; } - p = 0; i = 0; t = token; diff --git a/rr.c b/rr.c index 6b0c4a51..6c0a94a8 100644 --- a/rr.c +++ b/rr.c @@ -124,16 +124,26 @@ ldns_rr_new_frm_str(const char *str) ldns_buffer_new_frm_data(rr_buf, str, strlen(str)); - /* split the rr in its parts */ - (void)ldns_bget_token(rr_buf, owner, "\t \0", MAX_DOMAINLEN); - (void)ldns_bget_token(rr_buf, ttl, "\t \0", 21); - (void)ldns_bget_token(rr_buf, clas, "\t \0", 11); - (void)ldns_bget_token(rr_buf, type, "\t \0", 10); - (void)ldns_bget_token(rr_buf, rdata, "\0", MAX_PACKETLEN); - + /* split the rr in its parts -1 signal trouble */ + if (ldns_bget_token(rr_buf, owner, "\t ", MAX_DOMAINLEN) == -1) { + return NULL; + } + if (ldns_bget_token(rr_buf, ttl, "\t ", 21) == -1) { + return NULL; + } + if (ldns_bget_token(rr_buf, clas, "\t ", 11) == -1) { + return NULL; + } + if (ldns_bget_token(rr_buf, type, "\t ", 10) == -1) { + return NULL; + } + if (ldns_bget_token(rr_buf, rdata, "\0", MAX_PACKETLEN) == -1) { + return NULL; + } + ldns_buffer_new_frm_data( rd_buf, rdata, strlen(rdata)); - + /* FREE(rdata); NO! */ ldns_rr_set_owner(new, ldns_dname_new_frm_str(owner)); FREE(owner); /* ttl might be more complicated, like 2h, or 3d5h */ @@ -151,7 +161,7 @@ ldns_rr_new_frm_str(const char *str) r_min = ldns_rr_descriptor_minimum(desc); /* there is no limit, no no */ - while(ldns_bget_token(rd_buf, rd, "\t \0", MAX_RDFLEN) > 0) { + while(ldns_bget_token(rd_buf, rd, "\t ", MAX_RDFLEN) > 0) { r = ldns_rdf_new_frm_str( ldns_rr_descriptor_field_type(desc, r_cnt), rd); @@ -159,31 +169,27 @@ ldns_rr_new_frm_str(const char *str) if (!r) { printf("rdf conversion mismatch\n"); /* return what we've got */ - FREE(rdata); return new; } ldns_rr_push_rdf(new, r); if (r_cnt > r_max) { printf("rdf data overflow"); - FREE(rdata); return new; } r_cnt++; } + /* the last one - in case of EOF of the rdata */ r = ldns_rdf_new_frm_str( ldns_rr_descriptor_field_type(desc, r_cnt), rd); if (!r) { printf("rdf conversion mismatch\n"); - FREE(rdata); return new; } ldns_rr_push_rdf(new, r); - - FREE(rdata); return new; } diff --git a/run-test18.c b/run-test18.c index c9dc16c2..7d659646 100644 --- a/run-test18.c +++ b/run-test18.c @@ -49,6 +49,11 @@ main() rr = ldns_rr_new_frm_str("a.miek.nl. 1800 IN A 267.271.122.1t"); ldns_rr_print(stdout, rr); printf("\n"); + + printf("it craps on this one\n"); + rr = ldns_rr_new_frm_str("a.miek.nl. A 267.271.122.1t"); + ldns_rr_print(stdout, rr); + printf("\n"); exit(0); privkey = ldns_key_new_frm_algorithm(LDNS_SIGN_RSASHA1, 512);