Skip to content

Commit

Permalink
fix memory leak in expandEnvVars and memory corruption in set command
Browse files Browse the repository at this point in the history
  • Loading branch information
boeckmann committed Jul 6, 2024
1 parent f69815d commit 4259dae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int cmd_set(char *param)
error_out_of_memory();
return E_NoMem;
}
len = dos_read(0, promptBuf, promptBuffer);
len = dos_read(0, promptBuf, promptBuffer-1);
if(cbreak || len < 0) {
free(promptBuf);
return E_CBreak;
Expand Down
8 changes: 6 additions & 2 deletions shell/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,10 @@ int expandEnvVars(char *ip, char * const line)
*tp = '\0';

if((evar = getEnv(ip)) != 0) {
if(cp >= parsedMax(strlen(evar)))
if(cp >= parsedMax(strlen(evar))) {
free(evar);
return 0;
}
cp = stpcpy(cp, evar);
free(evar);
} else if(matchtok(ip, "ERRORLEVEL")) {
Expand All @@ -704,8 +706,10 @@ int expandEnvVars(char *ip, char * const line)
if(0 == (evar = cwd(0))) {
return 0;
} else {
if(cp >= parsedMax(strlen(evar)))
if(cp >= parsedMax(strlen(evar))) {
free(evar);
return 0;
}
cp = stpcpy(cp, evar);
free(evar);
}
Expand Down

0 comments on commit 4259dae

Please sign in to comment.