From 5c6c5073dd716c5f9a9cbac8808f3df0aa0e2533 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 16 Oct 2013 12:39:42 +0200 Subject: [PATCH] Fix crash when entry in linphonerc is empty + don't convert commented entries --- tools/lpc2xml.c | 12 +++++++++--- tools/xml2lpc.c | 14 ++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/lpc2xml.c b/tools/lpc2xml.c index 39fd62b0e..77cd0cb1a 100644 --- a/tools/lpc2xml.c +++ b/tools/lpc2xml.c @@ -93,12 +93,18 @@ static void lpc2xml_genericxml_warning(void *ctx, const char *fmt, ...) { */ static int processEntry(const char *section, const char *entry, xmlNode *node, lpc2xml_context *ctx) { + const char *comment = "#"; + if (strncmp(comment, entry, strlen(comment)) == 0) { + lpc2xml_log(ctx, LPC2XML_WARNING, "Skipped commented entry %s", entry); + return 0; + } + const char *content = lp_config_get_string(ctx->lpc, section, entry, NULL); - if(content == NULL) { - lpc2xml_log(ctx->ctx, LPC2XML_ERROR, "Issue when reading the lpc"); + if (content == NULL) { + lpc2xml_log(ctx, LPC2XML_ERROR, "Issue when reading the lpc"); return -1; } - + lpc2xml_log(ctx, LPC2XML_MESSAGE, "Set %s|%s = %s", section, entry, content); xmlNodeSetContent(node, (const xmlChar *) content); return 0; diff --git a/tools/xml2lpc.c b/tools/xml2lpc.c index c9a5c94e2..d02133674 100644 --- a/tools/xml2lpc.c +++ b/tools/xml2lpc.c @@ -114,15 +114,18 @@ static void dumpNodes(int level, xmlNode * a_node, xml2lpc_context *ctx) { static void dumpNode(xmlNode *node, xml2lpc_context *ctx) { - xml2lpc_log(ctx, XML2LPC_DEBUG, "node type: %d, name: %s", node->type, node->name); + xml2lpc_log(ctx, XML2LPC_DEBUG, "node type: %d, name: %s", node->type, node->name); } static void dumpAttr(xmlNode *node, xml2lpc_context *ctx) { - xml2lpc_log(ctx, XML2LPC_DEBUG, "attr name: %s value:%s", node->name, node->children->content); + xml2lpc_log(ctx, XML2LPC_DEBUG, "attr name: %s value:%s", node->name, node->children->content); } static void dumpContent(xmlNode *node, xml2lpc_context *ctx) { - xml2lpc_log(ctx, XML2LPC_DEBUG, "content: %s", node->children->content); + if (node->children) + xml2lpc_log(ctx, XML2LPC_DEBUG, "content: %s", node->children->content); + else + xml2lpc_log(ctx, XML2LPC_DEBUG, "content: "); } static int processEntry(xmlElement *element, const char *sectionName, xml2lpc_context *ctx) { @@ -142,8 +145,11 @@ static int processEntry(xmlElement *element, const char *sectionName, xml2lpc_co } } - value = (const char *)element->children->content; dumpContent((xmlNode *)element, ctx); + if (element->children) + value = (const char *)element->children->content; + else + value = ""; if(name != NULL) { const char *str = lp_config_get_string(ctx->lpc, sectionName, name, NULL);