Skip to content
Snippets Groups Projects
Commit 9ed4a958 authored by Wolfgang Denk's avatar Wolfgang Denk
Browse files

getenv_f(): fix handling of too short buffers


Fix error handling in getenv_f() when the user provided buffer is too
short to hold the variable name; make sure to truncate and
NUL-terminate without overwriting the buffer limits.

Signed-off-by: default avatarWolfgang Denk <wd@denx.de>
parent 739b8080
No related branches found
No related tags found
No related merge requests found
...@@ -557,13 +557,19 @@ int getenv_f(char *name, char *buf, unsigned len) ...@@ -557,13 +557,19 @@ int getenv_f(char *name, char *buf, unsigned len)
} }
if ((val=envmatch((uchar *)name, i)) < 0) if ((val=envmatch((uchar *)name, i)) < 0)
continue; continue;
/* found; copy out */ /* found; copy out */
n = 0; for (n=0; n<len; ++n, ++buf) {
while ((len > n++) && (*buf++ = env_get_char(val++)) != '\0') if ((*buf = env_get_char(val++)) == '\0')
; return n;
if (len == n) }
*buf = '\0';
return (n); if (n)
*--buf = '\0';
printf("env_buf too small [%d]\n", len);
return n;
} }
return (-1); return (-1);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment