Closed FGasper closed 2 years ago
If empty lines follow a comment line, ldns_rr_new_frm_fp_l() appears to misreport the line count.
Compile and run the following:
#include <stdio.h> #include <ldns/ldns.h> void _parse_lines( const char *label, const char **lines ) { fprintf(stdout, "%s ==============\n", label); FILE *fp = tmpfile(); for (const char **l = lines; *l; l++) { fprintf(fp, "%s\n", *l); } fseek(fp, 0, SEEK_SET); int line_nr = 0; while (!feof(fp)) { ldns_status mystatus; ldns_rr *rr; mystatus = ldns_rr_new_frm_fp_l(&rr, fp, NULL, NULL, NULL, &line_nr); fprintf(stdout, "status: %d; line_nr: %d\n", mystatus, line_nr); ldns_rr_free(rr); } fclose(fp); } int main() { FILE *fp = tmpfile(); const char *no_comment_lines[] = { "foo.com. 400 IN NS ns1.blah.", "", "", "", "", "", "", "foo.com. 400 IN NS ns2.blah.", NULL }; const char *with_comment_lines[] = { "foo.com. 400 IN NS ns1.blah.", "; comment before blank lines", "", "", "", "", "", "", "foo.com. 400 IN NS ns2.blah.", NULL }; _parse_lines( "no comment", no_comment_lines ); _parse_lines( "with comment", with_comment_lines ); return 0; }
For me it outputs:
no comment ============== status: 0; line_nr: 7 status: 0; line_nr: 8 with comment ============== status: 0; line_nr: 1 status: 0; line_nr: 3
The no-comment parse is as I’d expect, but the 2nd line in the with-comment parse weirdly reports line_nr==3. Since there are 6 blank lines that doesn’t seem to make much sense … ?
This will be fixed in ldns-1.8.0 (was fixed with commit 889f7c71)
If empty lines follow a comment line, ldns_rr_new_frm_fp_l() appears to misreport the line count.
Compile and run the following:
For me it outputs:
The no-comment parse is as I’d expect, but the 2nd line in the with-comment parse weirdly reports line_nr==3. Since there are 6 blank lines that doesn’t seem to make much sense … ?