summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2020-01-01 12:06:37 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2020-01-01 12:06:37 +0000
commitd3eae2a68ebac3d69e049ba2fed3609433d8cb12 (patch)
tree5dedb692a6aafa2fdcac89f301d6df482195e712 /bin
parent73db93b889129cdabe8e9e65dcc1aea49cc08396 (diff)
downloadsrc-test-d3eae2a68ebac3d69e049ba2fed3609433d8cb12.tar.gz
src-test-d3eae2a68ebac3d69e049ba2fed3609433d8cb12.zip
sh: Fix rare memory leak with SIGINT
If getcwd() failed earlier on but later succeeded in the pwd builtin, there was no INTOFF protection between calling savestr() and storing its result. It is quite rare for getcwd() to fail, and rarer for it to succeed later in the same directory. Found via code inspection for changing ckmalloc() and similar to assert INTOFF protection instead of applying it directly (which protects against corrupting malloc's internal state but allows memory leaks or double frees). MFC after: 1 week
Notes
Notes: svn path=/head/; revision=356251
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/cd.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index 355e204fe1480..66eee00b2c246 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -376,8 +376,11 @@ getpwd(void)
return curdir;
p = getpwd2();
- if (p != NULL)
+ if (p != NULL) {
+ INTOFF;
curdir = savestr(p);
+ INTON;
+ }
return curdir;
}