[PATCH] px5g-mbedtls error check
Peter Naulls
peter at chocky.org
Mon Dec 5 11:03:48 PST 2022
In 22.03, px5-mbedtls isn't bothering to check if the output was opened:
--- a/package/utils/px5g-mbedtls/px5g-mbedtls.c
+++ b/package/utils/px5g-mbedtls/px5g-mbedtls.c
@@ -29,6 +29,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <stdbool.h>
+#include <errno.h>
#include <mbedtls/bignum.h>
#include <mbedtls/x509_crt.h>
@@ -70,6 +71,11 @@ static void write_file(const char *path, int len, bool pem)
if (path)
f = fopen(path, "w");
+ if (!f) {
+ fprintf(stderr, "Failed to open output '%s': %s\n", path,
strerror(errno));
+ exit(1);
+ }
+
fwrite(buf_start, 1, len, f);
fclose(f);
}
More information about the openwrt-devel
mailing list