From: Cheyenne Wills Date: Tue, 2 Jul 2019 22:58:28 +0000 (-0600) Subject: ptserver: testpt.c format-overflow warning X-Git-Tag: upstream/1.8.6_pre1^2~47 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=d5c2f53e9488311b294d871894967f78949699b6;p=packages%2Fo%2Fopenafs.git ptserver: testpt.c format-overflow warning GCC 9 introduced new warnings/errors and is flagging a sprintf with a format-overflow warning. With --checking-enabled, this error is causing testpt.c to fail during compile. Change the buffer size from 16 bytes to PR_MAXNAMELEN+1 and use snprintf instead of sprintf. Generate an error message and exit if snprintf truncates the string. Reviewed-on: https://gerrit.openafs.org/13663 Reviewed-by: Cheyenne Wills Tested-by: BuildBot Reviewed-by: Benjamin Kaduk (cherry picked from commit 4a57cc54dfb6789a86ee735360ee44209c1a901a) Change-Id: I2f8012e7fb4384f3ad877d2c9beb5f00b03716b8 Reviewed-on: https://gerrit.openafs.org/13730 Reviewed-by: Andrew Deason Reviewed-by: Marcio Brito Barbosa Reviewed-by: Michael Meffie Tested-by: BuildBot Reviewed-by: Stephan Wiesand --- diff --git a/src/ptserver/testpt.c b/src/ptserver/testpt.c index 8deb88340..3888718e2 100644 --- a/src/ptserver/testpt.c +++ b/src/ptserver/testpt.c @@ -255,7 +255,7 @@ void CreateGroup(int g) { afs_int32 code; - char name[16]; + char name[PR_MAXNAMELEN + 1]; afs_int32 id = 0; afs_int32 owner = 0; char *ownerName = NULL; @@ -286,7 +286,12 @@ CreateGroup(int g) break; } - sprintf(name, "%s:%s%d", ownerName, createPrefix, g); + code = snprintf(name, sizeof(name), "%s:%s%d", ownerName, createPrefix, g); + if (code >= sizeof(name)) { + fprintf(stderr, "%s: generated group name is too long: %s:%s%d\n", + whoami, ownerName, createPrefix, g); + exit(13); + } code = ubik_PR_NewEntry(pruclient, 0, name, PRGRP, owner, &id); if (code) { if (code == PREXIST) {