libafscp: Avoid use of memory after freed

Clang's scan-build static analysis tool flagged a 'Use of memory after
it is freed'

The function _DirUpdate can reallocate the storage that is pointed to
by the dirbuffer member of the DirHeader structure.

The code in afscp_DirLookup initializes a local variable to d->dirbuffer
before calling _DirUpdate.

Update afscp_dir.c to initialize the local variable 'h' after calling
_DirUpdate.

Change-Id: Ibfc8b25ac31998f8581185f896737ca4bc27da7e
Reviewed-on: https://gerrit.openafs.org/14713
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
This commit is contained in:
Cheyenne Wills 2021-06-22 15:21:50 -06:00 committed by Michael Meffie
parent c220ac7a9f
commit f5eb9f7452

View File

@ -289,13 +289,14 @@ afscp_DirLookup(struct afscp_dirstream *d, const char *name)
{
int code;
int hval, entry;
struct DirHeader *h = (struct DirHeader *)d->dirbuffer;
struct DirHeader *h;
struct DirEntry *info;
code = _DirUpdate(d);
if (code != 0) {
return NULL;
}
h = (struct DirHeader *)d->dirbuffer;
hval = namehash(name);
entry = ntohs(h->hashTable[hval]);