From: Michael Meffie Date: Mon, 23 Aug 2021 23:43:45 +0000 (-0400) Subject: pts: Fix stringop-overflow warnings X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=a3aac5106beddc5a6f7a09c2d21c2524342aca01 pts: Fix stringop-overflow warnings The ptutil functions are defined to accept bounded character arrays for user and group names. As of GCC 11, callers which provide the names as string literals now trigger the stringop-overflow warning, since the regions provided by the string literals are smaller than the bounded areas. error: ‘pr_ChangeEntry’ accessing 64 bytes in a region of size 1 [-Werror=stringop-overflow=] note: referencing argument 4 of type ‘char *’ error: ‘pr_IsAMemberOf’ accessing 64 bytes in a region of size 22 [-Werror=stringop-overflow=] note: referencing argument 2 of type ‘char *’ error: ‘pr_CreateUser’ accessing 64 bytes in a region of size 16 [-Werror=stringop-overflow=] note: referencing argument 1 of type ‘char *’ error: ‘pr_Delete’ accessing 64 bytes in a region of size 16 [-Werror=stringop-overflow=] note: referencing argument 1 of type ‘char *’ Update the callers in pts and testpt which pass literal strings. Instead of passing char pointers to literal strings, assign the strings to prname buffers and pass the prname buffers to the pr utility functions. Change-Id: I7d8c67aa28d21bb6889ef92a2193a77b54c83cb1 Reviewed-on: https://gerrit.openafs.org/14769 Reviewed-by: Cheyenne Wills Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- diff --git a/src/ptserver/pts.c b/src/ptserver/pts.c index e749714..90d6f16 100644 --- a/src/ptserver/pts.c +++ b/src/ptserver/pts.c @@ -663,6 +663,7 @@ CheckEntry(struct cmd_syndesc *as, void *arock) idlist ids; idlist lids; struct prcheckentry aentry; + prname admins = "system:administrators"; if (GetNameOrId(as, &ids, &names)) return PRBADARG; @@ -728,7 +729,7 @@ CheckEntry(struct cmd_syndesc *as, void *arock) } if (aentry.id == SYSADMINID) admin = 1; - else if (!pr_IsAMemberOf(aentry.name, "system:administrators", &flag)) { + else if (!pr_IsAMemberOf(aentry.name, admins, &flag)) { if (flag) admin = 1; } @@ -791,11 +792,12 @@ ChownGroup(struct cmd_syndesc *as, void *arock) { afs_int32 code; char *name; + prname newname = ""; char *owner; name = as->parms[0].items->data; owner = as->parms[1].items->data; - code = pr_ChangeEntry(name, "", 0, owner); + code = pr_ChangeEntry(name, newname, 0, owner); if (code) afs_com_err(whoami, code, "; unable to change owner of %s to %s", name, owner); @@ -808,10 +810,11 @@ ChangeName(struct cmd_syndesc *as, void *arock) afs_int32 code; char *oldname; char *newname; + prname owner = ""; oldname = as->parms[0].items->data; newname = as->parms[1].items->data; - code = pr_ChangeEntry(oldname, newname, 0, ""); + code = pr_ChangeEntry(oldname, newname, 0, owner); if (code) afs_com_err(whoami, code, "; unable to change name of %s to %s", oldname, newname); diff --git a/src/ptserver/testpt.c b/src/ptserver/testpt.c index eaaee48..c359f8f 100644 --- a/src/ptserver/testpt.c +++ b/src/ptserver/testpt.c @@ -217,7 +217,7 @@ void CreateUser(int u) { afs_int32 code; - char name[16]; + prname name; afs_int32 id; sprintf(name, "%s%d", createPrefix, u);