aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils/src/utils.h
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2019-07-26 14:45:32 +0200
committerPetr Štetiar <ynezz@true.cz>2020-07-11 13:33:28 +0200
commit61b36ee9ba8dcf2b7a935900af603a946408c6ab (patch)
tree086c30e4951e380f9064abf9d3a90e1ee7335d5a /tools/firmware-utils/src/utils.h
parente027df97fc69dbdf0e770d5e3cf1f85228116ef9 (diff)
downloadupstream-61b36ee9ba8dcf2b7a935900af603a946408c6ab.tar.gz
upstream-61b36ee9ba8dcf2b7a935900af603a946408c6ab.tar.bz2
upstream-61b36ee9ba8dcf2b7a935900af603a946408c6ab.zip
firmware-utils: mkfwimage: fix memcpy and strncpy usage
Firmware is binary blob, so there are barely any NULL terminated strings expected, so we should probably convert all chars into u8 types, and after that it's clear, that using strcpy doesn't make sense anymore. This is rather theoretical stuff, but `uint8_t name[PART_NAME_LENGTH]` means, that you can supply PART_NAME_LENGTH sized name, not PART_NAME_LENGTH-1 name when NULL terminated. Ref: https://github.com/openwrt/openwrt/pull/2274 Fixes: 04cb651376f9 ("firmware-utils: mkfwimage: fix more errors reported by gcc-6/7/9") Signed-off-by: Petr Štetiar <ynezz@true.cz>
Diffstat (limited to 'tools/firmware-utils/src/utils.h')
-rw-r--r--tools/firmware-utils/src/utils.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/firmware-utils/src/utils.h b/tools/firmware-utils/src/utils.h
new file mode 100644
index 0000000000..11ec740069
--- /dev/null
+++ b/tools/firmware-utils/src/utils.h
@@ -0,0 +1,11 @@
+#include <stdint.h>
+#include <string.h>
+
+#pragma once
+
+#define FW_MEMCPY_STR(dst, src) \
+ do { \
+ size_t slen = strlen(src); \
+ size_t dlen = sizeof(dst); \
+ memcpy(dst, src, slen > dlen ? dlen : slen); \
+ } while (0);