mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-26 20:56:20 +00:00
_cmd_tiny: fix possible NULL pointer dereference
Check 'url' for NULL and move free(url) out of if-else structure
This commit is contained in:
@@ -753,6 +753,10 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help)
|
|||||||
{
|
{
|
||||||
if (strlen(inp) > 6) {
|
if (strlen(inp) > 6) {
|
||||||
char *url = strndup(inp+6, 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)) {
|
if (!tinyurl_valid(url)) {
|
||||||
GString *error = g_string_new("/tiny, badly formed URL: ");
|
GString *error = g_string_new("/tiny, badly formed URL: ");
|
||||||
@@ -762,7 +766,6 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help)
|
|||||||
win_bad_show(error->str);
|
win_bad_show(error->str);
|
||||||
}
|
}
|
||||||
g_string_free(error, TRUE);
|
g_string_free(error, TRUE);
|
||||||
free(url);
|
|
||||||
} else if (win_in_chat()) {
|
} else if (win_in_chat()) {
|
||||||
char *tiny = tinyurl_get(url);
|
char *tiny = tinyurl_get(url);
|
||||||
|
|
||||||
@@ -781,12 +784,10 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help)
|
|||||||
} else {
|
} else {
|
||||||
cons_bad_show("Couldn't get tinyurl.");
|
cons_bad_show("Couldn't get tinyurl.");
|
||||||
}
|
}
|
||||||
|
|
||||||
free(url);
|
|
||||||
} else {
|
} else {
|
||||||
cons_bad_command(inp);
|
cons_bad_command(inp);
|
||||||
free(url);
|
|
||||||
}
|
}
|
||||||
|
free(url);
|
||||||
} else {
|
} else {
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user