diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2011-04-21 11:09:28 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-04-21 11:09:28 +0300 |
commit | eada0e3e47b80da2dec8c11fefb5ad16e4d6faaa (patch) | |
tree | 3b4e9e880c811b32b29f2d8c1e8fbadd1f52f4b1 /sign | |
parent | e393393ff71e5d0a6dc1c4d316558e8396caf287 (diff) | |
download | librpm-tizen-eada0e3e47b80da2dec8c11fefb5ad16e4d6faaa.tar.gz librpm-tizen-eada0e3e47b80da2dec8c11fefb5ad16e4d6faaa.tar.bz2 librpm-tizen-eada0e3e47b80da2dec8c11fefb5ad16e4d6faaa.zip |
Handle errors from moving target file into place in rpmSign()
- Signing isn't successful unless we manage to replace the original
file with the signed one, take the stat() etc returns into count.
Diffstat (limited to 'sign')
-rw-r--r-- | sign/rpmgensig.c | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/sign/rpmgensig.c b/sign/rpmgensig.c index 328521275..e858e21a5 100644 --- a/sign/rpmgensig.c +++ b/sign/rpmgensig.c @@ -435,7 +435,6 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase) Header sigh = NULL; char * msg; int res = -1; /* assume failure */ - int xx; rpmRC rc; struct rpmtd_s utd; @@ -476,7 +475,6 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase) } msg = _free(msg); - /* ASSERT: ofd == NULL && sigtarget == NULL */ ofd = rpmMkTempFile(NULL, &sigtarget); if (ofd == NULL || Ferror(ofd)) { rpmlog(RPMLOG_ERR, _("rpmMkTemp failed\n")); @@ -486,7 +484,6 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase) if (copyFile(&fd, rpm, &ofd, sigtarget)) goto exit; /* Both fd and ofd are now closed. sigtarget contains tempfile name. */ - /* ASSERT: fd == NULL && ofd == NULL */ /* Dump the immutable region (if present). */ if (headerGet(sigh, RPMTAG_HEADERSIGNATURES, &utd, HEADERGET_DEFAULT)) { @@ -569,22 +566,14 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase) } /* Append the header and archive from the temp file */ - /* ASSERT: fd == NULL && ofd != NULL */ - if (copyFile(&fd, sigtarget, &ofd, trpm)) - goto exit; - /* Both fd and ofd are now closed. */ - /* ASSERT: fd == NULL && ofd == NULL */ - - /* Move final target into place, restore file permissions. */ - { + if (copyFile(&fd, sigtarget, &ofd, trpm) == 0) { struct stat st; - xx = stat(rpm, &st); - xx = unlink(rpm); - xx = rename(trpm, rpm); - xx = chmod(rpm, st.st_mode); - } - res = 0; + /* Move final target into place, restore file permissions. */ + if (stat(rpm, &st) == 0 && unlink(rpm) == 0 && + rename(trpm, rpm) == 0 && chmod(rpm, st.st_mode) == 0) + res = 0; + } exit: if (fd) (void) closeFile(&fd); @@ -594,7 +583,7 @@ exit: /* Clean up intermediate target */ if (sigtarget) { - xx = unlink(sigtarget); + unlink(sigtarget); sigtarget = _free(sigtarget); } if (trpm) { |