summaryrefslogtreecommitdiff
path: root/src/core/wee-command.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2014-02-22 20:03:34 +0100
committerSebastien Helleu <flashcode@flashtux.org>2014-02-22 20:03:34 +0100
commit88d5ff3f2075736616f098e3c414fcb57738c3d3 (patch)
tree912dc5608084cb4aa64874055854ec1f79924413 /src/core/wee-command.c
parent4d7e6c1664e42016d2f757b71f09ac0b7529ae3e (diff)
downloadweechat-88d5ff3f2075736616f098e3c414fcb57738c3d3.zip
core: fix possible zero bytes allocation in /help command
Diffstat (limited to 'src/core/wee-command.c')
-rw-r--r--src/core/wee-command.c89
1 files changed, 46 insertions, 43 deletions
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