pts: Fix stringop-overflow warnings 69/14769/4
authorMichael Meffie <mmeffie@sinenomine.net>
Mon, 23 Aug 2021 23:43:45 +0000 (19:43 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Tue, 7 Sep 2021 01:50:26 +0000 (21:50 -0400)
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 <cwills@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/ptserver/pts.c
src/ptserver/testpt.c

index e749714..90d6f16 100644 (file)
@@ -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);
index eaaee48..c359f8f 100644 (file)
@@ -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);