changeset 37033:de0c74742689

Fix handling of overlong termcap strings entries. The previous code would silently truncate and then read out of bounds later in a memcmp.
author reimar
date Sun, 06 Apr 2014 18:10:31 +0000
parents 4c7ab9a4f3cd
children cc50b327cffa
files osdep/getch2.c
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/osdep/getch2.c	Sun Apr 06 17:57:33 2014 +0000
+++ b/osdep/getch2.c	Sun Apr 06 18:10:31 2014 +0000
@@ -100,7 +100,12 @@
   if(!p) return;
   if(getch2_key_db>=MAX_KEYS) return;
   getch2_keys[getch2_key_db].len=strlen(p);
-  strncpy(getch2_keys[getch2_key_db].chars,p,8);
+  if (getch2_keys[getch2_key_db].len >= sizeof(getch2_keys[getch2_key_db].chars))
+  {
+    printf("Key string entry more than 7 characters, ignoring\n");
+    return;
+  }
+  strcpy(getch2_keys[getch2_key_db].chars,p);
   getch2_keys[getch2_key_db].code=code;
   ++getch2_key_db;
 /*  printf("%s=%s\n",id,p); */