]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
util: serverLog using memory after free
authorCheyenne Wills <cwills@sinenomine.net>
Tue, 25 Jun 2019 16:40:53 +0000 (10:40 -0600)
committerStephan Wiesand <stephan.wiesand@desy.de>
Thu, 25 Jul 2019 14:02:17 +0000 (10:02 -0400)
clang's scan-build detected a "use of memory after it is freed"
condition.

The function OpenLogFile frees the variable ourName before creating a
duplicate of the name passed to it.  However there is a call that uses
ourName as the parameter: OpenLogFile(ourName).  This results in freeing
ourName then doing a strdup of the same memory location.

Test the passed parameter and if it's the same as ourName already skip
the free and strdup.

This bug was introduced in commit
    340ec2f79208ee21c3130c4b1c13995947ce426c
    "util: allocate log filename buffers"

Reviewed-on: https://gerrit.openafs.org/13659
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
(cherry picked from commit f5f59cd8d336b153e2b762bb7afd16e6ab1b1ee2)

Change-Id: Ia1ae1144493fa682595b365324322d8d273c0cbb
Reviewed-on: https://gerrit.openafs.org/13675
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
src/util/serverLog.c

index a250d6533ceb10f9108d3434b4da2e59f6deaaf7..13dbed87cc5c390fdfdf3612becb10dbb5125df9 100644 (file)
@@ -575,9 +575,12 @@ OpenLogFile(const char *fileName)
     RedirectStdStreams(fileName);
 
     /* Save our name for reopening. */
-    free(ourName);
-    ourName = strdup(fileName);
-    opr_Assert(ourName != NULL);
+    if (ourName != fileName) {
+       /* Make a copy if needed */
+       free(ourName);
+       ourName = strdup(fileName);
+       opr_Assert(ourName != NULL);
+    }
 
     serverLogFD = tempfd;