From d6f87e7a1605f5d2086f2fcaa084b258f620f435 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Wed, 24 Oct 2012 13:43:25 +0300 Subject: [PATCH] _cmd_tiny: fix possible NULL pointer dereference Check 'url' for NULL and move free(url) out of if-else structure --- src/command.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/command.c b/src/command.c index d22458a6..b30e9cae 100644 --- a/src/command.c +++ b/src/command.c @@ -753,6 +753,10 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help) { if (strlen(inp) > 6) { char *url = strndup(inp+6, strlen(inp)-6); + if (url == NULL) { + log_error("Not enough memory."); + return FALSE; + } if (!tinyurl_valid(url)) { GString *error = g_string_new("/tiny, badly formed URL: "); @@ -762,10 +766,9 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help) win_bad_show(error->str); } g_string_free(error, TRUE); - free(url); } else if (win_in_chat()) { char *tiny = tinyurl_get(url); - + if (tiny != NULL) { char *recipient = win_get_recipient(); jabber_send(tiny, recipient); @@ -781,12 +784,10 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help) } else { cons_bad_show("Couldn't get tinyurl."); } - - free(url); } else { cons_bad_command(inp); - free(url); } + free(url); } else { cons_show("Usage: %s", help.usage);