about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDmitry Podgorny <pasis.ua@gmail.com>2012-10-24 13:43:25 +0300
committerDmitry Podgorny <pasis.ua@gmail.com>2012-10-24 13:43:25 +0300
commitd6f87e7a1605f5d2086f2fcaa084b258f620f435 (patch)
tree26066f8b22a5e6fe813a3f2bf888dcb42e206e33
parente49bea4d6bffd87b6631e84f03a35e47e5b35bd9 (diff)
downloadprofani-tty-d6f87e7a1605f5d2086f2fcaa084b258f620f435.tar.gz
_cmd_tiny: fix possible NULL pointer dereference
Check 'url' for NULL and move free(url) out of if-else structure
-rw-r--r--src/command.c11
1 files 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);