diff mbox series

suricatta: general: fix crash without config file

Message ID 20181217161443.11916-1-sbabic@denx.de
State Accepted
Headers show
Series suricatta: general: fix crash without config file | expand

Commit Message

Stefano Babic Dec. 17, 2018, 4:14 p.m. UTC
If no configuration data is passed, the server crashes (strdup called
with NULL argument). Without configuration file, no identify data can be
retrieved: the identify data is used to format the query string to the
server, that results Null. This is not correct and the URL is set to the
one passed via command line.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 suricatta/server_general.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/suricatta/server_general.c b/suricatta/server_general.c
index 1055957..6318224 100644
--- a/suricatta/server_general.c
+++ b/suricatta/server_general.c
@@ -246,6 +246,11 @@  static void *server_progress_thread (void *data)
 	if (!prog) {
 		ERROR("Fatal Error: thread without data !");
 	}
+	if (!prog->url || !strlen(prog->url)) {
+		INFO("No url for logging...no result sent");
+		pthread_exit((void *)SERVER_EINIT);
+	}
+
 	channel = channel_new();
 	if (!channel) {
 		ERROR("Cannot get channel for communication");
@@ -255,11 +260,6 @@  static void *server_progress_thread (void *data)
 		pthread_exit((void *)SERVER_EINIT);
 	}
 
-	if (!prog->url || !strlen(prog->url)) {
-		INFO("No url for logging...no result sent");
-		pthread_exit((void *)SERVER_EINIT);
-	}
-
 	if(prog->fname)
 		read_module_settings(prog->fname, "gservice.logevent", server_logevent_settings,
 					&fmtevents);
@@ -370,6 +370,9 @@  static char *server_prepare_query(char *url, struct dict *dict)
 cleanup:
 	curl_easy_cleanup(curl);
 
+	if (!qry)
+		qry = url;
+
 	return qry;
 
 }
@@ -629,7 +632,7 @@  server_op_res_t server_start(char *fname, int argc, char *argv[])
 	}
 
 	if (mandatory_argument_count != ALL_MANDATORY_SET) {
-		fprintf(stderr, "Mandatory arguments missing!\n");
+		ERROR("Mandatory arguments missing!");
 		suricatta_print_help();
 		return SERVER_EINIT;
 	}
@@ -648,7 +651,7 @@  server_op_res_t server_start(char *fname, int argc, char *argv[])
 		return SERVER_EINIT;
 	}
 
-	progdata.fname = strdup(fname);
+	progdata.fname = (fname) ? strdup(fname) : NULL;
 	progdata.url = server_general.logurl;
 	progdata.identify = &server_general.configdata;