Shell: fix crash when using cd - and OLDPWD is null

This commit is contained in:
Tim Morgan 2019-09-13 07:42:47 -05:00 committed by Andreas Kling
parent 3d4935a223
commit af6948afe0
Notes: sideshowbarker 2024-07-19 12:07:54 +09:00

View file

@ -85,6 +85,8 @@ static int sh_cd(int argc, char** argv)
} else {
if (strcmp(argv[1], "-") == 0) {
char* oldpwd = getenv("OLDPWD");
if (oldpwd == nullptr)
return 1;
size_t len = strlen(oldpwd);
ASSERT(len + 1 <= PATH_MAX);
memcpy(pathbuf, oldpwd, len + 1);