Module Name:    src
Committed By:   christos
Date:           Sat Aug 24 22:27:03 UTC 2024

Modified Files:
        src/lib/libcurses: get_wch.c

Log Message:
Check for returning ERR to avoid negative array index later (CID-1617248)


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libcurses/get_wch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libcurses/get_wch.c
diff -u src/lib/libcurses/get_wch.c:1.26 src/lib/libcurses/get_wch.c:1.27
--- src/lib/libcurses/get_wch.c:1.26	Mon Sep  6 03:45:48 2021
+++ src/lib/libcurses/get_wch.c	Sat Aug 24 18:27:03 2024
@@ -1,4 +1,4 @@
-/*   $NetBSD: get_wch.c,v 1.26 2021/09/06 07:45:48 rin Exp $ */
+/*   $NetBSD: get_wch.c,v 1.27 2024/08/24 22:27:03 christos Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: get_wch.c,v 1.26 2021/09/06 07:45:48 rin Exp $");
+__RCSID("$NetBSD: get_wch.c,v 1.27 2024/08/24 22:27:03 christos Exp $");
 #endif						  /* not lint */
 
 #include <errno.h>
@@ -135,7 +135,7 @@ inkey(wchar_t *wc, int to, int delay)
 			}
 
 			c = __fgetc_resize(infd);
-			if (ferror(infd)) {
+			if (c == ERR || ferror(infd)) {
 				clearerr(infd);
 				return c;
 			}
@@ -179,7 +179,7 @@ inkey(wchar_t *wc, int to, int delay)
 			}
 
 			c = __fgetc_resize(infd);
-			if (ferror(infd)) {
+			if (c == ERR || ferror(infd)) {
 				clearerr(infd);
 				return c;
 			}

Reply via email to