Calling free() for result of getenv() causes memory corruption
because getenv() returns global memory area. Fix the corruption
with copying result of getenv() because parsing it with strtok()
changes the string.
Change-Id: I21374e7d622b603de9f8d3d036561d00b1e26c23
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
int do_nfs_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *nfs_path;
- char *buf;
+ char *tmp, *buf;
char *line;
char src_path[LEN_BUF];
int size;
set_dfu_alt_info();
- buf = getenv("dfu_alt_info");
- if (!buf) {
+ tmp = getenv("dfu_alt_info");
+ if (!tmp) {
puts("No Default dfu_alt_info\n");
return CMD_RET_FAILURE;
}
+
+ buf = strdup(tmp);
+ if (!buf) {
+ puts("fail to parse dfu_alt_info\n");
+ return CMD_RET_FAILURE;
+ }
+
printf("\ndfu_alt_info = %s\n", buf);
ret = do_mmc_init(&mmc);