Skip to content

Commit

Permalink
Fix: Handle string encoding converison fail (#996)
Browse files Browse the repository at this point in the history
Previously a failed conversion was not cought
which meant Null was supplied to kb_item_push_str
which resulted in a segfault.

kb_item_push_str will also be made more resilient
on gvm-libs side.
  • Loading branch information
ArnoStiefvater committed Dec 9, 2021
1 parent 9b1925b commit 15f04b4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion misc/plugutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ proto_post_wrapped (const char *oid, struct script_infos *desc, int port,
const char *hostname = "";
char *buffer, *data, port_s[16] = "general";
char ip_str[INET6_ADDRSTRLEN];
GError *err = NULL;
GString *action_str;
gsize length;
kb_t kb;
Expand Down Expand Up @@ -424,7 +425,15 @@ proto_post_wrapped (const char *oid, struct script_infos *desc, int port,
msg_type_to_str (msg_type), ip_str, hostname ?: " ",
port_s, proto, oid, action_str->str, uri ?: "");
/* Convert to UTF-8 before sending to Manager. */
data = g_convert (buffer, -1, "UTF-8", "ISO_8859-1", NULL, &length, NULL);
data = g_convert (buffer, -1, "UTF-8", "ISO_8859-1", NULL, &length, &err);
if (!data)
{
g_warning ("%s: Error converting to UTF-8: %s\nOriginal string: %s",
__func__, err->message, buffer);
g_free (buffer);
g_string_free (action_str, TRUE);
return;
}
kb = plug_get_results_kb (desc);
kb_item_push_str (kb, "internal/results", data);
g_free (data);
Expand Down

0 comments on commit 15f04b4

Please sign in to comment.