Fix: lttng-ctl: lttng_list_sessions: initialize out_sessions to NULL when returning 0
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 11 Jan 2022 18:59:15 +0000 (13:59 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 11 Jan 2022 19:55:44 +0000 (14:55 -0500)
commit985aea182b618c85c51651f224abedfe367c75ee
tree23f06b3a152f26ca7c26ba9bdda6c6d6e5b3e525
parent7201079fc6b433affa4e6d5f0cd3cc8a08b549ac
Fix: lttng-ctl: lttng_list_sessions: initialize out_sessions to NULL when returning 0

Observed issue
==============

Users of lttng-ctl API's lttng_list_sessions observe application crash
when freeing the *out_sessions output value when lttng_list_sessions
returns 0.

Cause
=====

The implementation does not set *out_sessions to NULL when
lttng_ctl_ask_sessiond() sets the sessions variable to NULL.
This causes the user application to attempt to free(3) an uninitialized
pointer.

Solution
========

Initialize out_sessions to NULL before invoking
lttng_ctl_ask_sessiond(), so it is initialized when lttng_list_sessions
returns 0, thus allowing *out_sessions to be subsequently freed.
A free(3) on a NULL pointer is a no-op.

Known drawbacks
===============

None.

History
=======

This was introduced by those two commits:

b178f53e90 ("Generate session name and default output on sessiond's end")
27ea4ba825 ("Fix: error when listing sessions with no session")

This is a regression present in the stable-2.11, stable-2.12,
stable-2.13, and master branches.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I34125d708a32674d79b831e5004c48321ebd711e
src/lib/lttng-ctl/lttng-ctl.cpp
This page took 0.024972 seconds and 4 git commands to generate.