Fix some buffer underflows

This commit is contained in:
Pasi Kallinen
2018-11-08 21:02:24 +02:00
parent afd793e9b7
commit f9f1236f26

View File

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