diff mbox series

[v2,01/14] hash: Ensure verification hex pairs are terminated

Message ID 20210724150341.243074-2-sjg@chromium.org
State Accepted
Commit 031725f8cdf33e836d19f35d3fe82c5baa5a2976
Delegated to: Tom Rini
Headers show
Series lib: Add support for a decimal 0t prefix for numbers | expand

Commit Message

Simon Glass July 24, 2021, 3:03 p.m. UTC
This function seems to assume that the chr[] variable contains zeros at
the start, which is not always true. Use strlcpy() to be safe.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 common/hash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tom Rini Aug. 2, 2021, 5:51 p.m. UTC | #1
On Sat, Jul 24, 2021 at 09:03:28AM -0600, Simon Glass wrote:

> This function seems to assume that the chr[] variable contains zeros at
> the start, which is not always true. Use strlcpy() to be safe.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/hash.c b/common/hash.c
index 90cf46bcba5..059d381e231 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -396,7 +396,7 @@  int hash_parse_string(const char *algo_name, const char *str, uint8_t *result)
 	for (i = 0; i < algo->digest_size; i++) {
 		char chr[3];
 
-		strncpy(chr, &str[i * 2], 2);
+		strlcpy(chr, &str[i * 2], 3);
 		result[i] = simple_strtoul(chr, NULL, 16);
 	}