[PATCH usign] Use static buffer for default sigfile path
Haelwenn (lanodan) Monnier
contact at hacktivis.me
Sun Oct 5 13:52:21 PDT 2025
This allows to compile usign with TinyCC on architectures like AArch64
and riscv where it is missing an implementation of alloca.
VLA could also be used as this is C99 code, but would reduce portability.
malloc could be considered but musl's malloc is over 4KB of code and
dynamic/static analyzers would require a bunch of free().
Signed-off-by: Haelwenn (lanodan) Monnier <contact at hacktivis.me>
---
main.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/main.c b/main.c
index ebfdfb0..addbfb8 100644
--- a/main.c
+++ b/main.c
@@ -26,11 +26,16 @@
#include <fcntl.h>
#include <unistd.h>
#include <inttypes.h>
+#include <limits.h>
#include "base64.h"
#include "edsign.h"
#include "ed25519.h"
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
struct pubkey {
char pkalg[2];
uint8_t fingerprint[8];
@@ -409,14 +414,19 @@ int main(int argc, char **argv)
}
if (!sigfile && msgfile) {
- char *buf = alloca(strlen(msgfile) + 5);
-
if (!strcmp(msgfile, "-")) {
fprintf(stderr, "Need signature file when reading message from stdin\n");
return 1;
}
- sprintf(buf, "%s.sig", msgfile);
+ if ((strlen(msgfile) - 4) > PATH_MAX)
+ {
+ fprintf(stderr, "Need signature file when msgfile path is over %zd (PATH_MAX - 4)\n", (size_t)PATH_MAX);
+ return 1;
+ }
+
+ static char buf[PATH_MAX];
+ snprintf(buf, PATH_MAX, "%s.sig", msgfile);
sigfile = buf;
}
base-commit: f1f65026a94137c91b5466b149ef3ea3f20091e9
--
2.49.1
More information about the openwrt-devel
mailing list