From: ant.v.moryakov@gmail.com
To: trix@redhat.com
Cc: linux-kernel@vger.kernel.org, Anton Moryakov <ant.v.moryakov@gmail.com>
Subject: [PATCH v2] tiny-printf: handle NULL pointer for %s format string
Date: Mon, 19 May 2025 22:25:57 +0300 [thread overview]
Message-ID: <20250519192557.1505924-1-ant.v.moryakov@gmail.com> (raw)
From: Anton Moryakov <ant.v.moryakov@gmail.com>
Avoid NULL pointer dereference in string formatting by printing "(null)"
when a NULL pointer is passed to a %s format specifier.
This change makes the behavior consistent with standard printf()
implementations and prevents potential crashes in constrained environments.
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
lib/tiny-printf.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index 2a7a4d286c0..df5f6829db5 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -307,6 +307,8 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va)
break;
case 's':
p = va_arg(va, char*);
+ if (!p)
+ p = "(null)";
break;
case '%':
out(info, '%');
--
2.34.1
reply other threads:[~2025-05-19 19:26 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=20250519192557.1505924-1-ant.v.moryakov@gmail.com \
--to=ant.v.moryakov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=trix@redhat.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
all inboxes | Powered by JetHome®