mirror of
https://github.com/u-boot/u-boot.git
synced 2024-11-25 21:24:21 +08:00
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: Wolfgang Denk <wd@denx.de>
This commit is contained in:
parent
739b8080af
commit
9ed4a9582f
@ -557,13 +557,19 @@ int getenv_f(char *name, char *buf, unsigned len)
|
||||
}
|
||||
if ((val=envmatch((uchar *)name, i)) < 0)
|
||||
continue;
|
||||
|
||||
/* found; copy out */
|
||||
n = 0;
|
||||
while ((len > n++) && (*buf++ = env_get_char(val++)) != '\0')
|
||||
;
|
||||
if (len == n)
|
||||
*buf = '\0';
|
||||
return (n);
|
||||
for (n=0; n<len; ++n, ++buf) {
|
||||
if ((*buf = env_get_char(val++)) == '\0')
|
||||
return n;
|
||||
}
|
||||
|
||||
if (n)
|
||||
*--buf = '\0';
|
||||
|
||||
printf("env_buf too small [%d]\n", len);
|
||||
|
||||
return n;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user