From b7f1763652fb932ca5bd3f3351a48df11e58f2dc Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Mon, 28 Jul 2014 17:27:40 -0400 Subject: [PATCH] libafs: do not allow NULL creds for afs_CreateReq Do not allow callers to pass a NULL cred to afs_CreateReq. This avoids setting the uid of zero in the vrequest when no cred is passed. Update callers to pass afs_osi_credp for an anonymous cred when no cred is available. Thanks to Andrew Deason for pointing out afs_osi_credp should be used. Change-Id: I05f694026ec72ab701160d9920e47c16cda46cd7 Reviewed-on: http://gerrit.openafs.org/11336 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: D Brashear --- src/afs/afs_osi_pag.c | 17 +++++++---------- src/afs/afs_osi_vget.c | 2 +- src/afs/afs_vcache.c | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/afs/afs_osi_pag.c b/src/afs/afs_osi_pag.c index ec85e23..309dcaa 100644 --- a/src/afs/afs_osi_pag.c +++ b/src/afs/afs_osi_pag.c @@ -496,7 +496,8 @@ afs_InitReq(struct vrequest *av, afs_ucred_t *acred) * for osi_AllocSmallSpace() and osi_FreeSmallSpace(). * * \param[out] avpp address of the vrequest pointer - * \param[in] acred user credentials to setup the vrequest; may be NULL + * \param[in] acred user credentials to setup the vrequest + * afs_osi_credp should be used for anonymous connections * \return 0 on success */ int @@ -508,21 +509,17 @@ afs_CreateReq(struct vrequest **avpp, afs_ucred_t *acred) if (afs_shuttingdown) { return EIO; } - if (!avpp) { + if (!avpp || !acred) { return EINVAL; } treq = osi_AllocSmallSpace(sizeof(struct vrequest)); if (!treq) { return ENOMEM; } - if (!acred) { - memset(treq, 0, sizeof(struct vrequest)); - } else { - code = afs_InitReq(treq, acred); - if (code != 0) { - osi_FreeSmallSpace(treq); - return code; - } + code = afs_InitReq(treq, acred); + if (code != 0) { + osi_FreeSmallSpace(treq); + return code; } *avpp = treq; return 0; diff --git a/src/afs/afs_osi_vget.c b/src/afs/afs_osi_vget.c index 822ab08..5fd36bf 100644 --- a/src/afs/afs_osi_vget.c +++ b/src/afs/afs_osi_vget.c @@ -60,7 +60,7 @@ afs_osi_vget(struct vcache **avcpp, struct fid *afidp, struct vrequest *areqp) code = ENOENT; } else if (ret == 0) { /* didn't find an entry. */ - code = afs_CreateReq(&treq, NULL); + code = afs_CreateReq(&treq, afs_osi_credp); if (code == 0) { *avcpp = afs_GetVCache(&vfid, treq, NULL, NULL); afs_DestroyReq(treq); diff --git a/src/afs/afs_vcache.c b/src/afs/afs_vcache.c index dcdc8d9..4b6ba7a 100644 --- a/src/afs/afs_vcache.c +++ b/src/afs/afs_vcache.c @@ -1001,7 +1001,7 @@ afs_FlushActiveVcaches(afs_int32 doflocks) XSTATS_DECLS; AFS_STATCNT(afs_FlushActiveVcaches); - code = afs_CreateReq(&treq, NULL); + code = afs_CreateReq(&treq, afs_osi_credp); if (code) { afs_warn("unable to alloc treq\n"); return; -- 1.9.4