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: 04cb651376 ("firmware-utils: mkfwimage: fix more errors reported by gcc-6/7/9")
Signed-off-by: Petr Štetiar <ynezz@true.cz>
This commit is contained in:
Petr Štetiar
2019-07-26 14:45:32 +02:00
parent e027df97fc
commit 61b36ee9ba
3 changed files with 28 additions and 16 deletions

View File

@@ -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);