Skip to content

Commit 804b474

Browse files
Tomas Volfcopybara-github
Tomas Volf
authored andcommitted
Replace strdupa with strdup
Strdupa has potential to be unsafe thanks to the possibly unbound stack usage. It also generates warnings when compiled on musl. This commit therefore replaces it with properly checked heap allocation using strdup. Fixes bazelbuild#15729 Closes bazelbuild#15763. PiperOrigin-RevId: 458440234 Change-Id: I8c8574f654295086f767b4fc4ca6fc1e59097beb
1 parent 98853a7 commit 804b474

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/tools/linux-sandbox-pid1.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,17 @@ static int CreateTarget(const char *path, bool is_directory) {
146146
}
147147

148148
// Create the parent directory.
149-
if (CreateTarget(dirname(strdupa(path)), true) < 0) {
150-
DIE("CreateTarget %s", dirname(strdupa(path)));
149+
{
150+
char *buf, *dir;
151+
152+
if (!(buf = strdup(path))) DIE("strdup");
153+
154+
dir = dirname(buf);
155+
if (CreateTarget(dir, true) < 0) {
156+
DIE("CreateTarget %s", dir);
157+
}
158+
159+
free(buf);
151160
}
152161

153162
if (is_directory) {

0 commit comments

Comments
 (0)