diff options
author | Jeremy Allison <jra@samba.org> | 2006-06-14 21:36:49 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:17:26 -0500 |
commit | a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1 (patch) | |
tree | 14c15c8333572c5a2e089611ee61d03010a9d2b4 /source3/utils/net_cache.c | |
parent | 2b99951e7511d0ec2d928c06b05fe22b7b6572d1 (diff) | |
download | samba-a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1.tar.gz samba-a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1.tar.bz2 samba-a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1.zip |
r16230: Fix Klocwork #861 and others. localtime and asctime
can return NULL. Ensure we check all returns correctly.
Jeremy.
(This used to be commit 6c61dc8ed6d84f310ef391fb7700e93ef42c4afc)
Diffstat (limited to 'source3/utils/net_cache.c')
-rw-r--r-- | source3/utils/net_cache.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/source3/utils/net_cache.c b/source3/utils/net_cache.c index 0c107a5f01..69b3327f7a 100644 --- a/source3/utils/net_cache.c +++ b/source3/utils/net_cache.c @@ -37,24 +37,36 @@ static void print_cache_entry(const char* keystr, const char* datastr, const time_t timeout, void* dptr) { - char* timeout_str; + char *timeout_str; time_t now_t = time(NULL); struct tm timeout_tm, *now_tm; /* localtime returns statically allocated pointer, so timeout_tm has to be copied somewhere else */ - memcpy(&timeout_tm, localtime(&timeout), sizeof(struct tm)); + + now_tm = localtime(&timeout); + if (!now_tm) { + return; + } + memcpy(&timeout_tm, now_tm, sizeof(struct tm)); now_tm = localtime(&now_t); + if (!now_tm) { + return; + } /* form up timeout string depending whether it's today's date or not */ if (timeout_tm.tm_year != now_tm->tm_year || - timeout_tm.tm_mon != now_tm->tm_mon || - timeout_tm.tm_mday != now_tm->tm_mday) { + timeout_tm.tm_mon != now_tm->tm_mon || + timeout_tm.tm_mday != now_tm->tm_mday) { - timeout_str = asctime(&timeout_tm); - timeout_str[strlen(timeout_str) - 1] = '\0'; /* remove tailing CR */ - } else + timeout_str = asctime(&timeout_tm); + if (!timeout_str) { + return; + } + timeout_str[strlen(timeout_str) - 1] = '\0'; /* remove tailing CR */ + } else { asprintf(&timeout_str, "%.2d:%.2d:%.2d", timeout_tm.tm_hour, timeout_tm.tm_min, timeout_tm.tm_sec); + } d_printf("Key: %s\t Timeout: %s\t Value: %s %s\n", keystr, timeout_str, datastr, timeout > now_t ? "": "(expired)"); |