From 88d5ff3f2075736616f098e3c414fcb57738c3d3 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 22 Feb 2014 20:03:34 +0100 Subject: core: fix possible zero bytes allocation in /help command --- src/core/wee-command.c | 89 ++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'src/core/wee-command.c') diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 4ff3832a7..5e79e1138 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -2397,53 +2397,56 @@ COMMAND_CALLBACK(help) length += strlen (ptr_option->string_values[i]) + 5; i++; } - string = malloc (length); - if (string) + if (length > 0) { - string[0] = '\0'; - i = 0; - while (ptr_option->string_values[i]) - { - strcat (string, "\""); - strcat (string, ptr_option->string_values[i]); - strcat (string, "\""); - if (ptr_option->string_values[i + 1]) - strcat (string, ", "); - i++; - } - gui_chat_printf (NULL, " %s: %s", - _("type"), _("string")); - gui_chat_printf (NULL, " %s: %s", - _("values"), string); - if (ptr_option->default_value) - { - gui_chat_printf (NULL, " %s: \"%s\"", - _("default value"), - ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)]); - } - else + string = malloc (length); + if (string) { + string[0] = '\0'; + i = 0; + while (ptr_option->string_values[i]) + { + strcat (string, "\""); + strcat (string, ptr_option->string_values[i]); + strcat (string, "\""); + if (ptr_option->string_values[i + 1]) + strcat (string, ", "); + i++; + } gui_chat_printf (NULL, " %s: %s", - _("default value"), - _("(undefined)")); - } - if (ptr_option->value) - { - gui_chat_printf (NULL, - " %s: \"%s%s%s\"", - _("current value"), - GUI_COLOR(GUI_COLOR_CHAT_VALUE), - ptr_option->string_values[CONFIG_INTEGER(ptr_option)], - GUI_COLOR(GUI_COLOR_CHAT)); - } - else - { - gui_chat_printf (NULL, - " %s: %s", - _("current value"), - _("(undefined)")); + _("type"), _("string")); + gui_chat_printf (NULL, " %s: %s", + _("values"), string); + if (ptr_option->default_value) + { + gui_chat_printf (NULL, " %s: \"%s\"", + _("default value"), + ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)]); + } + else + { + gui_chat_printf (NULL, " %s: %s", + _("default value"), + _("(undefined)")); + } + if (ptr_option->value) + { + gui_chat_printf (NULL, + " %s: \"%s%s%s\"", + _("current value"), + GUI_COLOR(GUI_COLOR_CHAT_VALUE), + ptr_option->string_values[CONFIG_INTEGER(ptr_option)], + GUI_COLOR(GUI_COLOR_CHAT)); + } + else + { + gui_chat_printf (NULL, + " %s: %s", + _("current value"), + _("(undefined)")); + } + free (string); } - free (string); } } else -- cgit v1.2.3