Commit graph

123 commits

Author SHA1 Message Date
Tao Bao
3b828d879b Merge "imgdiff: Fix an edge case that leads to infinite loop." 2017-01-04 21:59:26 +00:00
Tao Bao
d37ce8f082 imgdiff: Fix an edge case that leads to infinite loop.
When the input image ends with the magic value sequence of 0x1f, 0x8b,
0x0b (optionally with 0x00), the image parsing code will be stuck in an
infinite loop.

Test: recovery_component_test passes.
Change-Id: Ie3629dfdc41360387b19cc3e0359c95ae4fb998e
2016-12-28 14:29:48 -08:00
Tao Bao
c8e79340e4 applypatch: Don't expose FindMatchingPatch().
Test: make
Change-Id: Ic77c4669574b6129e06aa6051804f419bcc8196c
2016-12-28 10:11:22 -08:00
Tao Bao
97555da4a6 Add tests for imgdiff.
Factor out libimgdiff static library for testing purpose.

This CL adds the imgdiff tests on host and on target both (similar to
libimgpatch). In practice, we only need imgdiff binary on host, and
libimgpatch on target. But they should build and pass tests on both
platforms.

Test: recovery_host_test passes; recovery_component_test passes.
Change-Id: I0eafb7faf727cdf70066310e845af6ee245d4f60
2016-12-19 16:53:03 -08:00
katao
9a6f520419 Bugfix:updater always retry apply patch failed,when memcpy failed.
https://code.google.com/p/android/issues/detail?id=230602
On the second attempt, open the file with O_RDONLY,
which causing a write failure。

Change-Id: If89165b8c7619fe25722073a46b3cc7c61530a71
Signed-off-by: katao <ustckato@gmail.com>
2016-12-19 08:51:07 +00:00
Tao Bao
ef3bea15b8 Merge "bootable/recovery: cleanup compiler warnings (unused value)" 2016-12-01 17:03:13 +00:00
Tao Bao
d255b661a1 Merge "bootable/recovery: cleanup compiler warnings (potential leak of memory)" 2016-11-30 21:19:42 +00:00
Rahul Chaudhry
a793c58208 bootable/recovery: cleanup compiler warnings (unused value)
bootable/recovery/applypatch/imgdiff.cpp:322:11: warning: Value stored to 'ret' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
bootable/recovery/applypatch/imgdiff.cpp:447:11: warning: Value stored to 'ret' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
bootable/recovery/applypatch/imgdiff.cpp:553:3: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]

Bug: 26936282
Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mm
Change-Id: I3f865e3e9b9d19e5ea5e8dfd2fe2c644254ffbb5
2016-11-30 11:18:32 -08:00
Tao Bao
358c2ec1dc Remove ota_close(int) and ota_fclose(FILE*).
We should always use unique_fd or unique_file to hold the FD or FILE*
pointer when opening via ota_(f)open functions.

This CL avoids accidentally closing raw FDs or FILE* pointers that are
managed by unique_fd/unique_file.

Test: recovery_component_test passes.
Change-Id: If58eb8b5c5da507563f85efd5d56276472a1c957
2016-11-28 12:09:39 -08:00
Tao Bao
3dc14cb429 Add ota_close(unique_fd&) and ota_fclose(std::unique_ptr<FILE>&).
We were using the below sequence prior to the CL in [1].

unique_fd fd(ota_open(...));
ota_close(fd);
fd.reset(ota_open(...));

fd.reset() may unintentionally close the newly opened FD if it
has the same value as the early ota_open. The CL in [1] changed to
"ota_close(fd.release())" to avoid the issue. This CL adds a new
overloaded function ota_close(unique_fd&) to handle the release
automatically.

Similarly add ota_fclose(std::unique_ptr<FILE>&).

[1] commit 48cf770471.

Bug: 33034669
Test: recovery_component_test passes.
Change-Id: Ief91edc590e95a7426e33364b28754173efb1056
2016-11-22 16:44:41 -08:00
Tao Bao
48cf770471 applypatch: Release FD when explicitly calling close.
We use android::base::unique_fd() to avoid leaking FD. We also want to
call close (or ota_close) to explicitly check the close result. When
combining the two together, we need to release the unique_fd to avoid
closing the same FD twice.

Bug: 33034669
Test: Trigger applypatch with install-recovery.sh.
Change-Id: I1a4f5d5fba7a23ef98d8bd7b7b07e87ae6f705c5
2016-11-21 09:47:34 -08:00
Tao Bao
6e02ea92ec applypatch: Use unique_fd to avoid leaking FDs.
Add unique_fd that calls ota_close() instead of the default closer.

