stats: Avoid NULL pointer deref in allocation failure paths.

We should either handle talloc returning NULL, or we should
OSMO_ASSERT().  Doing neither of the two is a bad idea.

Change-Id: I5e8d1cc22cf597f7f50c0f92bf86cb1f1413434c
This commit is contained in:
Harald Welte 2022-05-08 10:01:52 +02:00
parent 1e1436ce75
commit e8e24c7be9
2 changed files with 9 additions and 1 deletions

View File

@ -214,7 +214,9 @@ struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_t
{
struct osmo_stats_reporter *srep;
srep = talloc_zero(osmo_stats_ctx, struct osmo_stats_reporter);
OSMO_ASSERT(srep);
if (!srep)
return NULL;
srep->type = type;
if (name)
srep->name = talloc_strdup(srep, name);
@ -486,6 +488,8 @@ int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep)
}
srep->buffer = msgb_alloc(buffer_size, "stats buffer");
if (!srep->buffer)
goto failed;
return 0;
@ -569,6 +573,8 @@ struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name)
{
struct osmo_stats_reporter *srep;
srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_LOG, name);
if (!srep)
return NULL;
srep->have_net_config = 0;

View File

@ -54,6 +54,8 @@ struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name)
{
struct osmo_stats_reporter *srep;
srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_STATSD, name);
if (!srep)
return NULL;
srep->have_net_config = 1;