git: 511de5b1430e - main - runat.c: Add an explicit check for snprintf() failure
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 10 May 2025 14:48:35 UTC
The branch main has been updated by rmacklem:
URL: https://cgit.FreeBSD.org/src/commit/?id=511de5b1430ea974b3dc6fcb2af28d2e10b2b25e
commit 511de5b1430ea974b3dc6fcb2af28d2e10b2b25e
Author: Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2025-05-10 14:44:38 +0000
Commit: Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2025-05-10 14:46:17 +0000
runat.c: Add an explicit check for snprintf() failure
The check for "outsiz" too large was probably sufficient to
catch failures, since it was cast to an unsigned (size_t).
However, it seems appropriate to add an explicit check for
a failed case (returning -1).
Discussed with: oshogbo
Fixes: 0660de8172cd ("runat: Add a runat(1) utility similar to the Solaris one")
---
usr.bin/runat/runat.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/usr.bin/runat/runat.c b/usr.bin/runat/runat.c
index 66f4ebadd180..99437f3472f4 100644
--- a/usr.bin/runat/runat.c
+++ b/usr.bin/runat/runat.c
@@ -52,6 +52,8 @@ main(int argc, char *argv[])
pos = 0;
for (i = 1; i < argc; i++) {
outsiz = snprintf(&buf[pos], siz, "%s ", argv[i]);
+ if (outsiz <= 0)
+ errx(1, "snprintf failed: returned %d", outsiz);
if ((size_t)outsiz > siz)
errx(1, "Arguments too large");
pos += outsiz;