|
|
60de42 |
From a7476dd96e79197f65acf0f049f75ce8e8f9e801 Mon Sep 17 00:00:00 2001
|
|
|
60de42 |
From: Jan Pokorny <jpokorny@redhat.com>
|
|
|
60de42 |
Date: Thu, 2 Feb 2017 14:51:46 +0100
|
|
|
60de42 |
Subject: [PATCH] Fix: crm_mon: protect against non-standard or failing asctime
|
|
|
60de42 |
|
|
|
60de42 |
So far, we have been likely covered by standards requiring asctime to
|
|
|
60de42 |
produce an output ending with \n\0 bytes, because otherwise, we would
|
|
|
60de42 |
overrun the buffer, reading unspecified content, possibly segfaulting.
|
|
|
60de42 |
This was actually discovered with a brand new GCC7 warning
|
|
|
60de42 |
( [-Werror=pointer-compare]).
|
|
|
60de42 |
|
|
|
60de42 |
Another latent issue was that the code was not ready for the case
|
|
|
60de42 |
of failing asctime call (returning NULL). This is now fixed as well.
|
|
|
60de42 |
---
|
|
|
60de42 |
tools/crm_mon.c | 6 +++---
|
|
|
60de42 |
1 file changed, 3 insertions(+), 3 deletions(-)
|
|
|
60de42 |
|
|
|
60de42 |
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
|
|
|
60de42 |
index 776aea8..023b07b 100644
|
|
|
60de42 |
--- a/tools/crm_mon.c
|
|
|
60de42 |
+++ b/tools/crm_mon.c
|
|
|
60de42 |
@@ -954,10 +954,10 @@ print_nvpair(FILE *stream, const char *name, const char *value,
|
|
|
60de42 |
|
|
|
60de42 |
/* Otherwise print user-friendly time string */
|
|
|
60de42 |
} else {
|
|
|
60de42 |
- char *date_str, *c;
|
|
|
60de42 |
+ static char empty_str[] = "";
|
|
|
60de42 |
+ char *c, *date_str = asctime(localtime(&epoch_time));
|
|
|
60de42 |
|
|
|
60de42 |
- date_str = asctime(localtime(&epoch_time));
|
|
|
60de42 |
- for (c = date_str; c != '\0'; ++c) {
|
|
|
60de42 |
+ for (c = (date_str != NULL) ? date_str : empty_str; *c != '\0'; ++c) {
|
|
|
60de42 |
if (*c == '\n') {
|
|
|
60de42 |
*c = '\0';
|
|
|
60de42 |
break;
|
|
|
60de42 |
--
|
|
|
60de42 |
1.8.3.1
|
|
|
60de42 |
|