Often I struggle to understand memory allocations and the "weird" things of C, so please point out to me what I'm missing here (I must be wrong, because you guys would not miss this, right?
cleared_ci = (struct osmo_mgcpc_ep_ci){ .ep = ep, .mgcp_client_fi = ci->mgcp_client_fi, .got_port_info = ci->got_port_info, .rtp_info = ci->rtp_info,
.occupied = true, /* .pending = true follows below */ .verb = verb, .notify = { .fi = notify, .success = event_success, .failure = event_failure, .data = notify_data, } }; osmo_strlcpy(cleared_ci.label, ci->label, sizeof(cleared_ci.label)); osmo_strlcpy(cleared_ci.mgcp_ci_str, ci->mgcp_ci_str, sizeof(cleared_ci.mgcp_ci_str)); *ci = cleared_ci;
LOG_CI_VERB(ci, LOGL_DEBUG, "notify=%s\n", osmo_fsm_inst_name(ci->notify.fi));
#define LOG_CI_VERB(ci, level, fmt, args...) do { \ if (ci->verb_info.addr[0]) \ LOG_CI(ci, level, "%s %s:%u: " fmt, \ osmo_mgcp_verb_name(ci->verb), ci->verb_info.addr, ci->verb_info.port, \ ## args); \ else \ LOG_CI(ci, level, "%s: " fmt, \ osmo_mgcp_verb_name(ci->verb), \ ## args); \ } while(0)
How is ci->verb_info not being using uninitialized here?
Would that explain random crashes with this code? https://osmocom.org/issues/5572
On 23/06/2022 22:13, Keith wrote:
How is ci->verb_info not being using uninitialized here?
Actually I can see that maybe that doesn't really matter at all, but 5 or 6 macros deep into the LOGGING we are at some point doing:
LOGPFSMSLSRC(fi, (fi) ? (fi)->fsm->log_subsys : DLGLOBAL, level, \ caller_file, caller_line, fmt, ## args)
Where looking at the macro chain, fi is ci->ep->fi as passed into the original LOG_CI_VERB()
and in my backtrace:
(gdb) p *ci->ep->fi->fsm Cannot access memory at address 0x3536343436313032
I should continue in the ticket...
Hi Keith,
On 6/24/22 05:13, Keith wrote:
Often I struggle to understand memory allocations and the "weird" things of C, so please point out to me what I'm missing here (I must be wrong, because you guys would not miss this, right?
cleared_ci = (struct osmo_mgcpc_ep_ci){ .ep = ep, .mgcp_client_fi = ci->mgcp_client_fi, .got_port_info = ci->got_port_info, .rtp_info = ci->rtp_info,
.occupied = true, /* .pending = true follows below */ .verb = verb, .notify = { .fi = notify, .success = event_success, .failure = event_failure, .data = notify_data, } };
ci->verb_info is being initialized to 0 in here, since the field doesn't show up. Same as if you you did "cleared_ci = (struct osmo_mgcpc_ep_ci){};" everything within the struct will be initialized as 0. Actually, not everything, only the struct fields. Padding bytes may be kept uninitialized.
Regards, Pau