Hi,

While testing Christopher's DNS "thread-safe" code, I found a bug in
srv_update_status following a recent update (related to threads too).

The patch is in attachment.

Cheers
From 441b65d0d7df8f84c19663f57a4ec6a35f4e8d1e Mon Sep 17 00:00:00 2001
From: Baptiste Assmann <bed...@gmail.com>
Date: Tue, 24 Oct 2017 17:23:16 +0200
Subject: [PATCH] MINOR: server: missing chunck allocation in
 srv_update_status()

Patch 64cc49cf introduced a bug in srv_update_status(): use of an
uninitiaized chunck pointer leading to a segfault....
This patch aims at fixing this issue.
---
 src/server.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/server.c b/src/server.c
index f208124..538c9f5 100644
--- a/src/server.c
+++ b/src/server.c
@@ -4535,17 +4535,20 @@ void srv_update_status(struct server *s)
 		}
 
 		if (s->cur_state == SRV_ST_STOPPED) {	/* server was already down */
-			chunk_printf(tmptrash,
-			             "%sServer %s/%s was DOWN and now enters maintenance%s%s%s",
-			             s->flags & SRV_F_BACKUP ? "Backup " : "", s->proxy->id, s->id,
-			             *(s->adm_st_chg_cause) ? " (" : "", s->adm_st_chg_cause, *(s->adm_st_chg_cause) ? ")" : "");
-
-			srv_append_status(tmptrash, s, NULL, -1, (s->next_admin & SRV_ADMF_FMAINT));
+			tmptrash = alloc_trash_chunk();
+			if (tmptrash) {
+				chunk_printf(tmptrash,
+					     "%sServer %s/%s was DOWN and now enters maintenance%s%s%s",
+					     s->flags & SRV_F_BACKUP ? "Backup " : "", s->proxy->id, s->id,
+					     *(s->adm_st_chg_cause) ? " (" : "", s->adm_st_chg_cause, *(s->adm_st_chg_cause) ? ")" : "");
 
-			if (!(global.mode & MODE_STARTING)) {
-				Warning("%s.\n", tmptrash->str);
-				send_log(s->proxy, LOG_NOTICE, "%s.\n", tmptrash->str);
+				srv_append_status(tmptrash, s, NULL, -1, (s->next_admin & SRV_ADMF_FMAINT));
+				if (!(global.mode & MODE_STARTING)) {
+					Warning("%s.\n", tmptrash->str);
+					send_log(s->proxy, LOG_NOTICE, "%s.\n", tmptrash->str);
+				}
 			}
+
 		}
 		else {	/* server was still running */
 			check->health = 0; /* failure */
-- 
2.7.4

Reply via email to