diff options
author | pstanek@opera.com <pstanek@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 15:48:52 +0000 |
---|---|---|
committer | pstanek@opera.com <pstanek@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 15:48:52 +0000 |
commit | 793f2312bc6ce5c24d9ccd63c08ab85037ccbab5 (patch) | |
tree | 635c1281be910fab1090951d4f12df98f1aa9816 /third_party/bspatch | |
parent | 9fb55e8949f6cad47428df319c19d36fbcfb5759 (diff) | |
download | chromium_src-793f2312bc6ce5c24d9ccd63c08ab85037ccbab5.zip chromium_src-793f2312bc6ce5c24d9ccd63c08ab85037ccbab5.tar.gz chromium_src-793f2312bc6ce5c24d9ccd63c08ab85037ccbab5.tar.bz2 |
Improve error handling in bspatch.
BUG=265456
TBR=brettw@chromium.org
Review URL: https://chromiumcodereview.appspot.com/21049006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/bspatch')
-rw-r--r-- | third_party/bspatch/README.chromium | 2 | ||||
-rw-r--r-- | third_party/bspatch/mbspatch.cc | 67 |
2 files changed, 49 insertions, 20 deletions
diff --git a/third_party/bspatch/README.chromium b/third_party/bspatch/README.chromium index 262281d..ad044e3 100644 --- a/third_party/bspatch/README.chromium +++ b/third_party/bspatch/README.chromium @@ -12,7 +12,7 @@ Originally obtained from Mozilla's local copy/fork of bspatch; see: The license is shared in common with bsdiff. -Local changes include CRC32 verification. +Local changes include CRC32 verification and improvements in error handling. Update(08 Sep 08): Changed ApplyBinaryPatch to accept wchar_t paths instead of char paths. diff --git a/third_party/bspatch/mbspatch.cc b/third_party/bspatch/mbspatch.cc index f67aa11..164cc3c 100644 --- a/third_party/bspatch/mbspatch.cc +++ b/third_party/bspatch/mbspatch.cc @@ -211,35 +211,64 @@ int CalculateCrc(const unsigned char *buf, int size) { int ApplyBinaryPatch(const wchar_t *old_file, const wchar_t *patch_file, const wchar_t *new_file) { - int ret = 0; + int ret = OK; + int ofd = -1; + int nfd = -1; + unsigned char *buf = NULL; + int pfd = _wopen(patch_file, O_RDONLY | _O_BINARY); if (pfd < 0) return READ_ERROR; - MBSPatchHeader header; - if (ret = MBS_ReadHeader(pfd, &header)) return ret; + do { + MBSPatchHeader header; + if ((ret = MBS_ReadHeader(pfd, &header))) + break; - int ofd = _wopen(old_file, O_RDONLY | _O_BINARY); - if (ofd < 0) return READ_ERROR; + ofd = _wopen(old_file, O_RDONLY | _O_BINARY); + if (ofd < 0) { + ret = READ_ERROR; + break; + } - struct stat os; - if (ret = fstat(ofd, &os)) return READ_ERROR; - if (os.st_size != header.slen) return UNEXPECTED_ERROR; + struct stat os; + if ((ret = fstat(ofd, &os))) { + ret = READ_ERROR; + break; + } - unsigned char *buf = (unsigned char*) malloc(header.slen); - if (!buf) return MEM_ERROR; + if (os.st_size != header.slen) { + ret = UNEXPECTED_ERROR; + break; + } - if (read(ofd, buf, header.slen) != header.slen) return READ_ERROR; - if (CalculateCrc(buf, header.slen) != header.scrc32) - return CRC_ERROR; + buf = (unsigned char*) malloc(header.slen); + if (!buf) { + ret = MEM_ERROR; + break; + } - int nfd = _wopen(new_file, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY); - if (nfd < 0) return READ_ERROR; + if (read(ofd, buf, header.slen) != header.slen) { + ret = READ_ERROR; + break; + } - MBS_ApplyPatch(&header, pfd, buf, nfd); + if (CalculateCrc(buf, header.slen) != header.scrc32) { + ret = CRC_ERROR; + break; + } + + nfd = _wopen(new_file, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY); + if (nfd < 0) { + ret = READ_ERROR; + break; + } + + MBS_ApplyPatch(&header, pfd, buf, nfd); + } while (0); free(buf); close(pfd); - close(ofd); - close(nfd); - return OK; + if (ofd >= 0) close(ofd); + if (nfd >= 0) close(nfd); + return ret; } |