Skip to content

Commit

Permalink
Ensure existing path is NUL-terminated
Browse files Browse the repository at this point in the history
readlink() doesn't NUL-terminate a string, so leave room for a
NUL, and manually insert it before calling strcmp().

Signed-off-by: Jakob Kaivo <jkk@ung.org>
  • Loading branch information
jkaivo committed Apr 24, 2023
1 parent 12fc8e3 commit 26833c5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bubblewrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1477,15 +1477,18 @@ setup_newroot (bool unshare_pid,
{
if (errno == EEXIST)
{
char existing[PATH_MAX] = "";
if (readlink (dest, existing, sizeof (existing)) < 0)
char existing[PATH_MAX + 1] = "";
ssize_t elen = readlink (dest, existing, sizeof (existing) - 1);
if (elen < 0)
{
if (errno == EINVAL)
die ("Can't make symlink at %s: destination exists and is not a symlink", op->dest);
else
die_with_error ("Can't make symlink at %s: destination exists, and cannot read symlink target", op->dest);
}

existing[elen] = '\0';

if (strcmp (existing, op->source) == 0)
break;

Expand Down

0 comments on commit 26833c5

Please sign in to comment.