Question about static analysis
Hi everyone
Can I inquire here? If it's a problem, I'll delete it.
I have question about static analysis. below code, Why use after free? I can see modem.c and ussd.c, simfs.c let me know if you have any intentions.
=====================
Use after free (USE_AFTER_FREE)pass_freed_arg: Passing freed pointer found->data as an argument to g_slist_remove
in modem.c
g_free(found->data);
modem->interface_list = g_slist_remove(modem->interface_list,found->data);
feature = get_feature(interface);
if (feature) {
found = g_slist_find_custom(modem->feature_list, feature,(GCompareFunc) strcmp);
if (found) {
g_free(found->data);
modem->feature_list =
g_slist_remove(modem->feature_list, found->data);
}
}
=====================
in ussd.c
ssc_entry_destroy(l->data);
ussd->ss_control_list = g_slist_remove(ussd->ss_control_list, l->data);
=====================
in simfs.c
sim_fs_op_free(op);
g_queue_remove(fs->op_q, op);Quoted 7 lines
Hi everyone
Can I inquire here? If it's a problem, I'll delete it.
I have question about static analysis. below code, Why use after free? I can see
modem.candussd.c,simfs.clet me know if you have any intentions.
g_slist_remove() doesn't actually access the pointer. It doesn't even assume that it's a valid pointer (it could be an int cast to a pointer, for example). There's no danger whatsoever in freeing the memory first and then passing the pointer to g_slist_remove()
Although it would probably be cleaner to use g_slist_delete_link() for the found link, instead of g_slist_remove()
Cheers,
-Slava
Quoted 30 lines
=====================
Use after free (USE_AFTER_FREE)pass_freed_arg: Passing freed pointerfound->dataas an argument tog_slist_removein
modem.cg_free(found->data); modem->interface_list = g_slist_remove(modem->interface_list,found->data); feature = get_feature(interface); if (feature) { found = g_slist_find_custom(modem->feature_list, feature,(GCompareFunc) strcmp); if (found) { g_free(found->data); modem->feature_list = g_slist_remove(modem->feature_list, found->data); } } ===================== in ussd.c ssc_entry_destroy(l->data); ussd->ss_control_list = g_slist_remove(ussd->ss_control_list, l->data); ===================== in simfs.c sim_fs_op_free(op); g_queue_remove(fs->op_q, op);_______________________________________________
ofono mailing list -- ofono(a)ofono.org
To unsubscribe send an email to ofono-leave(a)ofono.org .
Hi Slava
Thanks for the clear explanation.
I respect your opinion use g_slist_delete_link() instead of g_slist_remove().
And other way, g_slist_remove () look like free data of element. so not need g_free() before use g_slist_remove().
Thankyou.
song