Commit 87c7fb396a59d3e2be434cc956462ba46451193b
Committed by
Tom Rini
1 parent
48f58a5973
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
cmd: nvedit: env_get_f must check for env_get_char error codes
env_get_f calls env_get_char to load single characters from the environment. However, the return value of env_get_char was not checked for errors. Now if the env driver does not support the .get_char call, env_get_f did not notice this and looped over the whole size of the environment, calling env_get_char over 8000 times with the default settings, just to return an error in the end. Fix this by checking if env_get_char returns < 0. Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Showing 1 changed file with 8 additions and 3 deletions Side-by-side Diff
cmd/nvedit.c
... | ... | @@ -650,12 +650,14 @@ |
650 | 650 | */ |
651 | 651 | int env_get_f(const char *name, char *buf, unsigned len) |
652 | 652 | { |
653 | - int i, nxt; | |
653 | + int i, nxt, c; | |
654 | 654 | |
655 | 655 | for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) { |
656 | 656 | int val, n; |
657 | 657 | |
658 | - for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) { | |
658 | + for (nxt = i; (c = env_get_char(nxt)) != '\0'; ++nxt) { | |
659 | + if (c < 0) | |
660 | + return c; | |
659 | 661 | if (nxt >= CONFIG_ENV_SIZE) |
660 | 662 | return -1; |
661 | 663 | } |
... | ... | @@ -666,7 +668,10 @@ |
666 | 668 | |
667 | 669 | /* found; copy out */ |
668 | 670 | for (n = 0; n < len; ++n, ++buf) { |
669 | - *buf = env_get_char(val++); | |
671 | + c = env_get_char(val++); | |
672 | + if (c < 0) | |
673 | + return c; | |
674 | + *buf = c; | |
670 | 675 | if (*buf == '\0') |
671 | 676 | return n; |
672 | 677 | } |