diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2011-05-27 09:02:38 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-05-27 09:06:53 +0300 |
commit | c499a0b912629eeeabc3554d3e3a95c088e96422 (patch) | |
tree | 875ead1e28da6d19ebb1d29aea56a6fce58492c3 /build | |
parent | a925a16f5b4206e8bef4b5f5e3742bf1d1f75809 (diff) | |
download | librpm-tizen-c499a0b912629eeeabc3554d3e3a95c088e96422.tar.gz librpm-tizen-c499a0b912629eeeabc3554d3e3a95c088e96422.tar.bz2 librpm-tizen-c499a0b912629eeeabc3554d3e3a95c088e96422.zip |
Handle readlink() failure in genCpioListAndHeader() correctly
- It might be a rare condition but it /can/ happen, and previously
that would cause '\0' written out of bounds (at negative array offset).
Also leave room for the terminating '\0' at the end of buffer when
calling readlink(), previously a link exactly the size of buffer
would've been silently truncated.
Diffstat (limited to 'build')
-rw-r--r-- | build/files.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/build/files.c b/build/files.c index 036644319..7d51a81b0 100644 --- a/build/files.c +++ b/build/files.c @@ -1215,11 +1215,16 @@ static void genCpioListAndHeader(FileList fl, buf[0] = '\0'; if (S_ISLNK(flp->fl_mode)) { - buf[readlink(flp->diskPath, buf, BUFSIZ)] = '\0'; - if (fl->buildRoot) { + ssize_t llen = readlink(flp->diskPath, buf, BUFSIZ-1); + if (llen == -1) { + rpmlog(RPMLOG_ERR, _("reading symlink %s failed: %s\n"), + flp->diskPath, strerror(errno)); + fl->processingFailed = 1; + } else { + buf[llen] = '\0'; if (buf[0] == '/' && !rstreq(fl->buildRoot, "/") && - rstreqn(buf, fl->buildRoot, strlen(fl->buildRoot))) { - rpmlog(RPMLOG_ERR, + rstreqn(buf, fl->buildRoot, strlen(fl->buildRoot))) { + rpmlog(RPMLOG_ERR, _("Symlink points to BuildRoot: %s -> %s\n"), flp->cpioPath, buf); fl->processingFailed = 1; |