From: Michael R Sweet Date: Sat, 6 Apr 2024 13:37:09 +0000 (-0400) Subject: Use size_t for buffer size and make sure it is at least 4 bytes long (Issue #921) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=497e2527f1b0a99bb623a4b697ce756f923511e9;p=thirdparty%2Fcups.git Use size_t for buffer size and make sure it is at least 4 bytes long (Issue #921) --- diff --git a/locale/checkpo.c b/locale/checkpo.c index 8e31aeb13b..7baf33a581 100644 --- a/locale/checkpo.c +++ b/locale/checkpo.c @@ -24,7 +24,7 @@ * Local functions... */ -static char *abbreviate(const char *s, char *buf, int bufsize); +static char *abbreviate(const char *s, char *buf, size_t bufsize); static cups_array_t *collect_formats(const char *id); static void free_formats(cups_array_t *fmts); @@ -292,11 +292,17 @@ main(int argc, /* I - Number of command-line args */ static char * /* O - Abbreviated string */ abbreviate(const char *s, /* I - String to abbreviate */ char *buf, /* I - Buffer */ - int bufsize) /* I - Size of buffer */ + size_t bufsize) /* I - Size of buffer */ { char *bufptr; /* Pointer into buffer */ + if (bufsize < 4) + { + *buf = '\0'; + return (buf); + } + for (bufptr = buf, bufsize -= 4; *s && bufsize > 0; s ++) { if (*s == '\n')