5293ab9 Bug 699907 - (cov#10843) Use of uninitialized variable in logging code

Authored and Committed by nkinder 13 years ago
    Bug 699907 - (cov#10843) Use of uninitialized variable in logging code
    
    The first time that logMsg is called, logEnabled and enableVerified will
    both be 0. This will cause us to fill in the logfile buffer with the file
    name and then check for the existence of the logfile. If the logfile does
    not exist, we leave enable_verified set and log_enable unset. This will
    make future calls to logMsg() just return at line 82.
    
    If we were able to access the file fine for reading the first time logMsg()
    is called at line 90, we will then go into the if condition at line 100
    to set logfp. We are guaranteed that logfile is filled in at this point.
    Further calls to logMsg() will have logfp set, so we no longer need logfile
    to be filled in.
    
    The problem here is that the call to fopen() at line 101 might fail, leaving
    logfp NULL and log_enabled set to 1. The next time logMsg() is called, we
    would call fopen again at line 101, but logfile would not be filled in.
    
    To fix this, we should not set log_enabled to 1 unless we have successfully
    opened the log file for writing.  I also moved the code around so we only
    attempt to call fopen on the file if we have filled the filename buffer in.
    
        
file modified
+22 -16