From: Yorgos Thessalonikefs Date: Wed, 19 Feb 2025 10:24:49 +0000 (+0100) Subject: - Fix static analysis report about unhandled EOF on error conditions X-Git-Tag: release-1.23.0rc1~49 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=5e1f35b59b7f4d8731be6f2f2090bc2aad180301;p=thirdparty%2Funbound.git - Fix static analysis report about unhandled EOF on error conditions when reading anchor key files. --- diff --git a/doc/Changelog b/doc/Changelog index e4d8aada0..435bcfa21 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +19 February 2025: Yorgos + - Fix static analysis report about unhandled EOF on error conditions + when reading anchor key files. + 17 February 2025: Yorgos - Consider reconfigurations when calculating the still_useful_timeout for servers in the infrastructure cache. diff --git a/testcode/unitldns.c b/testcode/unitldns.c index d226ee203..f8409fec7 100644 --- a/testcode/unitldns.c +++ b/testcode/unitldns.c @@ -172,10 +172,14 @@ rr_test_file(const char* input, const char* check) if(txt_in[0] == 0 || txt_in[0] == '\n' || txt_in[0] == ';') continue; /* read check lines */ - if(!fgets(wire_chk, (int)bufs, chf)) + if(!fgets(wire_chk, (int)bufs, chf)) { printf("%s too short\n", check); - if(!fgets(txt_chk, (int)bufs, chf)) + unit_assert(0); + } + if(!fgets(txt_chk, (int)bufs, chf)) { printf("%s too short\n", check); + unit_assert(0); + } chlineno += 2; if(vbmp) printf("%s:%d %s", check, chlineno-1, wire_chk); if(vbmp) printf("%s:%d %s", check, chlineno, txt_chk); diff --git a/validator/val_anchor.c b/validator/val_anchor.c index 7a5256264..ab41fa484 100644 --- a/validator/val_anchor.c +++ b/validator/val_anchor.c @@ -483,11 +483,10 @@ anchor_read_file(struct val_anchors* anchors, sldns_buffer* buffer, /** skip file to end of line */ static void -skip_to_eol(FILE* in) +skip_to_eol(FILE* in, int *c) { - int c; - while((c = getc(in)) != EOF ) { - if(c == '\n') + while((*c = getc(in)) != EOF ) { + if(*c == '\n') return; } } @@ -534,7 +533,8 @@ readkeyword_bindfile(FILE* in, sldns_buffer* buf, int* line, int comments) int numdone = 0; while((c = getc(in)) != EOF ) { if(comments && c == '#') { /* # blabla */ - skip_to_eol(in); + skip_to_eol(in, &c); + if(c == EOF) return 0; (*line)++; continue; } else if(comments && c=='/' && numdone>0 && /* /_/ bla*/ @@ -542,7 +542,8 @@ readkeyword_bindfile(FILE* in, sldns_buffer* buf, int* line, int comments) sldns_buffer_position(buf)-1) == '/') { sldns_buffer_skip(buf, -1); numdone--; - skip_to_eol(in); + skip_to_eol(in, &c); + if(c == EOF) return 0; (*line)++; continue; } else if(comments && c=='*' && numdone>0 && /* /_* bla *_/ */ @@ -559,6 +560,7 @@ readkeyword_bindfile(FILE* in, sldns_buffer* buf, int* line, int comments) if(c == '\n') (*line)++; } + if(c == EOF) return 0; continue; } /* not a comment, complete the keyword */ @@ -593,6 +595,7 @@ readkeyword_bindfile(FILE* in, sldns_buffer* buf, int* line, int comments) break; } } + if(c == EOF) return 0; return numdone; } if(is_bind_special(c))