From f5eb9f74529d2c544dfb9c3c8deb03a333ee5bde Mon Sep 17 00:00:00 2001 From: Cheyenne Wills Date: Tue, 22 Jun 2021 15:21:50 -0600 Subject: [PATCH] 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 Tested-by: BuildBot Reviewed-by: Michael Meffie --- src/libafscp/afscp_dir.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libafscp/afscp_dir.c b/src/libafscp/afscp_dir.c index 3a24a4b96b..3ee49e982e 100644 --- a/src/libafscp/afscp_dir.c +++ b/src/libafscp/afscp_dir.c @@ -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]);