]> granicus.if.org Git - nethack/commitdiff
Fix some buffer underflows
authorPasi Kallinen <paxed@alt.org>
Thu, 8 Nov 2018 19:02:24 +0000 (21:02 +0200)
committerPasi Kallinen <paxed@alt.org>
Thu, 8 Nov 2018 19:02:24 +0000 (21:02 +0200)
src/objnam.c

index c9d00f6abe8182206b243899aa335ca307e39339..bf108c4723c9b5330fe67adf7d3e8d2313a68a6a 100644 (file)
@@ -2086,6 +2086,7 @@ const char *const *alt_as_is; /* another set like as_is[] */
     const struct sing_plur *sp;
     const char *same, *other, *const *as;
     int al;
+    int baselen = strlen(basestr);
 
     for (as = as_is; *as; ++as) {
         al = (int) strlen(*as);
@@ -2112,20 +2113,20 @@ const char *const *alt_as_is; /* another set like as_is[] */
     }
     /* skip "ox" -> "oxen" entry when pluralizing "<something>ox"
        unless it is muskox */
-    if (to_plural && strlen(basestr) > 2 && !strcmpi(endstring - 2, "ox")
-        && strcmpi(endstring - 6, "muskox")) {
+    if (to_plural && baselen > 2 && !strcmpi(endstring - 2, "ox")
+        && baselen > 5 && strcmpi(endstring - 6, "muskox")) {
         /* "fox" -> "foxes" */
         Strcasecpy(endstring, "es");
         return TRUE;
     }
     if (to_plural) {
-        if (!strcmpi(endstring - 3, "man")
+        if (baselen > 2 && !strcmpi(endstring - 3, "man")
             && badman(basestr, to_plural)) {
             Strcasecpy(endstring, "s");
             return TRUE;
         }
     } else {
-        if (!strcmpi(endstring - 3, "men")
+        if (baselen > 2 && !strcmpi(endstring - 3, "men")
             && badman(basestr, to_plural))
             return TRUE;
     }