Test: recovery_component_test passes.
Test: Apply a package that calls apply_patch().

Change-Id: I0c19921731757934f76cf7d5215916673a8f2777
2016-11-17 12:01:44 -08:00
Tao Bao
8fce75a069 applypatch: Clean up LoadPartitionContents().
We don't need three vectors to sort the (size, SHA-1) pairs.

Test: recovery_component_test passes.
Test: Apply a package that calls apply_patch_check() to patch EMMC
      partitions.
Change-Id: I4a6620630a6711f490822cf30f1e7fe5cea6ce49
2016-11-17 00:02:52 -08:00
Rahul Chaudhry
b29f23f7e7 Use static_cast to cast pointers returned by malloc/calloc/realloc/mmap.
static_cast is preferable to reinterpret_cast when casting from void*
pointers returned by malloc/calloc/realloc/mmap calls.

Discovered while looking at compiler warnings (b/26936282).

Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mma
Change-Id: Iaffd537784aa857108f6981fdfd82d0496eb5592
Merged-In: I151642d5a60c94f312d0611576ad0143c249ba3d
2016-11-15 23:24:54 -08:00
Rahul Chaudhry
3a5177b16d bootable/recovery: cleanup compiler warnings (potential leak of memory)
bootable/recovery/applypatch/imgdiff.cpp:1065:3: warning: Potential leak of memory pointed to by 'patch_data'
bootable/recovery/applypatch/imgdiff.cpp:1065:3: warning: Potential leak of memory pointed to by 'patch_size'
bootable/recovery/applypatch/imgdiff.cpp:226:7: warning: Potential leak of memory pointed to by 'temp_entries'

Bug: 26936282
Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mm
Change-Id: I3cac945d7677d367934d5619ef7419daf6f48d6f
2016-11-15 16:18:46 -08:00
Tao Bao
36c3511952 applypatch: Add testcases for applypatch executable.
Refactor applypatch/main.cpp into libapplypatch_modes so that we can add
testcases.

Some changes to applypatch/main.cpp:
 - Replace char** argv with const char**;
 - Use android::base::Split() to split ":";
 - Use android::base::ParseUInt().

Bug: 32383590
Test: Unit tests pass, install-recovery.sh works.

Change-Id: I44e7bfa5ab717d439ea1d0ee9ddb7b2c40bb95a4
2016-11-01 14:40:14 -07:00
Tao Bao
fada91ccf2 applypatch: Switch the parameter of Value** to std::vector.
Test: Unit tests and install-recovery.sh pass on angler and dragon.

Change-Id: I328e6554edca667cf850f5584ebf1ac211e3d4d1
2016-10-28 16:46:12 -07:00
Tao Bao
edf1b15fef applypatch: Fix the bug when constructing VAL_BLOB.
When constructing std::string from C-string, the string may be truncated
at null char. Use range constructor instead.

Bug: 32380016
Test: Use applypatch to install a previously failed recovery image.
Change-Id: Id3e2afb4a810594243cd21db526933d1fea5044b
2016-10-24 16:08:28 -07:00
Tianjie Xu
7df1850d37 Merge "Fix applypatch_check failure when applying update on angler" 2016-10-19 00:29:23 +00:00
Tianjie Xu
984d7d058e Fix applypatch_check failure when applying update on angler
Applypatch_check should be skipped if no sha is specified. As the
comments said: "It's okay to specify no sha1s; the check will pass if
the LoadFileContents is successful. Useful for reading partitions,
where the filename encodes the sha1s."

Test: The update package applied on angler successfully.
Bug: 32243751
Change-Id: Ib8f3dadf19f745c2dbd350d60da46ab12d75bc87
2016-10-18 21:22:48 +00:00
Tianjie Xu
8cf5c8f60f Replace minzip with libziparchive
Clean up the duplicated codes that handle the zip files in
bootable/recovery; and rename the library of the remaining
utility functions to libotautil.

Test: Update package installed successfully on angler.
Bug: 19472796

Change-Id: Iea8962fcf3004473cb0322b6bb3a9ea3ca7f679e
2016-10-17 17:41:51 -07:00
Tianjie Xu
aced5d9e4e Change StringValue to use std::string
Changing the field of 'Value' in edify to std::string from char*.
Meanwhile cleaning up the users of 'Value' and switching them to
cpp style.

Test: compontent tests passed.
Bug: 31713288

Change-Id: Iec5a7d601b1e4ca40935bf1c70d325dafecec235
2016-10-15 01:18:23 +00:00
Tianjie Xu
7aa88748f6 Turn on -Werror for recovery
Also remove the 0xff comparison when validating the bootloader
message fields. As the fields won't be erased to 0xff after we
remove the MTD support.

