From 16e78e5b608077cdaef38f5acff546307da911f6 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 18 Dec 2018 02:44:21 -0800 Subject: [PATCH] plug potential open file leak in checkfile() Another item from static analysis. If an internal error ever caused the "bad do_look buffer" warning from checkfile(), open file 'data' would not be closed. (The bug in checkfile()'s caller which prompted that check was fixed long go.) An alternate fix would be to move the input buffer check to before the file is opened, but verifying the file first seems worthwhile. --- src/pager.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pager.c b/src/pager.c index 22df977e4..6982860c9 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 pager.c $NHDT-Date: 1543185072 2018/11/25 22:31:12 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.139 $ */ +/* NetHack 3.6 pager.c $NHDT-Date: 1545129848 2018/12/18 10:44:08 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.142 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2018. */ /* NetHack may be freely redistributed. See license for details. */ @@ -527,14 +527,14 @@ char *supplemental_name; fp = dlb_fopen(DATAFILE, "r"); if (!fp) { - pline("Cannot open data file!"); + pline("Cannot open 'data' file!"); return; } /* If someone passed us garbage, prevent fault. */ if (!inp || strlen(inp) > (BUFSZ - 1)) { impossible("bad do_look buffer passed (%s)!", !inp ? "null" : "too long"); - return; + goto checkfile_done; } /* To prevent the need for entries in data.base like *ngel to account -- 2.40.0