summaryrefslogtreecommitdiffstats
path: root/common/password.c
diff options
context:
space:
mode:
authorDavid Dgien <dgienda125@gmail.com>2020-05-22 20:51:56 -0400
committerSascha Hauer <s.hauer@pengutronix.de>2020-06-03 08:24:24 +0200
commit4a35f8894492883da0eba1e41c02979e350c02fa (patch)
tree41123ded1ff2c6a6a010f4166817491b6b3965d1 /common/password.c
parentb5fae708273212bf67cda768d285a825ab3e94b7 (diff)
downloadbarebox-4a35f8894492883da0eba1e41c02979e350c02fa.tar.gz
barebox-4a35f8894492883da0eba1e41c02979e350c02fa.tar.xz
password: Fix warning with empty default password
When CONFIG_PASSWORD_DEFAULT is unset, the default_passwd buffer is set to the empty string. The read_default_passwd() function wants to read at least two characters from that buffer, causing GCC to generate an array bounds warning: barebox/common/password.c: In function 'login': barebox/common/password.c:173:5: warning: array subscript [1, 2147483647] is outside array bounds of 'const char[1]' [-Warray-bounds] In file included from barebox/common/password.c:30: include/generated/passwd.h:1:19: note: while referencing 'default_passwd' Add an ARRAY_SIZE check to default_passwd so that the loop is optimized away and the warning is no longer generated. Since the read_default_passwd() function is only called when default_passwd is not the empty string, this is not a functional change. Signed-off-by: David Dgien <dgienda125@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/password.c')
-rw-r--r--common/password.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/common/password.c b/common/password.c
index e5a333d9b1..3c08ab782e 100644
--- a/common/password.c
+++ b/common/password.c
@@ -161,6 +161,9 @@ static int read_default_passwd(unsigned char *sum, size_t length)
unsigned char *buf = (unsigned char *)default_passwd;
unsigned char c;
+ if (ARRAY_SIZE(default_passwd) == 1)
+ return -ENOSYS;
+
if (!sum || length < 1)
return -EINVAL;