Bug: 28202046
Test: The recovery folder compiles for aosp_x86-eng
Change-Id: Ibb30ea1b2b28676fb08c7e92a1e5f7b6ef3247ab
2016-09-29 19:21:24 -07:00
Tianjie Xu
61590bbf0d Merge "Switch recovery to libbase logging" 2016-09-01 23:04:37 +00:00
Tianjie Xu
7b0ad9c638 Switch recovery to libbase logging
Clean up the recovery image and switch to libbase logging.

Bug: 28191554
Change-Id: Icd999c3cc832f0639f204b5c36cea8afe303ad35
Merged-In: Icd999c3cc832f0639f204b5c36cea8afe303ad35
2016-09-01 18:33:25 +00:00
Tianjie Xu
71e182bc38 Check an edge case when read(2) returns 0
We might end up in an infinite loop if read(2) reached EOF unexpectedly.
The problematic code in uncrypt mentioned in the bug has been fixed
by switching to libbase ReadFully(). So I grepped through the recovery
code and fixed some other occurences of the issue.

Bug: 31073201
Change-Id: Ib867029158ba23363b8f85d61c25058a635c5a6b
2016-08-31 19:11:41 -07:00
Josh Gao
dc97404346 Merge "Fix references to libcrypto_utils_static."
am: b97da5e0f0

Change-Id: Ia935df84e5ea36dfc6605b41872c36db69a114a0
2016-08-08 18:33:51 +00:00
Josh Gao
073164f24b Fix references to libcrypto_utils_static.
Bug: http://b/30708454
Change-Id: I7a5048beff1d8b783a9683dcb4a79606a77f20ee
2016-08-05 18:08:03 -07:00
Elliott Hughes
274d17dc0f resolve merge conflicts of 179c0d8 to stage-aosp-master
Change-Id: Iba5aec266444cabf83f600f2bdb45a3c027e5995
2016-06-15 15:22:17 -07:00
Tao Bao
38afad46d8 resolve merge conflicts of 490fad6 to nyc-dev-plus-aosp
Change-Id: I299fe15977c1a59d0c784728872c3a7f63c95e56
2016-06-13 19:12:46 -07:00
Tao Bao
490fad6791 applypatch: Don't call inflate() when it expects zero-length output.
We may have expanded_len == 0 when calling inflate(). After switching to
using std::vector, it passes a nullptr buffer to inflate() and leads to
Z_STREAM_ERROR.

Bug: 29312140
Change-Id: Iab7c6c07a9e8488e844e7cdda76d02bd60d2ea98
2016-06-13 16:42:52 -07:00
Elliott Hughes
63a319201f Remove obsolete MTD support.
Bug: http://b/29250988
Change-Id: Ia97ba9082a165c37f74d6e1c3f71a367adc59945
2016-06-10 13:45:35 -07:00
Tao Bao
a0c4011028 Revert "Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector."
This reverts commit 50a6f8c833.

A mix of new and free leads to memory corruptions.
2016-06-01 13:15:44 -07:00
Adam Buchbinder
50a6f8c833 Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector.
This fixes the following cppcheck reports:
[imgdiff.cpp:197]: (error) Memory leak: img
[imgdiff.cpp:386]: (error) Memory leak: img
[imgdiff.cpp:656]: (error) Memory leak: data
[imgdiff.cpp:664]: (error) Memory leak: data
[imgdiff.cpp:668]: (error) Memory leak: data
[imgdiff.cpp:668]: (error) Resource leak: f
[imgdiff.cpp:820]: (error) Memory leak: bonus_data
[imgdiff.cpp:824]: (error) Memory leak: bonus_data
[imgdiff.cpp:824]: (error) Resource leak: f
[imgdiff.cpp:847]: (error) Memory leak: bonus_data
[imgdiff.cpp:851]: (error) Memory leak: bonus_data
[imgdiff.cpp:856]: (error) Memory leak: bonus_data
[imgdiff.cpp:860]: (error) Memory leak: bonus_data
[imgdiff.cpp:227]: (error) Memory leak: temp_entries

Change-Id: I06f878d0b677a25328e0deb84f65f3b7212e24b1
(cherry picked from commit 51dc9444bc)
2016-06-01 10:28:45 -07:00
Tao Bao
16e3861c84 Revert "imgdiff: Generate statically linked imgdiff."
This reverts commit b4422bd769.

