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>
*/
int env_get_f(const char *name, char *buf, unsigned len)
{
- int i, nxt;
+ int i, nxt, c;
for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
int val, n;
- for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
+ for (nxt = i; (c = env_get_char(nxt)) != '\0'; ++nxt) {
+ if (c < 0)
+ return c;
if (nxt >= CONFIG_ENV_SIZE)
return -1;
}
/* found; copy out */
for (n = 0; n < len; ++n, ++buf) {
- *buf = env_get_char(val++);
+ c = env_get_char(val++);
+ if (c < 0)
+ return c;
+ *buf = c;
if (*buf == '\0')
return n;
}