Skip to content

Commit

Permalink
Replace strdupa with strdup
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Tomas Volf authored and Copybara-Service committed Jul 1, 2022
1 parent 98853a7 commit 804b474
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/tools/linux-sandbox-pid1.cc
Expand Up @@ -146,8 +146,17 @@ static int CreateTarget(const char *path, bool is_directory) {
}

// Create the parent directory.
if (CreateTarget(dirname(strdupa(path)), true) < 0) {
DIE("CreateTarget %s", dirname(strdupa(path)));
{
char *buf, *dir;

if (!(buf = strdup(path))) DIE("strdup");

dir = dirname(buf);
if (CreateTarget(dir, true) < 0) {
DIE("CreateTarget %s", dir);
}

free(buf);
}

if (is_directory) {
Expand Down

0 comments on commit 804b474

Please sign in to comment.