]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
cfg: avoid UB on FILE stream marked as error
authorDaiki Ueno <ueno@gnu.org>
Wed, 23 Jul 2025 04:55:17 +0000 (13:55 +0900)
committerDaiki Ueno <ueno@gnu.org>
Thu, 24 Jul 2025 05:52:48 +0000 (14:52 +0900)
Spotted by clang-analyzer 19.

Signed-off-by: Daiki Ueno <ueno@gnu.org>
src/cfg.c

index 705f912555ea2313431e0953e23ea1b97a91eabd..9a9627f180edb02dc571d8c922ef893854ead1be 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -104,8 +104,10 @@ static int parser_getc(struct parser_st *parser)
        if (parser->pushback_length > 0) {
                return parser->pushback[--parser->pushback_length];
        }
-       int c = getc(parser->fp);
-       return c;
+       if (feof(parser->fp) || ferror(parser->fp)) {
+               return EOF;
+       }
+       return getc(parser->fp);
 }
 
 static void parser_ungetc(struct parser_st *parser, int c)