Bug: 28941046
Change-Id: Ic3c7439c64b8e55832252850514f721a944993d6
2016-06-01 00:08:40 +00:00
Tao Bao
b4422bd769 imgdiff: Generate statically linked imgdiff.
Bug: 28941046
Change-Id: If3019d8cff91fd4f6fa4516bef5a0f51c2ddebc7
2016-05-30 21:53:11 -07:00
Sen Jiang
2fffcb174b applypatch: Use bsdiff from external/bsdiff.
external/bsdiff uses divsufsort which is much faster, and also include
some bug fixes.

Bug: 26982501
Test: ./imgdiff_test.sh

Change-Id: I089a301c291ee55d79938c7a3ca6d509895440d1
2016-05-03 16:39:51 -07:00
Chih-Hung Hsieh
54a2747ef3 Fix google-runtime-int warnings.
Bug: 28220065
Change-Id: Ida199c66692a1638be6990d583d2ed42583fb592
2016-04-18 12:29:30 -07:00
Jed Estep
ff6df890a2 Control fault injection with config files instead of build flags
Bug: 27724259
Change-Id: I65bdefed10b3fb85fcb9e1147eaf0687d7d438f4
2016-03-18 17:58:25 -07:00
Tao Bao
ce5868862a Revert "DO NOT MERGE Control fault injection with config files instead of build flags"
This reverts commit f73abf36bc.

Bug: 27724259
Change-Id: I1301fdad15650837d0b1febd0c3239134e2b94fb
2016-03-17 22:29:23 +00:00
Jed Estep
f73abf36bc DO NOT MERGE Control fault injection with config files instead of build flags
Bug: 26570379
Change-Id: I76109d09276d6e3ed3a32b6fedafb2582f545c0c
2016-03-16 12:36:57 -07:00
Alex Deymo
82f8c82046 Add include/ to the Makefile include path.
The applypatch heaaders were recently moved to the include/ directory.
This patch reflects that change in the Makefile.

Bug: None
TEST=sudo emerge imgdiff

Change-Id: I0bf3f991b5e0c98054033c5939ed69b3e3c827a9
2016-03-14 14:25:33 -07:00
Yabin Cui
1c522df25f applypatch: use vector to store data in FileContents.
Cherry pick this patch because it fixes the problem that
a newed Value is released by free().

Bug: 26906416
Change-Id: Ib53b445cd415a1ed5e95733fbc4073f9ef4dbc43
(cherry picked from commit d6c93afcc2)
2016-03-11 11:11:11 -08:00
Sen Jiang
5593342575 Merge "applypatch: add -fPIC for libimgpatch in Chrome OS." 2016-03-09 01:28:09 +00:00
Sen Jiang
ef2016f711 applypatch: add -fPIC for libimgpatch in Chrome OS.
To make the static library position independent.

Bug: 26866274
Test: emerge-peppy imgdiff; sudo emerge imgdiff; emerge nyan imgdiff

Change-Id: I319e721ccfb6a51f63d31afa49f54aa7f607f4bf
2016-03-08 17:02:50 -08:00
Tao Bao
d80a99883d Fix the improper use of LOCAL_WHOLE_STATIC_LIBRARIES.
If two libraries both use LOCAL_WHOLE_STATIC_LIBRARIES and include a same
library, there would be linking errors when generating a shared library
(or executable) that depends on the two libraries both.

Also clean up Android.mk files.

Remove the "LOCAL_MODULE_TAGS := eng" line for the updater module. The
module will then default to "optional" which won't be built until needed.

Change-Id: I3ec227109b8aa744b7568e7f82f575aae3fe0e6f
2016-03-03 14:52:44 -08:00
Jed Estep
39c1b5e872 Control fault injection with config files instead of build flags
Bug: 26570379
Change-Id: I76109d09276d6e3ed3a32b6fedafb2582f545c0c
(cherry picked from commit d940887dde)
2016-02-22 17:31:12 -08:00
Sen Jiang
f3e05f504d applypatch: Add libimgpatch.pc
Test: pkg-config --libs libimgpatch
Bug: 26866274
Change-Id: I79a103099d951943a88768c577224fccacbb79e3
2016-02-16 11:35:29 -08:00
Sen Jiang
fa4f1b75b6 imgdiff: don't fail if gzip is corrupted.
Treat it as a normal chunk if inflate() fails.

Test: run imgdiff on corrupted gzip and apply the patch
Bug: 27153028
Change-Id: Idcbb3c1360ec0774e6c7861b21d99af8ee10604a
2016-02-12 12:57:03 -08:00
Yabin Cui
d6c93afcc2 applypatch: use vector to store data in FileContents.
Bug: 26906416
Change-Id: Ib53b445cd415a1ed5e95733fbc4073f9ef4dbc43
2016-02-11 18:10:31 -08:00