[PATCH] samples: connector: Bound cn_test payload logging by msg length

From: Samuel Moelius

Date: Mon Jun 08 2026 - 20:16:26 EST


Connector messages carry length-delimited data in struct cn_msg::data.
The cn_test sample callback prints that data with %s whenever msg->len
is nonzero, so a userspace NETLINK_CONNECTOR sender can provide a
payload without a trailing NUL and make printk read past the validated
message payload while looking for the string terminator.

Use the existing msg->len as the printk precision. This keeps arbitrary
connector payloads accepted by the sample while limiting the log read to
the bytes that the connector core already verified are present.

Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@xxxxxxxxxxxxxxx>
---
samples/connector/cn_test.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/samples/connector/cn_test.c b/samples/connector/cn_test.c
index 73d50b4aebb6..28df8cf055ec 100644
--- a/samples/connector/cn_test.c
+++ b/samples/connector/cn_test.c
@@ -24,10 +24,10 @@ static struct timer_list cn_test_timer;

static void cn_test_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
{
- pr_info("%s: %lu: idx=%x, val=%x, seq=%u, ack=%u, len=%d: %s.\n",
- __func__, jiffies, msg->id.idx, msg->id.val,
- msg->seq, msg->ack, msg->len,
- msg->len ? (char *)msg->data : "");
+ pr_info("%s: %lu: idx=%x, val=%x, seq=%u, ack=%u, len=%d: %.*s.\n",
+ __func__, jiffies, msg->id.idx, msg->id.val,
+ msg->seq, msg->ack, msg->len,
+ msg->len, (char *)msg->data);
}

/*
--
2.43.0