From f9f1236f264878b3fb4d020f0cf306c03a733229 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Thu, 8 Nov 2018 21:02:24 +0200 Subject: [PATCH] Fix some buffer underflows --- src/objnam.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/objnam.c b/src/objnam.c index c9d00f6ab..bf108c472 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -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 "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; } -- 2.40.0