|
|
c54a00 |
From 0cfbb0797ba1788e131cf964ca53adcde8209e1f Mon Sep 17 00:00:00 2001
|
|
|
c54a00 |
From: Ken Gaillot <kgaillot@redhat.com>
|
|
|
c54a00 |
Date: Thu, 21 Mar 2019 09:20:32 -0500
|
|
|
c54a00 |
Subject: [PATCH] Fix: libcrmcommon: pcmk_nvpair_t should handle NULL values
|
|
|
c54a00 |
|
|
|
c54a00 |
Detected by static analysis; if pcmk_prepend_nvpair() were given a NULL value,
|
|
|
c54a00 |
pcmk__new_nvpair() would try to strdup() it. Now, name is asserted to be
|
|
|
c54a00 |
non-NULL, and NULL values are set directly.
|
|
|
c54a00 |
---
|
|
|
c54a00 |
lib/common/nvpair.c | 10 +++++++---
|
|
|
c54a00 |
1 file changed, 7 insertions(+), 3 deletions(-)
|
|
|
c54a00 |
|
|
|
c54a00 |
diff --git a/lib/common/nvpair.c b/lib/common/nvpair.c
|
|
|
c54a00 |
index 5d6853f..e9fec8a 100644
|
|
|
c54a00 |
--- a/lib/common/nvpair.c
|
|
|
c54a00 |
+++ b/lib/common/nvpair.c
|
|
|
c54a00 |
@@ -33,7 +33,7 @@
|
|
|
c54a00 |
* \internal
|
|
|
c54a00 |
* \brief Allocate a new name/value pair
|
|
|
c54a00 |
*
|
|
|
c54a00 |
- * \param[in] name New name
|
|
|
c54a00 |
+ * \param[in] name New name (required)
|
|
|
c54a00 |
* \param[in] value New value
|
|
|
c54a00 |
*
|
|
|
c54a00 |
* \return Newly allocated name/value pair
|
|
|
c54a00 |
@@ -43,11 +43,15 @@
|
|
|
c54a00 |
static pcmk_nvpair_t *
|
|
|
c54a00 |
pcmk__new_nvpair(const char *name, const char *value)
|
|
|
c54a00 |
{
|
|
|
c54a00 |
- pcmk_nvpair_t *nvpair = calloc(1, sizeof(pcmk_nvpair_t));
|
|
|
c54a00 |
+ pcmk_nvpair_t *nvpair = NULL;
|
|
|
c54a00 |
|
|
|
c54a00 |
+ CRM_ASSERT(name);
|
|
|
c54a00 |
+
|
|
|
c54a00 |
+ nvpair = calloc(1, sizeof(pcmk_nvpair_t));
|
|
|
c54a00 |
CRM_ASSERT(nvpair);
|
|
|
c54a00 |
+
|
|
|
c54a00 |
nvpair->name = strdup(name);
|
|
|
c54a00 |
- nvpair->value = strdup(value);
|
|
|
c54a00 |
+ nvpair->value = value? strdup(value) : NULL;
|
|
|
c54a00 |
return nvpair;
|
|
|
c54a00 |
}
|
|
|
c54a00 |
|
|
|
c54a00 |
--
|
|
|
c54a00 |
1.8.3.1
|
|
|
c54a00 |
|