Fix UB (dangling pointer usage)
Using dangling pointers, even if it's just to compare them with valid pointers (such as comparing them with the ones in sess_list), is UB. This fixes that.
This commit is contained in:
parent
6432694455
commit
aaa319735b
|
@ -191,7 +191,7 @@ lastact_getfirst(int (*filter) (session *sess))
|
||||||
int
|
int
|
||||||
is_session (session * sess)
|
is_session (session * sess)
|
||||||
{
|
{
|
||||||
return g_slist_find (sess_list, sess) ? 1 : 0;
|
return sess != NULL && (g_slist_find (sess_list, sess) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
session *
|
session *
|
||||||
|
|
|
@ -654,6 +654,18 @@ plugin_emit_print (session *sess, char *word[], time_t server_time)
|
||||||
HOOK_PRINT | HOOK_PRINT_ATTRS);
|
HOOK_PRINT | HOOK_PRINT_ATTRS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* used by plugin_emit_dummy_print to fix some UB */
|
||||||
|
static void
|
||||||
|
check_and_invalidate(void *plug_, void *killsess_)
|
||||||
|
{
|
||||||
|
hexchat_plugin *plug = plug_;
|
||||||
|
session *killsess = killsess_;
|
||||||
|
if (plug->context == killsess)
|
||||||
|
{
|
||||||
|
plug->context = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
plugin_emit_dummy_print (session *sess, char *name)
|
plugin_emit_dummy_print (session *sess, char *name)
|
||||||
{
|
{
|
||||||
|
@ -664,7 +676,16 @@ plugin_emit_dummy_print (session *sess, char *name)
|
||||||
for (i = 1; i < 32; i++)
|
for (i = 1; i < 32; i++)
|
||||||
word[i] = "\000";
|
word[i] = "\000";
|
||||||
|
|
||||||
return plugin_hook_run (sess, name, word, NULL, NULL, HOOK_PRINT);
|
i = plugin_hook_run (sess, name, word, NULL, NULL, HOOK_PRINT);
|
||||||
|
|
||||||
|
/* shoehorned fix for Undefined Behaviour */
|
||||||
|
/* see https://stackoverflow.com/q/52628773/3691554 */
|
||||||
|
/* this needs to be done on the hexchat side */
|
||||||
|
if (strcmp(name, "Close Context") == 0) {
|
||||||
|
g_slist_foreach(plugin_list, &check_and_invalidate, sess);
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue