]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
aah, the joy of return codes
authorMiek Gieben <miekg@NLnetLabs.nl>
Wed, 6 Apr 2005 08:43:06 +0000 (08:43 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Wed, 6 Apr 2005 08:43:06 +0000 (08:43 +0000)
parse.c
rr.c
run-test18.c

diff --git a/parse.c b/parse.c
index 4d17dc2bbd6c2f86aec360a96f17f0beba527e21..aa770c08f750434283143e7790841cb710a841e8 100644 (file)
--- 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 6b0c4a51e583c11945a32e776b4fabe66b5b83e7..6c0a94a88490ca615e243c3ba90dfd3169c35403 100644 (file)
--- 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;
 }
 
index c9dc16c232cc519552bb1184aeb5d557f5975833..7d659646b6b3460225d0dd7864ea630b03d09f70 100644 (file)
@@ -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);