From: Mathieu Desnoyers via lttng-dev <lttng-dev@lists.lttng.org>
To: jgalar@efficios.com
Cc: lttng-dev@lists.lttng.org
Subject: [lttng-dev] [PATCH lttng-tools 1/1] Fix: Handle empty string in lttng_event_field_value_string_create_with_size
Date: Tue, 27 Sep 2022 12:52:42 -0400 [thread overview]
Message-ID: <20220927165242.644594-1-mathieu.desnoyers@efficios.com> (raw)
When using the event notification capture API, empty strings are
represented by a NULL pointer with a size=0 in the msgpack object.
The NULL pointer is unexpected, which triggers an assertion in
lttng_event_field_value_string_create_with_size.
Fix this by duplicating an empty string ("") when a size=0 is
encountered. This ensures that users of the API don't end up with an
unexpected NULL pointer. Indeed, the sample program notif-app.c in the
LTTng website documentation does not expect a NULL pointer.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I7c3a839dbbeeb95a1b3bf6ddc3205a2f6b4538e3
---
src/common/event-field-value.cpp | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/common/event-field-value.cpp b/src/common/event-field-value.cpp
index 8017fd081..fa9e97018 100644
--- a/src/common/event-field-value.cpp
+++ b/src/common/event-field-value.cpp
@@ -183,8 +183,17 @@ struct lttng_event_field_value *lttng_event_field_value_string_create_with_size(
goto error;
}
- LTTNG_ASSERT(val);
- field_val->val = strndup(val, size);
+ if (size) {
+ LTTNG_ASSERT(val);
+ field_val->val = strndup(val, size);
+ } else {
+ /*
+ * User code (e.g. notif-app.c on lttng.org/docs) do not expect
+ * a NULL string pointer. Populate with an empty string when
+ * length is 0.
+ */
+ field_val->val = strdup("");
+ }
if (!field_val->val) {
goto error;
}
--
2.25.1
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
reply other threads:[~2022-09-27 16:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220927165242.644594-1-mathieu.desnoyers@efficios.com \
--to=lttng-dev@lists.lttng.org \
--cc=jgalar@efficios.com \
--cc=mathieu.desnoyers@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox