Blob Blame History Raw
From 4fefc3908ce527de4ca3d7386886c2447d6b4c14 Mon Sep 17 00:00:00 2001
From: David Rheinsberg <david.rheinsberg@gmail.com>
Date: Tue, 19 Apr 2022 13:29:53 +0200
Subject: [PATCH] launch/config: keep empty cdata around

We expect the `node->cdata` pointer to contain the actual content of an
XML entry. Make sure it is initialized to an empty string, so we can
dereference it without checking for validity everywhere.

Note that we want it to be an owned string, to allow claiming the value.
We will avoid any `n_cdata + 'static ""` here, to keep the code simple.
The performance of that strdup() merely affects XML parsing, no bus
runtime.

Reported-by: Steffen Robertz
Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
---
 src/launch/config.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/launch/config.c b/src/launch/config.c
index 490d7b7d..cb7e3fae 100644
--- a/src/launch/config.c
+++ b/src/launch/config.c
@@ -133,6 +133,10 @@ int config_node_new(ConfigNode **nodep, ConfigNode *parent, unsigned int type) {
                 break;
         }
 
+        node->cdata = strdup("");
+        if (!node->cdata)
+                return error_origin(-ENOMEM);
+
         *nodep = node;
         node = NULL;
         return 0;