afs: check for non-NULL before memset in afs_LookupName 83/15283/3
authorStephan Wiesand <stephan.wiesand@desy.de>
Wed, 18 Jan 2023 13:18:08 +0000 (14:18 +0100)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 19 Jan 2023 23:58:34 +0000 (18:58 -0500)
Commit 981bc005f8161ca9ee52ea281c7d73e0e4e2461a refactored PNewStatMount
and PFlushMount by moving their common logic to a new function
afs_LookupName(). In this function, the output parameters are zeroed.
However, this is done before checking that their pointers are valid.
Add additional checks before memset().

Change-Id: I134550d5f9b6d5a9aa5c360e260335d2efce884a
Reviewed-on: https://gerrit.openafs.org/15283
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/afs/afs_pioctl.c

index 94ee107..3b7ff9e 100644 (file)
@@ -2204,8 +2204,11 @@ afs_LookupName(struct vcache *avc, struct vrequest *areq, char *aname,
     struct dcache *tdc;
     afs_size_t offset, len;
 
-    memset(asys, 0, sizeof(*asys));
-    memset(afid, 0, sizeof(*afid));
+    /* do not leave garbage in the output parameters in error cases */
+    if (asys != NULL)
+       memset(asys, 0, sizeof(*asys));
+    if (afid != NULL)
+       memset(afid, 0, sizeof(*afid));
 
     if (!avc || !areq || !aname || !asys || !afid) {
        afs_warn("afs: Internal error, bad args to afs_LookupName: %p, %p, %p, "