]> granicus.if.org Git - nethack/commitdiff
Prevent out of array access
authorPasi Kallinen <paxed@alt.org>
Sat, 31 Oct 2015 23:32:20 +0000 (01:32 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 31 Oct 2015 23:32:24 +0000 (01:32 +0200)
As index() can match with the string terminator, that would make
the xdir etc array references out of bounds.

src/cmd.c

index 6cf2363a31ae42b5e05e4b5081c96d4bc73d8176..5bcd57fa5027af7d79cf991abdcd87297ba019e4 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -3472,7 +3472,7 @@ char sym;
     register const char *dp = index(Cmd.dirchars, sym);
 
     u.dz = 0;
-    if (!dp)
+    if (!dp || !*dp)
         return 0;
     u.dx = xdir[dp - Cmd.dirchars];
     u.dy = ydir[dp - Cmd.dirchars];