- Fix static analysis report about unhandled EOF on error conditions

when reading anchor key files.
This commit is contained in:
Yorgos Thessalonikefs 2025-02-19 11:24:49 +01:00
parent 72828ff81c
commit 5e1f35b59b
3 changed files with 19 additions and 8 deletions

View file

@ -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.

View file

@ -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);

View file

@ -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))