Skip to content

Commit

Permalink
Replace strdupa with strdup (bazelbuild#15787)
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

Co-authored-by: Tomas Volf <[email protected]>
  • Loading branch information
ckolli5 and Tomas Volf authored Jul 2, 2022
1 parent 240e3d1 commit e7efa1f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/tools/linux-sandbox-pid1.cc
Original file line number Diff line number Diff line change
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 e7efa1f

Please sign in to comment.