]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix static analysis report about unhandled EOF on error conditions
authorYorgos Thessalonikefs <yorgos@nlnetlabs.nl>
Wed, 19 Feb 2025 10:24:49 +0000 (11:24 +0100)
committerYorgos Thessalonikefs <yorgos@nlnetlabs.nl>
Wed, 19 Feb 2025 10:24:49 +0000 (11:24 +0100)
  when reading anchor key files.

doc/Changelog
testcode/unitldns.c
validator/val_anchor.c

index e4d8aada0f4a52d7b6b7a98d4cc42cf24b0ef6d3..435bcfa212decc8096623f1a014328d3dfd16fa8 100644 (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.
index d226ee203c10a5fe3af2dcb412f7754ac7be5bb0..f8409fec71b15398b1e911f8721d49878ec53903 100644 (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);
index 7a52562646bd81f5ea74dbaaf0c298d41f538375..ab41fa48402ae86050bf80bd3450494c6a284ecc 100644 (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))