...
 
Commits (63)
    https://gitcode.net/openharmony/update_updater/-/commit/888ccf4636552d145931648f2dc0b0257d52fe4c Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-14T21:11:34+08:00 wangjiadong wangjiadong14@huawei.com fix log https://gitcode.net/openharmony/update_updater/-/commit/06f93277334d04d3f4f2aff726d08fe9a26d6907 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-15T15:55:55+08:00 wangjiadong wangjiadong14@huawei.com add ut https://gitcode.net/openharmony/update_updater/-/commit/e5b19fbd0476aadac3aca1f8b5a5f8abd741151d Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-15T16:14:45+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/f0de0290a33dba3cb113d756125fcbd85eba579e Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-15T16:44:09+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/759772868ad308257d358ae924c31f5d4b4466a4 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-15T17:05:29+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/543ec3665970aa1ca001fe5019ed2d4f649d9457 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-15T20:17:23+08:00 wangjiadong wangjiadong14@huawei.com add fuzz https://gitcode.net/openharmony/update_updater/-/commit/6685e04d441a975b490dbc3c1dc382309061dea9 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-16T16:42:54+08:00 wangjiadong wangjiadong14@huawei.com fix rk_3568_mini https://gitcode.net/openharmony/update_updater/-/commit/ed71e4101c2fe9b4b4c43845530af933a6952504 !740 修复最小系统编译错误 2023-08-16T11:51:23+00:00 openharmony_ci 120357966@qq.com Merge pull request !740 from 王佳栋/master https://gitcode.net/openharmony/update_updater/-/commit/63012ab8334666e41191cd4c3164842cd89f8dad Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-17T09:37:28+08:00 wangjiadong wangjiadong14@huawei.com fix fuzz https://gitcode.net/openharmony/update_updater/-/commit/fb944278d368d8d3d1204e7f022c49162907e3e9 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-17T10:27:15+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/cc8dcafb2379226bc9aa9752c556f918fd7adab2 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-17T10:35:51+08:00 wangjiadong wangjiadong14@huawei.com fix fuzz https://gitcode.net/openharmony/update_updater/-/commit/e4d4aec962a271c8fb0fd607a1ec0c2ab8220761 !739 增加fuzz测试用例 2023-08-17T03:29:11+00:00 openharmony_ci 120357966@qq.com Merge pull request !739 from 王佳栋/master https://gitcode.net/openharmony/update_updater/-/commit/0de27ab2cc729998976b750d2261546d3f3d1a61 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-17T16:04:47+08:00 wangjiadong wangjiadong14@huawei.com fix https://gitcode.net/openharmony/update_updater/-/commit/1360c33acba2d28cb3e17ecb4cbb8ef8f486466e Signed-off-by:hanqiaosheng <hanqiaosheng@huawei.com> 2023-08-17T21:35:35+08:00 the_big_blue_devil hanqiaosheng@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/2e59dc78778f8f9cce1ff7109c812a5684353c46 Signed-off-by:hanqiaosheng <hanqiaosheng@huawei.com> 2023-08-18T11:22:30+08:00 the_big_blue_devil hanqiaosheng@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/bb3421989a58b56cb0c6abae6abf71cc854ac6ac Signed-off-by:hanqiaosheng <hanqiaosheng@huawei.com> 2023-08-18T12:18:48+08:00 the_big_blue_devil hanqiaosheng@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/5f2f4fb20ffc96916b024b8bbc2d33e0c1bc162d add 2023-08-18T14:21:21+08:00 qy136 18772452388@163.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:18772452388@163.com" title="18772452388@163.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg2" style="text-decoration: none">N</a><a href="mailto:18772452388@163.com" title="18772452388@163.com">qy136</a> &lt;<a href="mailto:18772452388@163.com" title="18772452388@163.com">18772452388@163.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/cb46d1e8b8f712e9559ccc58de29024b783b3f31 add 2023-08-18T14:29:15+08:00 qy136 18772452388@163.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:18772452388@163.com" title="18772452388@163.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg1" style="text-decoration: none">N</a><a href="mailto:18772452388@163.com" title="18772452388@163.com">qy136</a> &lt;<a href="mailto:18772452388@163.com" title="18772452388@163.com">18772452388@163.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/537c0403176140adebfe4e1cf6734fe81393d2f5 Signed-off-by:hanqiaosheng <hanqiaosheng@huawei.com> 2023-08-18T14:35:06+08:00 the_big_blue_devil hanqiaosheng@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/6de6cea10370f7e31f57acaf77399868f31a710a Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-18T14:47:14+08:00 wangjiadong wangjiadong14@huawei.com add fuzz https://gitcode.net/openharmony/update_updater/-/commit/9da68061b602ac17f8f367fe88075b4bfeb50371 update test/fuzztest/writeupdatermsg_fuzzer/BUILD.gn. 2023-08-18T07:01:39+00:00 王佳栋 wangjiadong14@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:wangjiadong14@huawei.com" title="wangjiadong14@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:wangjiadong14@huawei.com" title="wangjiadong14@huawei.com">王佳栋</a> &lt;<a href="mailto:wangjiadong14@huawei.com" title="wangjiadong14@huawei.com">wangjiadong14@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/55ffe4c14bbc21970c283f7a768561cbdaa4c195 !741 去掉多余close 2023-08-18T07:01:57+00:00 openharmony_ci 120357966@qq.com Merge pull request !741 from 王佳栋/master https://gitcode.net/openharmony/update_updater/-/commit/64c32658e416740066d8eba06b6e78c1b351dd75 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-18T15:18:29+08:00 wangjiadong wangjiadong14@huawei.com fix format https://gitcode.net/openharmony/update_updater/-/commit/0760ce8ec19eb91cd5786ac063aef99a5aad8657 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-18T15:36:27+08:00 wangjiadong wangjiadong14@huawei.com fix fuzz https://gitcode.net/openharmony/update_updater/-/commit/4f51bae706a6c29588bcc7943b838218c2a7b64b Signed-off-by:hanqiaosheng <hanqiaosheng@huawei.com> 2023-08-18T17:29:04+08:00 the_big_blue_devil hanqiaosheng@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/6e9f78fe1af07753da028ca4fb22e9173a482917 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-19T10:43:24+08:00 wangjiadong wangjiadong14@huawei.com fix fuzz https://gitcode.net/openharmony/update_updater/-/commit/ecd9e3d50834baae1c1b6f249c62cb29cd3228b8 !745 增加fuzz测试用例 2023-08-19T03:18:22+00:00 openharmony_ci 120357966@qq.com Merge pull request !745 from 王佳栋/master https://gitcode.net/openharmony/update_updater/-/commit/e9ca542e8d75953d8a6f5707d2253b664e28a22d Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-19T11:31:12+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/afb29e8ba6b33210ee3139664322ae8f0c12ebc3 add 2023-08-19T11:43:47+08:00 qy136 18772452388@163.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:18772452388@163.com" title="18772452388@163.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg1" style="text-decoration: none">N</a><a href="mailto:18772452388@163.com" title="18772452388@163.com">qy136</a> &lt;<a href="mailto:18772452388@163.com" title="18772452388@163.com">18772452388@163.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/0c4c6e83658192911c1adc7bf042f601572ecad3 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-19T12:00:50+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/2b041e23eddfca0fcc9dff3aca9d4d5a3b94670b update test/unittest/utils/utils_unittest.cpp. 2023-08-19T08:29:47+00:00 王佳栋 wangjiadong14@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:wangjiadong14@huawei.com" title="wangjiadong14@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:wangjiadong14@huawei.com" title="wangjiadong14@huawei.com">王佳栋</a> &lt;<a href="mailto:wangjiadong14@huawei.com" title="wangjiadong14@huawei.com">wangjiadong14@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/721affd4c1eafeef21a7968f20453657413b95af !743 修改升级结果文件 2023-08-19T09:17:03+00:00 openharmony_ci 120357966@qq.com Merge pull request !743 from qy136/master https://gitcode.net/openharmony/update_updater/-/commit/8e61e3cb1324d87c46b27adaa8b7f0864b168f4a !747 增加ut测试用例 2023-08-19T09:24:59+00:00 openharmony_ci 120357966@qq.com Merge pull request !747 from 王佳栋/master https://gitcode.net/openharmony/update_updater/-/commit/1d8fd61aa583b2a8ecb835c56a76d27524cabd23 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-21T21:50:20+08:00 wangjiadong wangjiadong14@huawei.com add ut https://gitcode.net/openharmony/update_updater/-/commit/02d26d3090e63a31c5ba25f84040defb5f092696 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-22T17:05:58+08:00 wangjiadong wangjiadong14@huawei.com deleat unused ut https://gitcode.net/openharmony/update_updater/-/commit/93335973e8e66fe1a9ac46126bc5b4e9e7b3b267 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-22T17:24:44+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/c4cec64fce8da8f3aed52bebef10b17628225018 !750 删除bin_flow_update测试用例 2023-08-22T11:01:42+00:00 openharmony_ci 120357966@qq.com Merge pull request !750 from 王佳栋/master https://gitcode.net/openharmony/update_updater/-/commit/4f53eba1ff85952fd026bedea487b1aff2fda0b0 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-22T19:29:25+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/263e12a1830094b88687a708c5a0329f552796b1 Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-22T21:50:25+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/39194f8846b20bcfbb7325eac75db9cf8bffee52 !737 更换日志显示为PKG_LOGW 2023-08-23T01:43:10+00:00 openharmony_ci 120357966@qq.com Merge pull request !737 from 王佳栋/master https://gitcode.net/openharmony/update_updater/-/commit/98358003ea6ac5fe4ba05432e2d54288be1aaf03 !749 增加ut测试用例 2023-08-23T04:11:41+00:00 openharmony_ci 120357966@qq.com Merge pull request !749 from 王佳栋/master https://gitcode.net/openharmony/update_updater/-/commit/60bece1e67314a14fcfa05e44afc6c1d20765cd7 Signed-off-by:hanqiaosheng <hanqiaosheng@huawei.com> 2023-08-23T17:07:55+08:00 the_big_blue_devil hanqiaosheng@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/3c2e1919c5057d23f40fc6715bd0d61593074d5c Merge branch 'master' of gitee.com:openharmony/update_updater into master 2023-08-23T09:09:24+00:00 蓝色大魔王 hanqiaosheng@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:hanqiaosheng@huawei.com" title="hanqiaosheng@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg3" style="text-decoration: none">N</a><a href="mailto:hanqiaosheng@huawei.com" title="hanqiaosheng@huawei.com">蓝色大魔王</a> &lt;<a href="mailto:hanqiaosheng@huawei.com" title="hanqiaosheng@huawei.com">hanqiaosheng@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/6193a6da14bc00856fc6371b90b54cc1c69ddee1 回退 'Pull Request !750 : 删除bin_flow_update测试用例' 2023-08-25T02:48:26+00:00 hughes h.hu@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/f033ab72104e40b4c714b0b061819bb54dc063ba Signed-off-by: wangjiadong <wangjiadong14@huawei.com> 2023-08-25T16:58:26+08:00 wangjiadong wangjiadong14@huawei.com fix ut https://gitcode.net/openharmony/update_updater/-/commit/0399770d255ac0e97f7ca399ed797f9dfe9b8108 !752 修复utils测试用例 2023-08-25T10:57:09+00:00 openharmony_ci 120357966@qq.com Merge pull request !752 from 王佳栋/master https://gitcode.net/openharmony/update_updater/-/commit/a51ca77d167db31b656f514a6267b3402b5d0c31 !751 回退 'Pull Request !750 : 删除bin_flow_update测试用例' 2023-08-26T01:24:52+00:00 openharmony_ci 120357966@qq.com Merge pull request !751 from hughes/revert-merge-750-master https://gitcode.net/openharmony/update_updater/-/commit/db74b994a5c8605f99d2ed1040a77261e5213dc9 fix IsSpaceCapacitySufficient 2023-08-26T14:24:58+08:00 lidanyang lidanyang12@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg4" style="text-decoration: none">N</a><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang</a> &lt;<a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang12@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/f7aee0db958717eee625560291bb5adb2a859891 fix compilation error 2023-08-26T17:25:37+08:00 lidanyang lidanyang12@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang</a> &lt;<a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang12@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/a0a6db17702ebf7cf7bf6377db8303aa040b8403 !742 ux定义修改为string类型,支持注册模式 2023-08-28T02:01:08+00:00 openharmony_ci 120357966@qq.com Merge pull request !742 from 蓝色大魔王/master https://gitcode.net/openharmony/update_updater/-/commit/d15d4c095e0de588b827b4749e34a72b249bc153 Signed-off-by:high_level <352754628@qq.com> 2023-08-28T15:21:52+08:00 the_big_blue_devil hanqiaosheng@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/ef374abe70d81f95d87f8c4efa2246c8a212e123 Signed-off-by:hanqiaosheng <hanqiaosheng@huawei.com> 2023-08-28T15:58:57+08:00 the_big_blue_devil hanqiaosheng@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/344b6c3e36c40569cdee0e43c5f91d43767288ad fix drop upgrade when CalcProgress 2023-08-29T09:24:30+08:00 lidanyang lidanyang12@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg3" style="text-decoration: none">N</a><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang</a> &lt;<a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang12@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/a8603e691da6b22d1a7aa5c650007eb85cb6b675 fix codex 2023-08-29T09:51:06+08:00 lidanyang lidanyang12@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg3" style="text-decoration: none">N</a><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang</a> &lt;<a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang12@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/e3872730e8997d0be7b92aa00950b79a4a9fd2c9 update services/ptable_parse/emmc_ptable.h. 2023-08-29T02:51:21+00:00 蓝色大魔王 hanqiaosheng@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:hanqiaosheng@huawei.com" title="hanqiaosheng@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg4" style="text-decoration: none">N</a><a href="mailto:hanqiaosheng@huawei.com" title="hanqiaosheng@huawei.com">蓝色大魔王</a> &lt;<a href="mailto:hanqiaosheng@huawei.com" title="hanqiaosheng@huawei.com">hanqiaosheng@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/3b2cdbbebe71dd3a4ddd0b7a9c17f5dc42a8bc9b update services/ptable_parse/emmc_ptable.h. 2023-08-29T03:17:05+00:00 蓝色大魔王 hanqiaosheng@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:hanqiaosheng@huawei.com" title="hanqiaosheng@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg6" style="text-decoration: none">N</a><a href="mailto:hanqiaosheng@huawei.com" title="hanqiaosheng@huawei.com">蓝色大魔王</a> &lt;<a href="mailto:hanqiaosheng@huawei.com" title="hanqiaosheng@huawei.com">hanqiaosheng@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/50b96337dd7b3e78464af68f46a13cc5387ff826 !754 支持emmc分区表解析 2023-08-29T06:33:50+00:00 openharmony_ci 120357966@qq.com Merge pull request !754 from 蓝色大魔王/master https://gitcode.net/openharmony/update_updater/-/commit/1eb9c37d50be82e54715fae5fbf3280f91950514 fix install time and sdcard upgrade bug when power down upgrading 2023-08-29T21:55:22+08:00 lidanyang lidanyang12@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg5" style="text-decoration: none">N</a><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang</a> &lt;<a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang12@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/610fc52c6a886b2f64bad00c4a8d71ca250061d5 !755 修复多包+掉电场景的问题 2023-08-31T03:36:26+00:00 openharmony_ci 120357966@qq.com Merge pull request !755 from ldy/font_fix https://gitcode.net/openharmony/update_updater/-/commit/6175baade4bc76c3f0e64b1e1b2c17b4409dfd2e fix power down bug when progress 100% 2023-09-02T15:28:58+08:00 lidanyang lidanyang12@huawei.com Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com"></a><a href="javascript:void(0)" class="avatar s16 avatar-inline identicon bg4" style="text-decoration: none">N</a><a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang</a> &lt;<a href="mailto:lidanyang12@huawei.com" title="lidanyang12@huawei.com">lidanyang12@huawei.com</a>&gt;</span> https://gitcode.net/openharmony/update_updater/-/commit/4ea46cd4005272f5b27f9a52aaf7dc0528ed5896 !760 进度条100%掉电后升级失败 2023-09-02T08:35:54+00:00 openharmony_ci 120357966@qq.com Merge pull request !760 from ldy/power_down https://gitcode.net/openharmony/update_updater/-/commit/d8c12b2520459949cf85eb566cbdd714b9413230 Signed-off-by: hughes802 <h.hu@huawei.com> 2023-09-04T11:09:13+08:00 hughes802 h.hu@huawei.com https://gitcode.net/openharmony/update_updater/-/commit/6a8ad306d280d91976c42377b84021b7f329cc3e !761 修复updater部件依赖不一致问题 2023-09-04T08:00:52+00:00 openharmony_ci 120357966@qq.com Merge pull request !761 from hughes/master
......@@ -20,10 +20,15 @@ group("fuzztest") {
"test/fuzztest/UpdaterFormatPartition_fuzzer:UpdaterFormatPartitionFuzzTest",
"test/fuzztest/UpdaterMountForPath_fuzzer:UpdaterMountForPathFuzzTest",
"test/fuzztest/UpdaterStartUpdaterProc_fuzzer:UpdaterStartUpdaterProcFuzzTest",
"test/fuzztest/applypatch_fuzzer:ApplyPatchFuzzTest",
"test/fuzztest/dopartitions_fuzzer:DoPartitionsFuzzTest",
"test/fuzztest/extractandexecutescript_fuzzer:ExtractAndExecuteScriptFuzzTest",
"test/fuzztest/getupdatepackageinfo_fuzzer:GetUpdatePackageInfoFuzzTest",
"test/fuzztest/package_fuzzer:PackageFuzzTest",
"test/fuzztest/readfstabfromfile_fuzzer:ReadFstabFromFileFuzzTest",
"test/fuzztest/rebootandinstallupgradepackage_fuzzer:RebootAndInstallUpgradePackageFuzzTest",
"test/fuzztest/updaterfactoryreset_fuzzer:UpdaterFactoryResetFuzzTest",
"test/fuzztest/writeupdatermsg_fuzzer:WriteUpdaterMsgFuzzTest",
]
}
......
......@@ -50,7 +50,7 @@
"init",
"hdc",
"drivers_peripheral_input",
"drivers_peripheral_partition_slot",
"drivers_peripheral_partitionslot",
"c_utils",
"hilog",
"selinux_adapter",
......
......@@ -32,6 +32,7 @@ config("diff_config") {
"${updater_path}/services/diffpatch/bzip2",
"${updater_path}/services/diffpatch/diff",
"${updater_path}/services/diffpatch",
"${updater_path}/services/package/pkg_manager",
"//third_party/bounds_checking_function/include",
"//third_party/bzip2",
]
......@@ -48,6 +49,8 @@ ohos_static_library("libdiff") {
]
deps = [
"${updater_path}/services/log:libupdaterlog",
"${updater_path}/services/package:libupdaterpackage",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/bzip2:libbz2",
"//third_party/openssl:libcrypto_shared",
......
......@@ -24,6 +24,7 @@
#include <unistd.h>
#include <vector>
#include "openssl/sha.h"
#include "pkg_utils.h"
namespace UpdatePatch {
int32_t WriteDataToFile(const std::string &fileName, const std::vector<uint8_t> &data, size_t dataSize)
......@@ -65,11 +66,13 @@ int32_t PatchMapFile(const std::string &fileName, MemMapInfo &info)
lseek(info.fd, 0, SEEK_SET);
}
info.memory = static_cast<uint8_t*>(mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, info.fd, 0));
if (info.memory == nullptr) {
void *mappedData = mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, info.fd, 0);
if (mappedData == MAP_FAILED) {
close(info.fd);
PATCH_LOGE("Failed to memory map");
return -1;
}
info.memory = static_cast<uint8_t*>(mappedData);
info.length = static_cast<size_t>(st.st_size);
return PATCH_SUCCESS;
}
......
......@@ -32,6 +32,7 @@ config("patch_config") {
"${updater_path}/services/diffpatch/bzip2",
"${updater_path}/services/diffpatch/patch",
"${updater_path}/services/diffpatch",
"${updater_path}/services/package/pkg_manager",
"//third_party/bounds_checking_function/include",
"//third_party/bzip2",
"//third_party/zlib",
......
......@@ -227,13 +227,11 @@ int32_t UpdateApplyPatch::ApplyPatch(const std::string &patchName,
std::vector<uint8_t> empty;
MemMapInfo patchData {};
MemMapInfo oldData {};
int32_t ret = PatchMapFile(patchName, patchData);
if (ret != 0) {
if (PatchMapFile(patchName, patchData) != 0) {
PATCH_LOGE("ApplyPatch : Failed to read patch file");
return -1;
}
ret = PatchMapFile(oldName, oldData);
if (ret != 0) {
if (PatchMapFile(oldName, oldData) != 0) {
PATCH_LOGE("ApplyPatch : Failed to read old file");
return -1;
}
......@@ -246,22 +244,24 @@ int32_t UpdateApplyPatch::ApplyPatch(const std::string &patchName,
writer->Init();
// check if image patch
if (patchData.length < std::char_traits<char>::length(PKGDIFF_MAGIC)) {
PATCH_LOGE("length error");
return -1;
}
if (memcmp(patchData.memory, PKGDIFF_MAGIC, std::char_traits<char>::length(PKGDIFF_MAGIC)) == 0) {
PatchParam param {};
param.patch = patchData.memory;
param.patchSize = patchData.length;
param.oldBuff = oldData.memory;
param.oldSize = oldData.length;
ret = UpdatePatch::UpdateApplyPatch::ApplyImagePatch(param, writer.get(), empty);
if (ret != 0) {
if (UpdatePatch::UpdateApplyPatch::ApplyImagePatch(param, writer.get(), empty) != 0) {
PATCH_LOGE("Failed to apply image patch file");
return -1;
}
} else if (memcmp(patchData.memory, BSDIFF_MAGIC, std::char_traits<char>::length(BSDIFF_MAGIC)) == 0) { // bsdiff
PatchBuffer patchInfo = {patchData.memory, 0, patchData.length};
BlockBuffer oldInfo = {oldData.memory, oldData.length};
ret = ApplyBlockPatch(patchInfo, oldInfo, writer.get());
if (ret != 0) {
if (ApplyBlockPatch(patchInfo, oldInfo, writer.get()) != 0) {
PATCH_LOGE("Failed to apply block patch");
return -1;
}
......
......@@ -34,6 +34,7 @@ ohos_static_library("libBinFlowUpdate") {
"${updater_path}/services/package",
"${updater_path}/services/package/pkg_algorithm",
"${updater_path}/services/package/pkg_manager",
"${updater_path}/services/package/pkg_package",
"${updater_path}/utils/include",
]
deps = [
......
......@@ -18,6 +18,7 @@
#include <thread>
#include "applypatch/partition_record.h"
#include "log.h"
#include "pkg_manager_impl.h"
#include "pkg_package/pkg_pkgfile.h"
#include "pkg_utils.h"
#include "ring_buffer/ring_buffer.h"
......@@ -58,7 +59,12 @@ int32_t UScriptInstructionBinFlowWrite::Execute(Uscript::UScriptEnv &env, Uscrip
stashBuffer_.data.resize(STASH_BUFFER_SIZE);
stashBuffer_.buffer = stashBuffer_.data.data();
PkgManager::StreamPtr binFlowStream = nullptr;
ret = pkgManager->CreatePkgStream(binFlowStream, upgradeFileName, &ringBuffer);
const FileInfo *info = pkgManager->GetFileInfo(upgradeFileName);
if (info == nullptr) {
LOG(ERROR) << "Get file info fail " << upgradeFileName;
return PKG_INVALID_FILE;
}
ret = pkgManager->CreatePkgStream(binFlowStream, upgradeFileName, info->unpackedSize, &ringBuffer);
if (ret != USCRIPT_SUCCESS || binFlowStream == nullptr) {
LOG(ERROR) << "Error to create output stream";
return USCRIPT_INVALID_PARAM;
......
......@@ -130,7 +130,7 @@ class SkipImgProcessor : public ComponentProcessor {
public:
SkipImgProcessor(const std::string &name, const size_t len)
: ComponentProcessor(name, len) {}
~SkipImgProcessor() override {}
virtual ~SkipImgProcessor() override {}
int32_t PreProcess(Uscript::UScriptEnv &env) override;
int32_t DoProcess(Uscript::UScriptEnv &env) override;
int32_t PostProcess(Uscript::UScriptEnv &env) override;
......
......@@ -42,6 +42,10 @@ public:
{
return isRetry_;
}
virtual PostMessageFunction GetPostmsgFunc()
{
return postMessage_;
}
private:
UScriptInstructionFactoryPtr factory_ = nullptr;
PostMessageFunction postMessage_ = nullptr;
......
......@@ -101,7 +101,7 @@ public:
return 0;
}
void Stop()
virtual void Stop()
{
return;
}
......@@ -330,7 +330,8 @@ public:
* @param buffer ringbuffer
* @return creation result
*/
virtual int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName, Updater::RingBuffer *buffer) = 0;
virtual int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName,
uint64_t fileLen, Updater::RingBuffer *buffer) = 0;
/**
* Close the stream
......
......@@ -17,6 +17,7 @@
#include <string>
#include "pkg_manager.h"
#include "updater/updater.h"
namespace Uscript {
class UScriptInstructionFactory;
......@@ -46,6 +47,7 @@ public:
virtual UScriptInstructionFactoryPtr GetInstructionFactory() = 0;
virtual const std::vector<std::string> GetInstructionNames() const = 0;
virtual bool IsRetry() const = 0;
virtual Updater::PostMessageFunction GetPostmsgFunc() = 0;
private:
Hpackage::PkgManager::PkgManagerPtr pkgManager_ = nullptr;
int32_t state_ = 0;
......
......@@ -44,8 +44,8 @@ enum PackageUpdateMode {
struct UpdaterParams {
bool factoryWipeData = false;
bool userWipeData = false;
bool sdcardUpdate = false;
bool forceUpdate = false;
PackageUpdateMode updateMode = HOTA_UPDATE;
int retryCount = 0;
float initialProgress = 0; /* The upgrade starts at the progress bar location */
float currentPercentage = 0; /* The proportion of progress bars occupied by the upgrade process */
......@@ -72,6 +72,7 @@ int32_t ExtractUpdaterBinary(Hpackage::PkgManager::PkgManagerPtr manager, std::s
const std::string &updaterBinary);
int GetTmpProgressValue();
void SetTmpProgressValue(int value);
void ProgressSmoothHandler(int beginProgress, int endProgress);
......@@ -86,9 +87,9 @@ int GetUpdatePackageInfo(Hpackage::PkgManager::PkgManagerPtr pkgManager, const s
int ExecUpdate(Hpackage::PkgManager::PkgManagerPtr pkgManager, int retry, const std::string &pkgPath,
PostMessageFunction postMessage);
UpdaterStatus IsSpaceCapacitySufficient(const std::vector<std::string> &packagePath);
UpdaterStatus IsSpaceCapacitySufficient(const UpdaterParams &upParams);
std::vector<uint64_t> GetStashSizeList(const std::vector<std::string> &packagePath);
std::vector<uint64_t> GetStashSizeList(const UpdaterParams &upParams);
void HandleChildOutput(const std::string &buffer, int32_t bufferLen, bool &retryUpdate, UpdaterParams &upParams);
......
......@@ -39,6 +39,7 @@ constexpr const char *UPDATER_HDC_LOG = "/data/updater/log/flashd_hdc.log";
constexpr const char *PREFIX_UFS_NODE = "/dev/block/sd";
constexpr const char *SDCARD_PACKAGE_SUFFIX = ".zip";
constexpr const char *POWEROFF = "shutdown";
constexpr const char *BOOTDEV_TYPE = "/proc/bootdevice/type";
// update mode
constexpr const char *SDCARD_MODE = "sdcard_update";
......@@ -49,11 +50,15 @@ constexpr const char *SDCARD_CARD_PATH = "/sdcard/updater";
constexpr const char *SDCARD_CARD_PKG_PATH = "/sdcard/updater/updater.zip";
constexpr const char *DEFAULT_LOCALE = "en-US";
constexpr const char *G_WORK_PATH = "/tmp/";
constexpr const char *MMC_BLOCK_DEV_NAME = "/dev/block/mmcblk0";
constexpr const char *MMC_SIZE_FILE = "/sys/class/block/mmcblk0/size";
#else
constexpr const char *SDCARD_CARD_PATH = "/data/sdcard/updater";
constexpr const char *SDCARD_CARD_PKG_PATH = "/data/updater/updater/updater_full.zip";
constexpr const char *G_WORK_PATH = "/data/updater/src/";
constexpr const char *UT_VERSION = "OpenHarmony 3.2.9.1";
constexpr const char *MMC_BLOCK_DEV_NAME = "/data/block/mmcblk0";
constexpr const char *MMC_SIZE_FILE = "/data/class/block/mmcblk0/size";
#endif
constexpr int MAX_RETRY_COUNT = 4;
constexpr int MINIMAL_ARGC_LIMIT = 2;
......
......@@ -503,15 +503,10 @@ int32_t PkgManagerImpl::CreatePkgStream(StreamPtr &stream, const std::string &fi
return PKG_SUCCESS;
}
int32_t PkgManagerImpl::CreatePkgStream(StreamPtr &stream, const std::string &fileName, RingBuffer *buffer)
int32_t PkgManagerImpl::CreatePkgStream(StreamPtr &stream, const std::string &fileName,
uint64_t fileLen, RingBuffer *buffer)
{
const FileInfo *info = GetFileInfo(fileName);
if (info == nullptr) {
PKG_LOGE("Get file info fail %s", fileName.c_str());
return PKG_INVALID_FILE;
}
PkgStreamPtr pkgStream = new(std::nothrow) FlowDataStream(this, fileName, info->unpackedSize,
PkgStreamPtr pkgStream = new(std::nothrow) FlowDataStream(this, fileName, fileLen,
buffer, PkgStream::PkgStreamType_FlowData);
if (pkgStream == nullptr) {
PKG_LOGE("Failed to create stream");
......
......@@ -73,7 +73,8 @@ public:
int32_t CreatePkgStream(PkgStreamPtr &stream, const std::string &fileName,
PkgStream::ExtractFileProcessor processor, const void *context) override;
int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName, Updater::RingBuffer *buffer) override;
int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName,
uint64_t fileLen, Updater::RingBuffer *buffer) override;
int32_t VerifyOtaPackage(const std::string &packagePath) override;
......
......@@ -372,4 +372,12 @@ int32_t FlowDataStream::Write(const PkgBuffer &data, size_t size, size_t start)
PKG_LOGE("Write ring buffer fail");
return PKG_INVALID_STREAM;
}
void FlowDataStream::Stop()
{
PKG_LOGI("FlowDataStream stop");
if (ringBuf_ != nullptr) {
ringBuf_->Stop();
}
}
} // namespace Hpackage
......@@ -266,6 +266,8 @@ public:
return readOffset_;
}
void Stop() override;
private:
int32_t ReadFromRingBuf(uint8_t *&buff, const uint32_t needLen, uint32_t &readLen);
......
......@@ -142,7 +142,7 @@ int32_t PkgVerifyUtil::HashCheck(const PkgStreamPtr srcData, const size_t dataLe
}
if (memcmp(hash.data(), sourceDigest.data(), digestLen) != EOK) {
PKG_LOGE("Failed to memcmp data.");
PKG_LOGW("Failed to memcmp data.");
UPDATER_LAST_WORD(PKG_INVALID_DIGEST);
return PKG_INVALID_DIGEST;
}
......
......@@ -40,6 +40,7 @@ config("libptableparse_exported_headers") {
ohos_static_library("libptableparse") {
sources = [
"./emmc_ptable.cpp",
"./ptable.cpp",
"./ptable_manager.cpp",
"./ptable_process.cpp",
......
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "emmc_ptable.h"
#include <algorithm>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include "log/log.h"
#include "securec.h"
#include "updater/updater_const.h"
namespace Updater {
uint64_t EmmcPtable::GetDeviceCapacity()
{
uint64_t capacity = 0;
std::string capacityPath = std::string(MMC_SIZE_FILE);
GetCapacity(capacityPath, capacity);
return capacity;
}
void EmmcPtable::EmmcPatchGptHeader(EmmcPartitionDataInfo &ptnDataInfo, const uint32_t blockSize)
{
// mbr len + gptHeader len = 2 blockSize
if (blockSize == 0 || ptnDataInfo.writeDataLen < 2 * blockSize) {
LOG(ERROR) << "invaild argument";
return;
}
uint64_t devDensity = GetDeviceCapacity();
uint64_t devBlockSize = EMMC_BLOCK_SIZE;
uint64_t cardSizeSector = devDensity / devBlockSize;
// Patching primary header
uint8_t *primaryGptHeader = ptnDataInfo.data + blockSize;
PUT_LONG_LONG(primaryGptHeader + BACKUP_HEADER_OFFSET, (cardSizeSector - 1));
PUT_LONG_LONG(primaryGptHeader + LAST_USABLE_LBA_OFFSET, (cardSizeSector - 1));
// Find last partition
uint32_t totalPart = 0;
while (((GPT_PARTITION_SIZE - blockSize - blockSize) > totalPart * PARTITION_ENTRY_SIZE) &&
(*(primaryGptHeader + blockSize + totalPart * PARTITION_ENTRY_SIZE) != 0)) {
totalPart++;
}
if (totalPart == 0) {
LOG(ERROR) << "no partition exist";
return;
}
// Patching last partition
uint8_t *lastPartOffset = primaryGptHeader + blockSize + (totalPart - 1) * PARTITION_ENTRY_SIZE;
uint64_t lastLba = GET_LLWORD_FROM_BYTE(lastPartOffset + PARTITION_ENTRY_LAST_LBA);
uint64_t firstLba = GET_LLWORD_FROM_BYTE(lastPartOffset + FIRST_LBA_OFFSET);
// General algorithm : calculate partition size by lba
uint64_t partitionSize = (lastLba - firstLba + 1) * MIN_EMMC_WRITE_SIZE;
std::string partitionName;
uint8_t *nameOffset = lastPartOffset + GPT_PARTITION_NAME_OFFSET;
// 2 bytes for 1 charactor of partition name
ParsePartitionName(nameOffset, MAX_GPT_NAME_SIZE, partitionName, MAX_GPT_NAME_SIZE / 2);
if (partitionName == USERDATA_PARTITION || (totalPart == 1 && partitionSize == 0)) {
// patch userdata or only one partition
PUT_LONG_LONG(lastPartOffset + PARTITION_ENTRY_LAST_LBA, (cardSizeSector - 1));
LOG(INFO) << "partitionSize=" << cardSizeSector - 1 << ", partition_name:" << partitionName;
}
// Updating CRC of the Partition entry array in both headers
uint32_t partCount = GET_LWORD_FROM_BYTE(primaryGptHeader + PARTITION_COUNT_OFFSET);
uint32_t entrySize = GET_LWORD_FROM_BYTE(primaryGptHeader + PENTRY_SIZE_OFFSET);
// mbr len + gptHeader len = 2 blockSize
uint32_t crcValue = CalculateCrc32(ptnDataInfo.data + (blockSize * 2), partCount * entrySize);
PUT_LONG(primaryGptHeader + PARTITION_CRC_OFFSET, crcValue);
// Clearing CRC fields to calculate
PUT_LONG(primaryGptHeader + HEADER_CRC_OFFSET, 0);
crcValue = CalculateCrc32(primaryGptHeader, GPT_CRC_LEN);
PUT_LONG(primaryGptHeader + HEADER_CRC_OFFSET, crcValue);
return;
}
bool EmmcPtable::WritePartitionTable()
{
if (partitionInfo_.empty()) {
LOG(ERROR) << "emmcPtnDataInfo_ is empty, write failed!";
return false;
}
if (!emmcPtnDataInfo_.isGptVaild) {
LOG(WARNING) << "invaild ptable, no need to update";
return false;
}
std::string emmcNode = std::string(MMC_BLOCK_DEV_NAME);
if (!WriteBufferToPath(emmcNode, 0, emmcPtnDataInfo_.data, GPT_PARTITION_SIZE)) {
LOG(ERROR) << "write gpt fail";
return false;
}
return true;
}
// blocksize is 4096, lbaLen is 512. Because in ptable.img block is 512 while in device block is 4096
bool EmmcPtable::ParsePartitionFromBuffer(uint8_t *ptbImgBuffer, const uint32_t imgBufSize)
{
if (ptbImgBuffer == nullptr || imgBufSize < GPT_PARTITION_SIZE) {
LOG(ERROR) << "ptbImgBuffer == NULL || imgBufSize < GPT_PARTITION_SIZE";
return false;
}
return UpdateCommInitializeGptPartition(ptbImgBuffer, imgBufSize);
}
bool EmmcPtable::ParseGptHeaderByEmmc(uint8_t *gptImage, const uint32_t len)
{
GPTHeaderInfo gptHeaderInfo;
uint32_t blockSize = ptableData_.blockSize; // 4096
(void)memset_s(&gptHeaderInfo, sizeof(GPTHeaderInfo), 0, sizeof(GPTHeaderInfo));
if (!GetPartitionGptHeaderInfo(gptImage + blockSize, blockSize, gptHeaderInfo)) {
LOG(ERROR) << "GetPartitionGptHeaderInfo fail";
return false;
}
uint64_t deviceSize = GetDeviceCapacity();
uint32_t lbaNum = deviceSize / MIN_EMMC_WRITE_SIZE;
return PartitionCheckGptHeader(gptImage, len, lbaNum, blockSize, gptHeaderInfo);
}
bool EmmcPtable::EmmcReadGpt(uint8_t *ptableData)
{
uint32_t number = 0;
for (uint32_t i = 0; i < MAX_PARTITION_NUM; i++) {
uint8_t *startLbaOffset = ptableData + GPT_PARTITION_START_LBA_OFFSET;
uint8_t *endLbaOffset = ptableData + GPT_PARTITION_START_LBA_OFFSET + GPT_PARTITION_END_LBA_OFFSET;
uint8_t *typeGuidOffset = ptableData + GPT_PARTITION_TYPE_GUID_OFFSET;
uint8_t *nameOffset = ptableData + GPT_PARTITION_NAME_OFFSET;
PtnInfo newPtnInfo;
(void)memset_s(&newPtnInfo, sizeof(newPtnInfo), 0, sizeof(newPtnInfo));
ParsePartitionName(nameOffset, MAX_GPT_NAME_SIZE, newPtnInfo.dispName, GPT_DISP_NAME_LEN);
if (newPtnInfo.dispName[0] == 0) {
break;
}
uint64_t startLba = GET_LLWORD_FROM_BYTE(startLbaOffset);
uint64_t endLba = GET_LLWORD_FROM_BYTE(endLbaOffset);
if (memcpy_s(newPtnInfo.partitionTypeGuid, GPT_PARTITION_TYPE_GUID_LEN,
typeGuidOffset, GPT_PARTITION_TYPE_GUID_LEN) != EOK) {
LOG(ERROR) << "memcpy guid fail";
}
newPtnInfo.startAddr = startLba * LBA_LENGTH;
/* General algorithm : calculate partition size by lba */
newPtnInfo.partitionSize = (endLba - startLba + 1) * LBA_LENGTH;
ptableData += GPT_PARTITION_INFO_LENGTH;
partitionInfo_.push_back(newPtnInfo);
number++;
}
return number != 0;
}
bool EmmcPtable::UpdateCommInitializeGptPartition(uint8_t *gptImage, const uint32_t len)
{
if (gptImage == nullptr || len < GPT_PARTITION_SIZE) {
LOG(ERROR) << "input param invalid";
return false;
}
uint32_t imgBlockSize = ptableData_.lbaLen; // 512
uint32_t deviceBlockSize = ptableData_.blockSize; // 4096
uint8_t *gptHeaderStart = gptImage + imgBlockSize;
uint8_t *ptableData = gptImage + PROTECTIVE_MBR_SIZE + LBA_LENGTH; /* skip MBR and gpt header */
if (!CheckProtectiveMbr(gptImage, imgBlockSize) || !CheckIfValidGpt(gptHeaderStart, imgBlockSize)) {
LOG(ERROR) << "check mbr or header fail";
emmcPtnDataInfo_.isGptVaild = false;
return false;
}
// for hisi: change ptable.img(512 bytes/block) into format of device(4096 bytes/block)
if (memcpy_s(emmcPtnDataInfo_.data, GPT_PARTITION_SIZE, gptImage, imgBlockSize) != EOK) {
LOG(ERROR) << "memcpy_s mbr fail";
return false;
}
if (memcpy_s(emmcPtnDataInfo_.data + deviceBlockSize, GPT_PARTITION_SIZE - deviceBlockSize,
gptHeaderStart, imgBlockSize) != EOK) {
LOG(ERROR) << "memcpy_s gpt header fail";
return false;
}
// skip 2 lba length to set gpt entry
if (memcpy_s(emmcPtnDataInfo_.data + 2 * deviceBlockSize, GPT_PARTITION_SIZE - 2 * deviceBlockSize,
ptableData, GPT_PARTITION_SIZE - 2 * deviceBlockSize) != EOK) {
LOG(ERROR) << "memcpy_s gpt data fail";
return false;
}
emmcPtnDataInfo_.writeDataLen = len;
if (!ParseGptHeaderByEmmc(gptImage, len)) {
LOG(ERROR) << "Primary signature invalid";
return false;
}
EmmcPatchGptHeader(emmcPtnDataInfo_, deviceBlockSize);
emmcPtnDataInfo_.isGptVaild = true;
return EmmcReadGpt(ptableData);
}
bool EmmcPtable::ReadEmmcGptImageToRam()
{
std::string emmcNode = std::string(MMC_BLOCK_DEV_NAME);
int32_t imgLen = GPT_PARTITION_SIZE;
auto buf = std::make_unique<uint8_t[]>(imgLen);
uint8_t *buffer = buf.get();
uint32_t deviceBlockSize = ptableData_.blockSize; // 4096
if (buffer == nullptr) {
LOG(ERROR) << "new buffer failed!";
return false;
}
if (!MemReadWithOffset(emmcNode, 0, buffer, imgLen)) {
LOG(ERROR) << "read " << imgLen << " bytes from emmcNode " << emmcNode << " failed!";
return false;
}
uint8_t *gptHeaderStart = buffer + deviceBlockSize; // if image imgBlockSize, if device deviceBlockSize
if (!CheckProtectiveMbr(buffer, deviceBlockSize) || !CheckIfValidGpt(gptHeaderStart, deviceBlockSize)) {
LOG(ERROR) << "check mbr or header fail";
return false;
}
(void)memset_s(emmcPtnDataInfo_.data, GPT_PARTITION_SIZE, 0, GPT_PARTITION_SIZE);
if (memcpy_s(emmcPtnDataInfo_.data, GPT_PARTITION_SIZE, buffer, imgLen) != EOK) {
LOG(ERROR) << "memcpy_s GPT fail";
return false;
}
emmcPtnDataInfo_.isGptVaild = true;
uint8_t *ptableData = buffer + 2 * deviceBlockSize; /* skip MBR and gpt header */
return EmmcReadGpt(ptableData);
}
bool EmmcPtable::LoadPtableFromDevice()
{
if (!partitionInfo_.empty()) {
LOG(INFO) << "ptable is already loaded to ram";
return true;
}
if (ReadEmmcGptImageToRam()) {
LOG(INFO) << "init ptable to ram ok";
return true;
}
return false;
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef UPDATER_EMMC_PTABLE_H
#define UPDATER_EMMC_PTABLE_H
#include <iostream>
#include "ptable.h"
namespace Updater {
class EmmcPtable : public Ptable {
public:
EmmcPtable() = default;
DISALLOW_COPY_MOVE(EmmcPtable);
~EmmcPtable() override {}
uint32_t GetDeviceLunNum();
bool ParsePartitionFromBuffer(uint8_t *ptbImgBuffer, const uint32_t imgBufSize) override;
bool LoadPtableFromDevice() override;
bool WritePartitionTable() override;
private:
static constexpr uint32_t GPT_PARTITION_START_LBA_OFFSET = 32;
static constexpr uint32_t GPT_PARTITION_END_LBA_OFFSET = 8;
static constexpr uint32_t GPT_PARTITION_NAME_OFFSET = 56;
static constexpr uint32_t GPT_PARTITION_TYPE_GUID_OFFSET = 0;
static constexpr uint32_t GPT_DISP_NAME_LEN = 32;
static constexpr uint32_t GPT_PARTITION_SIZE = 128 * 1024;
static constexpr uint32_t LBA_LENGTH = 512;
static constexpr uint32_t GPT_PARTITION_INFO_LENGTH = 128;
static constexpr uint32_t PROTECTIVE_MBR_SIZE = 512;
static constexpr uint32_t MIN_EMMC_WRITE_SIZE = 4096;
static constexpr uint32_t EMMC_BLOCK_SIZE = 512;
struct EmmcPartitionDataInfo {
bool isGptVaild = false;
uint32_t writeDataLen = 0; // data len write to emmc
uint8_t data[GPT_PARTITION_SIZE] = {0}; // ptable image data
};
struct EmmcPartitionDataInfo emmcPtnDataInfo_;
bool EmmcReadGpt(uint8_t *ptableData);
bool UpdateCommInitializeGptPartition(uint8_t *gptImage, const uint32_t len);
bool ReadEmmcGptImageToRam();
uint64_t GetDeviceCapacity();
void EmmcPatchGptHeader(EmmcPartitionDataInfo &ptnDataInfo, const uint32_t blockSize);
bool ParseGptHeaderByEmmc(uint8_t *gptImage, const uint32_t len);
};
} // namespace Updater
#endif // UPDATER_EMMC_PTABLE_H
\ No newline at end of file
......@@ -367,7 +367,7 @@ bool Ptable::CheckGptHeader(uint8_t *buffer, const uint32_t bufferLen, const uin
LOG(ERROR) << "starting LBA mismatch";
return false;
}
LOG(INFO) << "ufs gpt header check ok";
LOG(INFO) << "gpt header check ok";
return true;
}
......@@ -375,7 +375,8 @@ bool Ptable::PartitionCheckGptHeader(const uint8_t *gptImage, const uint32_t len
const uint32_t blockSize, GPTHeaderInfo& gptHeaderInfo)
{
if (len < ptableData_.writeDeviceLunSize || lbaNum == 0) {
LOG(ERROR) << "len < ptableData_.writeDeviceLunSize || lbaNum == 0";
LOG(ERROR) << "len" << len << "ptableData_.writeDeviceLunSize" << ptableData_.writeDeviceLunSize
<< "lbaNum" << lbaNum;
return false;
}
......@@ -407,7 +408,7 @@ bool Ptable::PartitionCheckGptHeader(const uint8_t *gptImage, const uint32_t len
orgCrcVal << std::dec;
return false;
}
LOG(INFO) << "UfsPartitionCheckGptHeader ok";
LOG(INFO) << "PartitionCheckGptHeader ok";
return true;
}
......
......@@ -17,6 +17,7 @@
#include "log/log.h"
#include "securec.h"
#include "updater/updater_const.h"
namespace Updater {
std::string PtableManager::ptbImgTag_ = "";
......@@ -48,7 +49,20 @@ void PtableManager::SetDeviceStorageType()
bool PtableManager::IsUfsDevice()
{
return true;
std::string filePath = std::string(BOOTDEV_TYPE);
if (filePath.empty()) {
LOG(ERROR) << "filePath is empty or lunCapacity is nullptr";
return false;
}
std::ifstream fin(filePath, std::ios::in);
if (!fin.is_open()) {
LOG(ERROR) << "open " << filePath << " fail";
return false;
}
uint64_t type = 0;
fin >> type;
fin.close();
return type != 0;
}
void PtableManager::ReloadDevicePartition(Hpackage::PkgManager *pkgManager)
......@@ -63,7 +77,7 @@ void PtableManager::InitPtablePtr()
if (GetDeviceStorageType() == StorageType::STORAGE_UFS) {
pPtable_ = std::make_unique<UfsPtable>();
} else {
pPtable_ = nullptr;
pPtable_ = std::make_unique<EmmcPtable>();
}
}
}
......
......@@ -18,6 +18,7 @@
#include "package/pkg_manager.h"
#include "ufs_ptable.h"
#include "emmc_ptable.h"
namespace Updater {
class PtableManager {
......
......@@ -63,7 +63,7 @@ bool PtableProcess(UpdaterParams &upParams)
Hpackage::PkgManager::ReleasePackageInstance(pkgManager);
continue;
}
if (!upParams.sdcardUpdate) {
if (upParams.updateMode != SDCARD_UPDATE) {
if (devicePtb.ComparePartition(packagePtb, "USERDATA")) {
LOG(ERROR) << "Hota update not allow userdata partition change!";
Hpackage::PkgManager::ReleasePackageInstance(pkgManager);
......
......@@ -187,6 +187,10 @@ UScriptValuePtr ScriptInterpreter::ExecuteNativeFunc(UScriptContextPtr context,
}
if (params == nullptr) {
int32_t ret = instruction->Execute(*scriptManager_->GetScriptEnv(name), *funcContext.get());
if (ret != USCRIPT_SUCCESS) {
error->SetValue(ret);
return error;
}
retValue->AddValues(funcContext->GetOutVar());
INTERPRETER_LOGI(*this, context, "ExecuteNativeFunc::Execute %s result: %d", name.c_str(), ret);
return retValue;
......
......@@ -21,13 +21,10 @@ constexpr const char *DEFAULT_FONT_FILENAME = "HarmonyOS_Sans_SC_Regular_Small.t
constexpr const char *FB_DEV_PATH = "/dev/graphics/fb0";
constexpr const char *DRM_DEV_PATH = "/dev/dri/card0";
enum class UpdaterMode {
SDCARD = 0,
FACTORYRST,
REBOOTFACTORYRST,
OTA,
RECOVER,
MODEMAX
};
constexpr const char *UPDATREMODE_SDCARD = "sdcard";
constexpr const char *UPDATREMODE_FACTORYRST = "factoryRst";
constexpr const char *UPDATREMODE_REBOOTFACTORYRST = "rebootFactoryRst";
constexpr const char *UPDATREMODE_OTA = "ota";
constexpr const char *UPDATREMODE_RECOVER = "recover";
} // namespace Updater
#endif /* UPDATE_UI_HOS_UPDATER_H */
......@@ -21,6 +21,7 @@
#include <vector>
#include "json_visitor.h"
#include "language_ui_msg_id.h"
#include "language/language_ui.h"
#include "updater_ui_traits.h"
namespace Updater {
......
......@@ -49,45 +49,49 @@ std::ostream &operator<<(std::ostream &os, const ProgressPage &info)
return os;
}
std::unordered_map<UpdaterMode, UiStrategyCfg> UiStrategy::strategies_;
std::unordered_map<UpdaterMode, std::string> UiStrategy::modeStr_ = {
{UpdaterMode::SDCARD, "sdcard"},
{UpdaterMode::FACTORYRST, "factoryRst"},
{UpdaterMode::REBOOTFACTORYRST, "rebootFactoryRst"},
{UpdaterMode::OTA, "ota"},
{UpdaterMode::RECOVER, "recover"},
std::unordered_map<std::string, UiStrategyCfg> UiStrategy::strategies_;
std::vector<std::string> UiStrategy::modeStr_ = {
{UPDATREMODE_SDCARD},
{UPDATREMODE_FACTORYRST},
{UPDATREMODE_REBOOTFACTORYRST},
{UPDATREMODE_OTA},
{UPDATREMODE_RECOVER},
};
const std::unordered_map<UpdaterMode, UiStrategyCfg> &UiStrategy::GetStrategy()
void UiStrategy::RegisterUiMode(const std::string &mode)
{
LOG(INFO) << "RegisterUiMode " << mode;
modeStr_.emplace_back(mode);
}
const std::unordered_map<std::string, UiStrategyCfg> &UiStrategy::GetStrategy()
{
return strategies_;
}
bool UiStrategy::LoadStrategy(const JsonNode &node, UpdaterMode mode)
bool UiStrategy::LoadStrategy(const JsonNode &node, const std::string &mode)
{
auto it = modeStr_.find(mode);
auto it = std::find(modeStr_.begin(), modeStr_.end(), mode);
if (it == modeStr_.end()) {
return false;
}
const JsonNode &defaultNode = node[Traits<UiStrategyCfg>::STRUCT_KEY][DEFAULT_KEY];
const JsonNode &specificNode = node[Traits<UiStrategyCfg>::STRUCT_KEY][it->second];
const JsonNode &specificNode = node[Traits<UiStrategyCfg>::STRUCT_KEY][*it];
if (!Visit<SETVAL>(specificNode, defaultNode, strategies_[mode])) {
LOG(ERROR) << "parse strategy config error";
return false;
}
LOG(DEBUG) << "mode " << modeStr_[mode] << ":\n" << strategies_[mode];
LOG(DEBUG) << "mode " << mode << "\n" << strategies_[mode];
return true;
}
bool UiStrategy::LoadStrategy(const JsonNode &node)
{
std::unordered_map<UpdaterMode, UiStrategyCfg>().swap(strategies_);
constexpr std::array strategies {UpdaterMode::OTA, UpdaterMode::FACTORYRST,
UpdaterMode::SDCARD, UpdaterMode::REBOOTFACTORYRST, UpdaterMode::RECOVER};
for (auto mode : strategies) {
std::unordered_map<std::string, UiStrategyCfg>().swap(strategies_);
for (auto mode : modeStr_) {
if (!LoadStrategy(node, mode)) {
LOG(ERROR) << "load strategy " << modeStr_[mode] << " failed";
std::unordered_map<UpdaterMode, UiStrategyCfg>().swap(strategies_);
LOG(ERROR) << "load strategy " << mode << " failed";
std::unordered_map<std::string, UiStrategyCfg>().swap(strategies_);
return false;
}
}
......
......@@ -29,13 +29,14 @@ std::ostream &operator<<(std::ostream &os, const ProgressPage &info);
class UiStrategy {
public:
static const std::unordered_map<UpdaterMode, UiStrategyCfg> &GetStrategy();
static const std::unordered_map<std::string, UiStrategyCfg> &GetStrategy();
static bool LoadStrategy(const JsonNode &node);
static void RegisterUiMode(const std::string &mode);
private:
static bool LoadStrategy(const JsonNode &node, UpdaterMode mode);
static bool LoadStrategy(const JsonNode &node, const std::string &mode);
static constexpr auto DEFAULT_KEY = "default";
static std::unordered_map<UpdaterMode, UiStrategyCfg> strategies_;
static std::unordered_map<UpdaterMode, std::string> modeStr_;
static std::unordered_map<std::string, UiStrategyCfg> strategies_;
static std::vector<std::string> modeStr_;
};
} // namespace Updater
#endif
......@@ -136,7 +136,7 @@ bool UpdaterUiConfig::Init(const JsonNode &node)
return res;
}
const std::unordered_map<UpdaterMode, UiStrategyCfg> &UpdaterUiConfig::GetStrategy()
const std::unordered_map<std::string, UiStrategyCfg> &UpdaterUiConfig::GetStrategy()
{
return UiStrategy::GetStrategy();
}
......
......@@ -26,7 +26,7 @@ namespace Updater {
class UpdaterUiConfig {
public:
static bool Init();
static const std::unordered_map<UpdaterMode, UiStrategyCfg> &GetStrategy();
static const std::unordered_map<std::string, UiStrategyCfg> &GetStrategy();
static bool GetFocusCfg();
private:
static bool Init(const JsonNode &node);
......
......@@ -29,13 +29,13 @@ public:
return instance;
}
void InitEnv() const {}
[[nodiscard]] bool SetMode(UpdaterMode mode)
[[nodiscard]] bool SetMode(std::string mode)
{
return true;
}
UpdaterMode GetMode() const
std::string GetMode() const
{
return UpdaterMode::MODEMAX;
return "";
}
void ShowLog(const std::string &tag, bool isClear = false) const {}
void ShowLogRes(const std::string &tag, bool isClear = false) const {}
......
......@@ -23,7 +23,7 @@
namespace Updater {
UpdaterUiFacade::UpdaterUiFacade()
: strategies_ {UpdaterUiConfig::GetStrategy()}, pgMgr_ {PageManager::GetInstance()}, mode_ {UpdaterMode::MODEMAX}
: strategies_ {UpdaterUiConfig::GetStrategy()}, pgMgr_ {PageManager::GetInstance()}, mode_ {""}
{
}
......@@ -40,12 +40,8 @@ void UpdaterUiFacade::InitEnv() const
UpdaterEvent::Subscribe(UPDATER_POWER_VOLUME_DOWN_EVENT, OnKeyDownEvent);
}
[[nodiscard]] bool UpdaterUiFacade::SetMode(UpdaterMode mode)
[[nodiscard]] bool UpdaterUiFacade::SetMode(std::string mode)
{
if (mode < UpdaterMode::SDCARD || mode >= UpdaterMode::MODEMAX) {
LOG(ERROR) << "updater mode invalid";
return false;
}
if (mode == mode_) {
return true;
}
......@@ -54,20 +50,16 @@ void UpdaterUiFacade::InitEnv() const
return true;
}
UpdaterMode UpdaterUiFacade::GetMode() const
std::string UpdaterUiFacade::GetMode() const
{
return mode_;
}
std::pair<bool, UpdaterUiFacade::StrategyMap::const_iterator> UpdaterUiFacade::CheckMode() const
{
if (mode_ < UpdaterMode::SDCARD || mode_ >= UpdaterMode::MODEMAX) {
LOG(ERROR) << "mode invalid";
return {false, strategies_.cend()};
}
auto it = strategies_.find(mode_);
if (it == strategies_.end()) {
LOG(ERROR) << "mode has not a strategy for it";
LOG(ERROR) << "mode has not a strategy for it " << mode_;
return {false, strategies_.cend()};
}
return {true, it};
......
......@@ -23,7 +23,7 @@
namespace Updater {
class UpdaterUiFacade {
DISALLOW_COPY_MOVE(UpdaterUiFacade);
using StrategyMap = std::unordered_map<UpdaterMode, UiStrategyCfg>;
using StrategyMap = std::unordered_map<std::string, UiStrategyCfg>;
public:
UpdaterUiFacade();
~UpdaterUiFacade() = default;
......@@ -31,8 +31,8 @@ public:
void InitEnv() const;
[[nodiscard]] bool SetMode(UpdaterMode mode);
UpdaterMode GetMode() const;
[[nodiscard]] bool SetMode(std::string mode);
std::string GetMode() const;
void ShowLog(const std::string &tag, bool isClear = false) const;
void ShowLogRes(const std::string &tag, bool isClear = false) const;
......@@ -61,9 +61,9 @@ private:
void SetLogoProgress();
const StrategyMap &strategies_;
PageManager &pgMgr_;
UpdaterMode mode_;
std::unordered_map<UpdaterMode, std::unique_ptr<ProgressStrategy>> progressMap_ {};
std::unordered_map<UpdaterMode, std::unique_ptr<LogoStrategy>> logoMap_ {};
std::string mode_;
std::unordered_map<std::string, std::unique_ptr<ProgressStrategy>> progressMap_ {};
std::unordered_map<std::string, std::unique_ptr<LogoStrategy>> logoMap_ {};
};
void OnKeyUpEvent();
void OnKeyDownEvent();
......
......@@ -100,10 +100,10 @@ int GetUpdatePackageInfo(PkgManager::PkgManagerPtr pkgManager, const std::string
return PKG_SUCCESS;
}
UpdaterStatus IsSpaceCapacitySufficient(const std::vector<std::string> &packagePath)
UpdaterStatus IsSpaceCapacitySufficient(const UpdaterParams &upParams)
{
UPDATER_INIT_RECORD;
std::vector<uint64_t> stashSizeList = GetStashSizeList(packagePath);
std::vector<uint64_t> stashSizeList = GetStashSizeList(upParams);
if (stashSizeList.size() == 0) {
LOG(ERROR) << "get stash size error";
UPDATER_LAST_WORD(UPDATE_ERROR);
......@@ -111,7 +111,7 @@ UpdaterStatus IsSpaceCapacitySufficient(const std::vector<std::string> &packageP
}
uint64_t maxStashSize = *max_element(stashSizeList.begin(), stashSizeList.end());
LOG(INFO) << "get max stash size:" << maxStashSize;
uint64_t maxLogSpace = MAX_LOG_SPACE * packagePath.size();
uint64_t maxLogSpace = MAX_LOG_SPACE * upParams.updatePackage.size();
uint64_t totalPkgSize = maxStashSize + maxLogSpace;
if (CheckStatvfs(totalPkgSize) != UPDATE_SUCCESS) {
......@@ -122,11 +122,11 @@ UpdaterStatus IsSpaceCapacitySufficient(const std::vector<std::string> &packageP
return UPDATE_SUCCESS;
}
std::vector<uint64_t> GetStashSizeList(const std::vector<std::string> &packagePath)
std::vector<uint64_t> GetStashSizeList(const UpdaterParams &upParams)
{
const std::string maxStashFileName = "all_max_stash";
std::vector<uint64_t> stashSizeList;
for (auto path : packagePath) {
for (unsigned int i = upParams.pkgLocation; i < upParams.updatePackage.size(); i++) {
PkgManager::PkgManagerPtr pkgManager = Hpackage::PkgManager::CreatePackageInstance();
if (pkgManager == nullptr) {
LOG(ERROR) << "pkgManager is nullptr";
......@@ -135,9 +135,9 @@ std::vector<uint64_t> GetStashSizeList(const std::vector<std::string> &packagePa
}
std::vector<std::string> fileIds;
int ret = pkgManager->LoadPackageWithoutUnPack(path, fileIds);
int ret = pkgManager->LoadPackageWithoutUnPack(upParams.updatePackage[i], fileIds);
if (ret != PKG_SUCCESS) {
LOG(ERROR) << "LoadPackageWithoutUnPack failed " << path;
LOG(ERROR) << "LoadPackageWithoutUnPack failed " << upParams.updatePackage[i];
PkgManager::ReleasePackageInstance(pkgManager);
UPDATER_LAST_WORD(UPDATE_CORRUPT);
return std::vector<uint64_t> {};
......@@ -145,7 +145,7 @@ std::vector<uint64_t> GetStashSizeList(const std::vector<std::string> &packagePa
const FileInfo *info = pkgManager->GetFileInfo(maxStashFileName);
if (info == nullptr) {
LOG(INFO) << "all_max_stash not exist " << path;
LOG(INFO) << "all_max_stash not exist " << upParams.updatePackage[i];
stashSizeList.push_back(0);
PkgManager::ReleasePackageInstance(pkgManager);
continue;
......@@ -155,7 +155,7 @@ std::vector<uint64_t> GetStashSizeList(const std::vector<std::string> &packagePa
ret = pkgManager->CreatePkgStream(outStream, maxStashFileName, info->unpackedSize,
PkgStream::PkgStreamType_MemoryMap);
if (outStream == nullptr || ret != PKG_SUCCESS) {
LOG(ERROR) << "Create stream fail " << maxStashFileName << " in " << path;
LOG(ERROR) << "Create stream fail " << maxStashFileName << " in " << upParams.updatePackage[i];
PkgManager::ReleasePackageInstance(pkgManager);
UPDATER_LAST_WORD(UPDATE_CORRUPT);
return std::vector<uint64_t> {};
......@@ -163,7 +163,7 @@ std::vector<uint64_t> GetStashSizeList(const std::vector<std::string> &packagePa
ret = pkgManager->ExtractFile(maxStashFileName, outStream);
if (ret != PKG_SUCCESS) {
LOG(ERROR) << "ExtractFile fail " << maxStashFileName << " in " << path;
LOG(ERROR) << "ExtractFile fail " << maxStashFileName << " in " << upParams.updatePackage[i];
PkgManager::ReleasePackageInstance(pkgManager);
UPDATER_LAST_WORD(UPDATE_CORRUPT);
return std::vector<uint64_t> {};
......@@ -171,8 +171,8 @@ std::vector<uint64_t> GetStashSizeList(const std::vector<std::string> &packagePa
PkgBuffer data {};
outStream->GetBuffer(data);
std::string str(reinterpret_cast<char*>(data.buffer), data.length);
int64_t max_stash_size = std::stoll(str);
stashSizeList.push_back(static_cast<uint64_t>(max_stash_size));
int64_t maxStashSize = std::stoll(str);
stashSizeList.push_back(static_cast<uint64_t>(maxStashSize));
PkgManager::ReleasePackageInstance(pkgManager);
}
return stashSizeList;
......@@ -210,6 +210,11 @@ int GetTmpProgressValue()
return g_tmpProgressValue;
}
void SetTmpProgressValue(int value)
{
g_tmpProgressValue = value;
}
void ProgressSmoothHandler(int beginProgress, int endProgress)
{
if (endProgress < 0 || endProgress > FULL_PERCENT_PROGRESS || beginProgress < 0) {
......
......@@ -155,6 +155,7 @@ static UpdaterStatus VerifyPackages(UpdaterParams &upParams)
return UPDATE_CORRUPT;
}
upParams.callbackProgress(0.0);
upParams.installTime.resize(upParams.updatePackage.size(), std::chrono::duration<double>(0));
for (unsigned int i = upParams.pkgLocation; i < upParams.updatePackage.size(); i++) {
LOG(INFO) << "Verify package:" << upParams.updatePackage[i];
auto startTime = std::chrono::system_clock::now();
......@@ -166,12 +167,12 @@ static UpdaterStatus VerifyPackages(UpdaterParams &upParams)
upParams.pkgLocation = i;
UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_VERIFYPKGFAIL), true);
auto endTime = std::chrono::system_clock::now();
upParams.installTime.push_back(endTime - startTime);
upParams.installTime[i] = endTime - startTime;
UPDATER_LAST_WORD(UPDATE_CORRUPT);
return UPDATE_CORRUPT;
}
auto endTime = std::chrono::system_clock::now();
upParams.installTime.push_back(endTime - startTime);
upParams.installTime[i] = endTime - startTime;
}
ProgressSmoothHandler(0, static_cast<int>(VERIFY_PERCENT * FULL_PERCENT_PROGRESS));
......@@ -236,7 +237,7 @@ bool IsBatteryCapacitySufficient()
return capacity > lowLevel;
}
static UpdaterStatus InstallUpdaterPackage(UpdaterParams &upParams, PkgManager::PkgManagerPtr manager)
UpdaterStatus InstallUpdaterPackage(UpdaterParams &upParams, PkgManager::PkgManagerPtr manager)
{
UpdaterStatus status = UPDATE_UNKNOWN;
STAGE(UPDATE_STAGE_BEGIN) << "Install package";
......@@ -249,7 +250,7 @@ static UpdaterStatus InstallUpdaterPackage(UpdaterParams &upParams, PkgManager::
}
SetMessageToMisc(upParams.miscCmd, upParams.retryCount + 1, "retry_count");
}
if (upParams.sdcardUpdate) {
if (upParams.updateMode == SDCARD_UPDATE) {
status = DoInstallUpdaterPackage(manager, upParams, SDCARD_UPDATE);
} else {
status = DoInstallUpdaterPackage(manager, upParams, HOTA_UPDATE);
......@@ -277,12 +278,16 @@ static UpdaterStatus CalcProgress(const UpdaterParams &upParams,
UPDATER_INIT_RECORD;
int64_t allPkgSize = 0;
std::vector<int64_t> everyPkgSize;
if (upParams.pkgLocation == upParams.updatePackage.size()) {
updateStartPosition = VERIFY_PERCENT;
return UPDATE_SUCCESS;
}
for (const auto &path : upParams.updatePackage) {
char realPath[PATH_MAX + 1] = {0};
if (realpath(path.c_str(), realPath) == nullptr) {
LOG(ERROR) << "Can not find updatePackage : " << path;
UPDATER_LAST_WORD(UPDATE_ERROR);
return UPDATE_ERROR;
LOG(WARNING) << "Can not find updatePackage : " << path;
everyPkgSize.push_back(0);
continue;
}
struct stat st {};
if (stat(realPath, &st) == 0) {
......@@ -316,6 +321,8 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams)
LOG(INFO) << "start to update packages, start index:" << upParams.pkgLocation;
UpdaterStatus status = UPDATE_UNKNOWN;
upParams.installTime.resize(upParams.updatePackage.size(), std::chrono::duration<double>(0));
if (SetupPartitions() != 0) {
UPDATER_UI_INSTANCE.ShowUpdInfo(TR(UPD_SETPART_FAIL), true);
UPDATER_LAST_WORD(UPDATE_ERROR);
......@@ -327,6 +334,11 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams)
LOG(INFO) << "deleate last upgrade file";
}
if(upParams.pkgLocation == upParams.updatePackage.size()) {
LOG(WARNING) << "all package has been upgraded, skip pre process";
return UPDATE_SUCCESS;
}
// verify packages first
if (VerifyPackages(upParams) != UPDATE_SUCCESS) {
UPDATER_LAST_WORD(UPDATE_ERROR);
......@@ -334,7 +346,7 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams)
}
// Only handle UPATE_ERROR and UPDATE_SUCCESS here.Let package verify handle others.
if (IsSpaceCapacitySufficient(upParams.updatePackage) == UPDATE_ERROR) {
if (IsSpaceCapacitySufficient(upParams) == UPDATE_ERROR) {
UPDATER_LAST_WORD(status);
return status;
}
......@@ -356,26 +368,14 @@ static UpdaterStatus PreUpdatePackages(UpdaterParams &upParams)
return UPDATE_SUCCESS;
}
static UpdaterStatus DoUpdatePackages(UpdaterParams &upParams)
static UpdaterStatus DoInstallPackages(UpdaterParams &upParams, std::vector<double> &pkgStartPosition)
{
UPDATER_INIT_RECORD;
UpdaterStatus status = UPDATE_UNKNOWN;
std::vector<double> pkgStartPosition {};
double updateStartPosition;
status = CalcProgress(upParams, pkgStartPosition, updateStartPosition);
if (status != UPDATE_SUCCESS) {
UPDATER_LAST_WORD(status);
return status;
if (upParams.pkgLocation == upParams.updatePackage.size()) {
LOG(WARNING) << "all packages has been installed, directly return success";
upParams.callbackProgress(FULL_PERCENT_PROGRESS);
return UPDATE_SUCCESS;
}
for (unsigned int i = 0; i < upParams.updatePackage.size(); i++) {
LOG(INFO) << "package " << i << ":" << upParams.updatePackage[i] <<
" precent:" << upParams.currentPercentage;
}
if (upParams.callbackProgress == nullptr) {
LOG(ERROR) << "CallbackProgress is nullptr";
return UPDATE_CORRUPT;
}
upParams.callbackProgress(updateStartPosition * FULL_PERCENT_PROGRESS);
for (; upParams.pkgLocation < upParams.updatePackage.size(); upParams.pkgLocation++) {
PkgManager::PkgManagerPtr manager = PkgManager::CreatePackageInstance();
auto startTime = std::chrono::system_clock::now();
......@@ -387,12 +387,12 @@ static UpdaterStatus DoUpdatePackages(UpdaterParams &upParams)
status = InstallUpdaterPackage(upParams, manager);
SetMessageToMisc(upParams.miscCmd, upParams.pkgLocation + 1, "upgraded_pkg_num");
auto endTime = std::chrono::system_clock::now();
upParams.installTime[upParams.pkgLocation] = upParams.installTime[upParams.pkgLocation] + endTime - startTime;
ProgressSmoothHandler(
static_cast<int>(upParams.initialProgress * FULL_PERCENT_PROGRESS +
upParams.currentPercentage * GetTmpProgressValue()),
static_cast<int>(pkgStartPosition[upParams.pkgLocation + 1] * FULL_PERCENT_PROGRESS));
auto endTime = std::chrono::system_clock::now();
upParams.installTime[upParams.pkgLocation] = upParams.installTime[upParams.pkgLocation] + endTime - startTime;
if (status != UPDATE_SUCCESS) {
LOG(ERROR) << "InstallUpdaterPackage failed! Pkg is " << upParams.updatePackage[upParams.pkgLocation];
if (!CheckDumpResult()) {
......@@ -403,6 +403,34 @@ static UpdaterStatus DoUpdatePackages(UpdaterParams &upParams)
}
PkgManager::ReleasePackageInstance(manager);
}
return status;
}
UpdaterStatus DoUpdatePackages(UpdaterParams &upParams)
{
UPDATER_INIT_RECORD;
UpdaterStatus status = UPDATE_UNKNOWN;
std::vector<double> pkgStartPosition {};
double updateStartPosition = 0.0;
status = CalcProgress(upParams, pkgStartPosition, updateStartPosition);
if (status != UPDATE_SUCCESS) {
UPDATER_LAST_WORD(status);
return status;
}
for (unsigned int i = 0; i < upParams.updatePackage.size(); i++) {
LOG(INFO) << "package " << i << ":" << upParams.updatePackage[i] <<
" precent:" << upParams.currentPercentage;
}
if (upParams.callbackProgress == nullptr) {
LOG(ERROR) << "CallbackProgress is nullptr";
return UPDATE_CORRUPT;
}
upParams.callbackProgress(updateStartPosition * FULL_PERCENT_PROGRESS);
status = DoInstallPackages(upParams, pkgStartPosition);
if (status != UPDATE_SUCCESS) {
UPDATER_LAST_WORD(status);
return status;
}
if (upParams.forceUpdate) {
UPDATER_UI_INSTANCE.ShowLogRes(TR(LABEL_UPD_OK_SHUTDOWN));
}
......@@ -420,20 +448,20 @@ static void PostUpdatePackages(UpdaterParams &upParams, bool updateResult)
std::ifstream fin {resultPath};
if (!fin.is_open() || !std::getline(fin, buf)) {
LOG(ERROR) << "read result file error " << resultPath;
buf = "fail";
buf = "fail|";
}
} else {
buf = "pass";
buf = "pass|";
upParams.pkgLocation = upParams.pkgLocation == 0 ? upParams.pkgLocation : (upParams.pkgLocation - 1);
}
for (unsigned int i = 0; i < upParams.pkgLocation; i++) {
time = DurationToString(upParams.installTime[i]);
writeBuffer += upParams.updatePackage[i] + "|pass|install_time=" + time + "\n";
time = DurationToString(upParams.installTime, i);
writeBuffer += upParams.updatePackage[i] + "|pass||install_time=" + time + "|\n";
}
time = DurationToString(upParams.installTime[upParams.pkgLocation]);
time = DurationToString(upParams.installTime, upParams.pkgLocation);
writeBuffer += upParams.updatePackage[upParams.pkgLocation] + "|" + buf + "|install_time=" + time + "\n";
writeBuffer += upParams.updatePackage[upParams.pkgLocation] + "|" + buf + "|install_time=" + time + "|\n";
for (unsigned int i = upParams.pkgLocation + 1; i < upParams.updatePackage.size(); i++) {
writeBuffer += upParams.updatePackage[i] + "\n";
}
......@@ -452,6 +480,7 @@ UpdaterStatus UpdaterFromSdcard(UpdaterParams &upParams)
LOG(ERROR) << "can not find sdcard packages";
return UPDATE_ERROR;
}
upParams.installTime.resize(upParams.updatePackage.size(), std::chrono::duration<double>(0));
// verify packages first
if (upParams.retryCount == 0 && !IsBatteryCapacitySufficient()) {
UPDATER_UI_INSTANCE.ShowUpdInfo(TR(LOG_LOWPOWER));
......@@ -460,7 +489,7 @@ UpdaterStatus UpdaterFromSdcard(UpdaterParams &upParams)
return UPDATE_SKIP;
}
if (upParams.pkgLocation == 0 && VerifyPackages(upParams) != UPDATE_SUCCESS) {
if (VerifyPackages(upParams) != UPDATE_SUCCESS) {
return UPDATE_ERROR;
}
#ifdef UPDATER_USE_PTABLE
......@@ -488,10 +517,10 @@ UpdaterStatus InstallUpdaterPackages(UpdaterParams &upParams)
return status;
}
static UpdaterStatus StartUpdaterEntry(UpdaterParams &upParams)
UpdaterStatus StartUpdaterEntry(UpdaterParams &upParams)
{
UpdaterStatus status = UPDATE_UNKNOWN;
if (upParams.sdcardUpdate) {
if (upParams.updateMode == SDCARD_UPDATE) {
LOG(INFO) << "start sdcard update";
UPDATER_UI_INSTANCE.ShowProgressPage();
status = UpdaterFromSdcard(upParams);
......@@ -555,20 +584,20 @@ static UpdaterStatus StartUpdater(const std::vector<std::string> &args,
std::string option = OPTIONS[optionIndex].name;
if (option == "update_package") {
upParams.updatePackage.push_back(optarg);
(void)UPDATER_UI_INSTANCE.SetMode(UpdaterMode::OTA);
(void)UPDATER_UI_INSTANCE.SetMode(UPDATREMODE_OTA);
mode = HOTA_UPDATE;
} else if (option == "retry_count") {
upParams.retryCount = atoi(optarg);
} else if (option == "factory_wipe_data") {
(void)UPDATER_UI_INSTANCE.SetMode(UpdaterMode::REBOOTFACTORYRST);
(void)UPDATER_UI_INSTANCE.SetMode(UPDATREMODE_REBOOTFACTORYRST);
upParams.factoryWipeData = true;
} else if (option == "user_wipe_data") {
(void)UPDATER_UI_INSTANCE.SetMode(UpdaterMode::REBOOTFACTORYRST);
(void)UPDATER_UI_INSTANCE.SetMode(UPDATREMODE_REBOOTFACTORYRST);
upParams.userWipeData = true;
} else if (option == "upgraded_pkg_num") {
upParams.pkgLocation = static_cast<unsigned int>(atoi(optarg));
} else if (option == "sdcard_update") {
upParams.sdcardUpdate = true;
upParams.updateMode = SDCARD_UPDATE;
} else if (option == "force_update_action" && std::string(optarg) == POWEROFF) { /* Only for OTA. */
upParams.forceUpdate = true;
}
......@@ -581,8 +610,8 @@ static UpdaterStatus StartUpdater(const std::vector<std::string> &args,
}
optind = 1;
// Sanity checks
if (upParams.sdcardUpdate) {
(void)UPDATER_UI_INSTANCE.SetMode(UpdaterMode::SDCARD);
if (upParams.updateMode == SDCARD_UPDATE) {
(void)UPDATER_UI_INSTANCE.SetMode(UPDATREMODE_SDCARD);
mode = SDCARD_UPDATE;
}
if (upParams.factoryWipeData && upParams.userWipeData) {
......
......@@ -17,6 +17,7 @@
#include <iostream>
#include <string>
#include "pkg_manager.h"
#include "updater/updater.h"
#include "updater_init.h"
......@@ -30,6 +31,12 @@ int UpdaterMain(int argc, char **argv);
int FactoryReset(FactoryResetMode mode, const std::string &path);
UpdaterStatus InstallUpdaterPackage(UpdaterParams &upParams, Hpackage::PkgManager::PkgManagerPtr manager);
UpdaterStatus DoUpdatePackages(UpdaterParams &upParams);
UpdaterStatus StartUpdaterEntry(UpdaterParams &upParams);
UpdaterStatus UpdaterFromSdcard(UpdaterParams &upParams);
bool IsBatteryCapacitySufficient();
......
......@@ -46,7 +46,7 @@ void DoProgress()
constexpr int progressValueStep = static_cast<int>(0.3 * ratio);
constexpr int maxProgressValue = static_cast<int>(100 * ratio);
int progressvalueTmp = 0;
if (GetFacade().GetMode() != UpdaterMode::FACTORYRST && GetFacade().GetMode() != UpdaterMode::REBOOTFACTORYRST) {
if (GetFacade().GetMode() != UPDATREMODE_FACTORYRST && GetFacade().GetMode() != UPDATREMODE_REBOOTFACTORYRST) {
return;
}
GetFacade().ShowProgress(0);
......@@ -71,7 +71,7 @@ DEFINE_ASYN_CALLBACK(OnRebootEvt)
DEFINE_SYNC_CALLBACK(OnLabelResetEvt)
{
LOG(INFO) << "On Label Reset";
if (!GetFacade().SetMode(UpdaterMode::FACTORYRST)) {
if (!GetFacade().SetMode(UPDATREMODE_FACTORYRST)) {
return;
}
GetFacade().ShowFactoryConfirmPage();
......@@ -80,7 +80,7 @@ DEFINE_SYNC_CALLBACK(OnLabelResetEvt)
DEFINE_ASYN_CALLBACK(OnLabelSDCardEvt)
{
LOG(INFO) << "On Label SDCard";
if (!GetFacade().SetMode(UpdaterMode::SDCARD)) {
if (!GetFacade().SetMode(UPDATREMODE_SDCARD)) {
return;
}
Utils::UsSleep(CALLBACK_DELAY);
......@@ -89,7 +89,7 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardEvt)
GetFacade().ShowLog(TR(LOG_SDCARD_NOTMOVE));
Utils::UsSleep(DISPLAY_TIME);
UpdaterParams upParams;
upParams.sdcardUpdate = true;
upParams.updateMode = SDCARD_UPDATE;
if (UpdaterFromSdcard(upParams) != UPDATE_SUCCESS) {
GetFacade().ShowMainpage();
return;
......@@ -101,12 +101,12 @@ DEFINE_ASYN_CALLBACK(OnLabelSDCardEvt)
DEFINE_ASYN_CALLBACK(OnLabelSDCardNoDelayEvt)
{
LOG(INFO) << "On Label SDCard";
if (!GetFacade().SetMode(UpdaterMode::SDCARD)) {
if (!GetFacade().SetMode(UPDATREMODE_SDCARD)) {
return;
}
Utils::UsSleep(CALLBACK_DELAY);
UpdaterParams upParams;
upParams.sdcardUpdate = true;
upParams.updateMode = SDCARD_UPDATE;
if (auto res = UpdaterFromSdcard(upParams); res != UPDATE_SUCCESS) {
GetFacade().ShowLogRes(res == UPDATE_CORRUPT ? TR(LOGRES_VERIFY_FAILED) : TR(LOGRES_UPDATE_FAILED));
GetFacade().ShowFailedPage();
......@@ -134,7 +134,7 @@ DEFINE_ASYN_CALLBACK(OnLabelOkEvt)
GetFacade().ShowMainpage();
GetFacade().ClearText();
GetFacade().ShowLog(TR(LOG_WIPE_DATA));
if (!GetFacade().SetMode(UpdaterMode::FACTORYRST)) {
if (!GetFacade().SetMode(UPDATREMODE_FACTORYRST)) {
return;
}
GetFacade().ShowProgress(0);
......@@ -152,7 +152,7 @@ DEFINE_ASYN_CALLBACK(OnLabelOkEvt)
DEFINE_ASYN_CALLBACK(OnConfirmRstEvt)
{
LOG(INFO) << "On Label Ok";
if (!GetFacade().SetMode(UpdaterMode::FACTORYRST)) {
if (!GetFacade().SetMode(UPDATREMODE_FACTORYRST)) {
return;
}
GetFacade().ShowUpdInfo(TR(LABEL_RESET_PROGRESS_INFO));
......@@ -180,7 +180,7 @@ DEFINE_ASYN_CALLBACK(OnMenuClearCacheEvt)
{
LOG(INFO) << "On clear cache";
GetFacade().ClearText();
if (!GetFacade().SetMode(UpdaterMode::FACTORYRST)) {
if (!GetFacade().SetMode(UPDATREMODE_FACTORYRST)) {
return;
}
Utils::UsSleep(CALLBACK_DELAY);
......
......@@ -234,7 +234,7 @@ void SetMessageToMisc(const std::string &miscCmd, const int message, const std::
char buffer[128] {}; // 128 : set headInfo size
if (headInfo == "sdcard_update") {
if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "--%s", headInfo.c_str()) == -1) {
LOG(ERROR) << "SetMessageToMisc strncpy_s failed";
LOG(ERROR) << "SetMessageToMisc snprintf_s failed";
return;
}
} else {
......
......@@ -71,10 +71,10 @@ ohos_fuzztest("UpdaterStartUpdaterProcFuzzTest") {
"//third_party/zlib:libz",
]
external_deps = [
"init:libbegetutil",
"ui_lite:libupdater_layout",
]
external_deps = [ "init:libbegetutil" ]
if (updater_ui_support) {
external_deps += [ "ui_lite:libupdater_layout" ]
}
cflags = [
"-g",
......
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module_output_path = "updater/do_partitions"
import("//base/update/updater/updater_default_cfg.gni")
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
updater_path = rebase_path("${updater_absolutely_path}", ".")
##############################fuzztest##########################################
ohos_fuzztest("ApplyPatchFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${updater_path}/test/fuzztest/applypatch_fuzzer"
include_dirs = [
"${updater_path}/utils/include",
"${updater_path}/interfaces/kits/include/",
"${updater_path}/services/include/fs_manager",
"${updater_path}/services/include/log",
"${updater_path}/services",
"${updater_path}/services/include",
]
deps = [
"${updater_path}/interfaces/kits/diff_patch:libdiff_patch",
"${updater_path}/interfaces/kits/misc_info:libmiscinfo",
"${updater_path}/interfaces/kits/packages:libpackageExt",
"${updater_path}/services/applypatch:libapplypatch",
"${updater_path}/services/diffpatch/patch:libpatch",
"${updater_path}/services/fs_manager:libfsmanager",
"${updater_path}/services/log:libupdaterlog",
"${updater_path}/services/package:libupdaterpackage",
"${updater_path}/services/script:libupdaterscript",
"${updater_path}/services/ui:libui",
"${updater_path}/utils:libutils",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/bzip2:libbz2",
"//third_party/libdrm:libdrm",
"//third_party/lz4:liblz4_static",
"//third_party/openssl:libcrypto_shared",
"//third_party/openssl:libssl_shared",
"//third_party/zlib:libz",
]
external_deps = [
"c_utils:utils",
"init:libbegetutil",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "applypatch_fuzzer.cpp" ]
}
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "diff_patch/diff_patch_interface.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
using namespace Updater;
namespace OHOS {
void FuzzApplyPatch(const uint8_t* data, size_t size)
{
const std::string filePath = "/data/fuzz/test/MountForPath_fuzzer.fstable";
ApplyPatch(filePath, filePath, std::string(reinterpret_cast<const char*>(data)));
ApplyPatch(filePath, std::string(reinterpret_cast<const char*>(data)), filePath);
ApplyPatch(std::string(reinterpret_cast<const char*>(data)), filePath, filePath);
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzApplyPatch(data, size);
return 0;
}
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APPLY_PATCH_FUZZER_H
#define APPLY_PATCH_FUZZER_H
#define FUZZ_PROJECT_NAME "applypatch_fuzzer"
#endif /* APPLY_PATCH_FUZZER_H */
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FUZZ
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2023 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>30</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
......@@ -124,6 +124,11 @@ public:
{
return isRetry;
}
virtual PostMessageFunction GetPostmsgFunc()
{
return nullptr;
}
private:
bool isRetry = false;
};
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration ver="2.0">
<target name="ApplyPatchFuzzTest">
<preparer>
<option name="push" value="MountForPath_fuzzer.fstable -> /data/fuzz/test" src="res"/>
</preparer>
</target>
<target name="ExtractAndExecuteScriptFuzzTest">
<preparer>
<option name="push" value="loadScript.us -> /data/fuzz/test" src="res"/>
......
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module_output_path = "updater/get_update_package_info"
import("//base/update/updater/updater_default_cfg.gni")
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
updater_path = rebase_path("${updater_absolutely_path}", ".")
##############################fuzztest##########################################
ohos_fuzztest("GetUpdatePackageInfoFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${updater_path}/test/fuzztest/getupdatepackageinfo_fuzzer"
include_dirs = [
"${updater_path}/utils/include",
"${updater_path}/interfaces/kits/include/",
"${updater_path}/services/common",
"${updater_path}/services/include/updater",
"${updater_path}/services/include/package",
"${updater_path}/services",
"${updater_path}/services/include",
]
deps = [
"${updater_path}/services:libupdater",
"${updater_path}/services/log:libupdaterlog",
"${updater_path}/services/package:libupdaterpackage",
"${updater_path}/utils:libutils",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/bzip2:libbz2",
"//third_party/libdrm:libdrm",
"//third_party/lz4:liblz4_static",
"//third_party/openssl:libcrypto_shared",
"//third_party/openssl:libssl_shared",
"//third_party/zlib:libz",
]
external_deps = [
"c_utils:utils",
"init:libbegetutil",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "getupdatepackageinfo_fuzzer.cpp" ]
}
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FUZZ
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "getupdatepackageinfo_fuzzer.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include "updater.h"
using namespace Updater;
namespace OHOS {
void FuzzGetUpdatePackageInfo(const uint8_t* data, size_t size)
{
Hpackage::PkgManager::PkgManagerPtr pkgManager = Hpackage::PkgManager::CreatePackageInstance();
GetUpdatePackageInfo(pkgManager, std::string(reinterpret_cast<const char*>(data)));
Hpackage::PkgManager::ReleasePackageInstance(pkgManager);
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzGetUpdatePackageInfo(data, size);
return 0;
}
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GET_UPDATE_PACKAGE_INFO_FUZZER
#define GET_UPDATE_PACKAGE_INFO_FUZZER
#define FUZZ_PROJECT_NAME "getupdatepackageinfo_fuzzer"
#endif /* GET_UPDATE_PACKAGE_INFO_FUZZER */
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2023 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>30</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module_output_path = "updater/package_fuzzer"
import("//base/update/updater/updater_default_cfg.gni")
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
updater_path = rebase_path("${updater_absolutely_path}", ".")
##############################fuzztest##########################################
ohos_fuzztest("PackageFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${updater_path}/test/fuzztest/package_fuzzer"
include_dirs = [
"${updater_path}/interfaces/kits/include",
"${updater_path}/interfaces/kits/include/package",
"${updater_path}/services/common",
"${updater_path}/services/include",
"${updater_path}/services/include/package",
"${updater_path}/utils/include",
"//third_party/bounds_checking_function/include",
]
deps = [
"${updater_path}/interfaces/kits/misc_info:libmiscinfo",
"${updater_path}/interfaces/kits/packages:libpackageExt",
"${updater_path}/interfaces/kits/updaterkits:libupdaterkits",
"${updater_path}/services/log:libupdaterlog",
"${updater_path}/services/package:libupdaterpackage",
"${updater_path}/utils:libutils",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/lz4:liblz4_static",
"//third_party/openssl:libcrypto_shared",
"//third_party/openssl:libssl_shared",
"//third_party/zlib:libz",
]
external_deps = [
"c_utils:utils",
"init:libbegetutil",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"${updater_path}/interfaces/kits/packages/package.cpp",
"package_fuzzer.cpp",
]
}
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FUZZ
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "package_fuzzer.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include "log/log.h"
#include "package.h"
using namespace Updater;
namespace OHOS {
void FuzzVerifyPackage(const uint8_t* data, size_t size)
{
constexpr size_t digestSize = 32;
std::vector<uint8_t> digest(digestSize);
const std::string keyPath = "/data/fuzz/test/signing_cert.crt";
const std::string pkgPath = "/data/fuzz/test/updater.zip";
const std::string pkgDir = "/data/fuzz/test";
VerifyPackage(reinterpret_cast<const char*>(data), keyPath.c_str(), "", digest.data(), digest.capacity());
VerifyPackage(pkgPath.c_str(), reinterpret_cast<const char*>(data), "", digest.data(), digest.capacity());
VerifyPackage(pkgPath.c_str(), keyPath.c_str(), reinterpret_cast<const char*>(data),
digest.data(), digest.capacity());
VerifyPackage(pkgPath.c_str(), keyPath.c_str(), "", data, size);
VerifyPackageWithCallback(reinterpret_cast<const char*>(data), keyPath.c_str(),
[](int32_t result, uint32_t percent) {});
VerifyPackageWithCallback(pkgPath, reinterpret_cast<const char*>(data),
[](int32_t result, uint32_t percent) {});
ExtraPackageDir(reinterpret_cast<const char*>(data), keyPath.c_str(), nullptr, pkgDir.c_str());
ExtraPackageDir(pkgPath.c_str(), reinterpret_cast<const char*>(data), nullptr, pkgDir.c_str());
ExtraPackageDir(pkgPath.c_str(), keyPath.c_str(), reinterpret_cast<const char*>(data), pkgDir.c_str());
ExtraPackageDir(pkgPath.c_str(), keyPath.c_str(), nullptr, reinterpret_cast<const char*>(data));
const std::string file = "updater.bin";
ExtraPackageFile(reinterpret_cast<const char*>(data), keyPath.c_str(), file.c_str(), pkgDir.c_str());
ExtraPackageFile(pkgPath.c_str(), reinterpret_cast<const char*>(data), file.c_str(), pkgDir.c_str());
ExtraPackageFile(pkgPath.c_str(), keyPath.c_str(), reinterpret_cast<const char*>(data), pkgDir.c_str());
ExtraPackageFile(pkgPath.c_str(), keyPath.c_str(), file.c_str(), reinterpret_cast<const char*>(data));
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzVerifyPackage(data, size);
return 0;
}
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PACKAGE_FUZZER_H
#define PACKAGE_FUZZER_H
#define FUZZ_PROJECT_NAME "package_fuzzer"
#endif /* PACKAGE_FUZZER_H */
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2023 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>30</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module_output_path = "updater/reboot_and_install_upgrade_package"
import("//base/update/updater/updater_default_cfg.gni")
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
updater_path = rebase_path("${updater_absolutely_path}", ".")
##############################fuzztest##########################################
ohos_fuzztest("RebootAndInstallUpgradePackageFuzzTest") {
defines = [
"UPDATER_UT",
"BUILD_OHOS",
"HDC_DEBUG",
"HDC_SUPPORT_FLASHD",
"HARMONY_PROJECT",
]
#configs = [ "${updater_path}/test/unittest:utest_config" ]
module_out_path = module_output_path
fuzz_config_file =
"${updater_path}/test/fuzztest/rebootandinstallupgradepackage_fuzzer"
include_dirs = [
"${updater_path}/interfaces/kits/include",
"${updater_path}/services/include/log",
"${updater_path}/utils/include",
"//third_party/bounds_checking_function/include",
]
deps = [
"${updater_path}/interfaces/kits/misc_info:libmiscinfo",
"${updater_path}/interfaces/kits/updaterkits:libupdaterkits",
"${updater_path}/services/log:libupdaterlog",
"${updater_path}/utils:libutils",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [
"c_utils:utils",
"init:libbegetutil",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"${updater_path}/interfaces/kits/updaterkits/updaterkits.cpp",
"rebootandinstallupgradepackage_fuzzer.cpp",
]
}
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FUZZ
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>30</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "rebootandinstallupgradepackage_fuzzer.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include "log/log.h"
#include "updaterkits/updaterkits.h"
#include "securec.h"
using namespace Updater;
namespace OHOS {
void FuzzUpdaterKits(const uint8_t* data, size_t size)
{
// const std::string miscFile = "/dev/block/by_name/misc";
const std::vector<std::string> packageName {std::string(reinterpret_cast<const char*>(data))};
RebootAndInstallUpgradePackage("", packageName);
RebootAndCleanUserData("", std::string(reinterpret_cast<const char*>(data)));
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzUpdaterKits(data, size);
return 0;
}
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef REBOOT_AND_INSTALL_UPGRADE_PACKAGE_FUZZER_H
#define REBOOT_AND_INSTALL_UPGRADE_PACKAGE_FUZZER_H
#define FUZZ_PROJECT_NAME "rebootandinstallupgradepackage_fuzzer"
#endif /* REBOOT_AND_INSTALL_UPGRADE_PACKAGE_FUZZER_H */
......@@ -69,10 +69,10 @@ ohos_fuzztest("UpdaterFactoryResetFuzzTest") {
"//third_party/zlib:libz",
]
external_deps = [
"init:libbegetutil",
"ui_lite:libupdater_layout",
]
external_deps = [ "init:libbegetutil" ]
if (updater_ui_support) {
external_deps += [ "ui_lite:libupdater_layout" ]
}
cflags = [
"-g",
......
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module_output_path = "updater/write_updater_msg"
import("//base/update/updater/updater_default_cfg.gni")
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
updater_path = rebase_path("${updater_absolutely_path}", ".")
##############################fuzztest##########################################
ohos_fuzztest("WriteUpdaterMsgFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "${updater_path}/test/fuzztest/writeupdatermsg_fuzzer"
include_dirs = [
"${updater_path}/interfaces/kits/include",
"${updater_path}/services/common",
"${updater_path}/services/include",
"${updater_path}/utils/include",
"//third_party/bounds_checking_function/include",
]
deps = [
"${updater_path}/interfaces/kits/misc_info:libmiscinfo",
"${updater_path}/services/fs_manager:libfsmanager",
"${updater_path}/services/log:libupdaterlog",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "init:libbegetutil" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "writeupdatermsg_fuzzer.cpp" ]
}
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FUZZ
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>30</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "writeupdatermsg_fuzzer.h"
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include "log/log.h"
#include "misc_info/misc_info.h"
#include "securec.h"
using namespace Updater;
namespace OHOS {
void FuzzWriteUpdaterMsg(const uint8_t* data, size_t size)
{
UpdateMessage boot;
if (strcpy_s(boot.update, MAX_UPDATE_SIZE - 1, reinterpret_cast<const char*>(data)) != EOK) {
return;
}
ReadUpdaterMiscMsg(boot);
const std::string path = "/dev/block/by_name/misc";
WriteUpdaterMessage(path, boot);
WriteUpdaterMiscMsg(boot);
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzWriteUpdaterMsg(data, size);
return 0;
}
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DO_PARTTIONS_FUZZER_H
#define DO_PARTTIONS_FUZZER_H
#define FUZZ_PROJECT_NAME "dopartitions_fuzzer"
#endif /* DO_PARTTIONS_FUZZER_H */
......@@ -54,6 +54,7 @@ ohos_unittest("updater_unittest") {
sources = [
"diffpatch/bzip2_unittest.cpp",
"diffpatch/diffpatch_unittest.cpp",
"diffpatch/image_patch_unittest.cpp",
"log_test/log_unittest.cpp",
"misc_info_test/misc_info_unittest.cpp",
"updaterkits_test/updaterkits_unittest.cpp",
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "image_patch.h"
#include "diffpatch.h"
#include "unittest_comm.h"
using namespace std;
using namespace Hpackage;
using namespace UpdatePatch;
using namespace testing::ext;
namespace {
class TestCompressedImagePatch : public CompressedImagePatch {
public:
TestCompressedImagePatch(UpdatePatchWriterPtr writer, const std::vector<uint8_t> &bonusData)
: CompressedImagePatch(writer, bonusData) {}
~TestCompressedImagePatch() override {}
int32_t ApplyImagePatch(const PatchParam &param, size_t &startOffset) override
{
return 0;
}
int32_t TestStartReadHeader(const PatchParam &param, PatchHeader &header, size_t &offset)
{
return StartReadHeader(param, header, offset);
}
int32_t TestDecompressData(PkgManager::PkgManagerPtr &pkgManager, PkgBuffer buffer,
PkgManager::StreamPtr &stream, bool memory, size_t expandedLen)
{
return DecompressData(pkgManager, buffer, stream, memory, expandedLen);
}
protected:
int32_t ReadHeader(const PatchParam &param, PatchHeader &header, size_t &offset) override
{
return 0;
}
std::unique_ptr<FileInfo> GetFileInfo() const override
{
ZipFileInfo *fileInfo = new(std::nothrow) ZipFileInfo;
return std::unique_ptr<FileInfo>((FileInfo *)fileInfo);
}
};
class CompressedImagePatchUnitTest : public testing::Test {
public:
CompressedImagePatchUnitTest() {}
~CompressedImagePatchUnitTest() {}
static void SetUpTestCase(void) {}
static void TearDownTestCase(void) {}
void SetUp() {}
void TearDown() {}
void TestBody() {}
};
HWTEST_F(CompressedImagePatchUnitTest, TestStartReadHeader, TestSize.Level0)
{
UpdatePatchWriterPtr writer = nullptr;
const std::vector<uint8_t> bonusData;
TestCompressedImagePatch test(writer, bonusData);
PatchParam patchParam = {
reinterpret_cast<u_char*>(const_cast<char*>("xxx")), sizeof("xxx"),
reinterpret_cast<u_char*>(const_cast<char*>("xxx")), sizeof("xxx")
};
PatchHeader header = {0, 0, 0, 0, 0};
size_t offset = 0;
int32_t ret = test.TestStartReadHeader(patchParam, header, offset);
EXPECT_EQ(ret, 0);
}
HWTEST_F(CompressedImagePatchUnitTest, TestDecompressData, TestSize.Level0)
{
UpdatePatchWriterPtr writer = nullptr;
const std::vector<uint8_t> bonusData;
TestCompressedImagePatch test(writer, bonusData);
PkgManager::PkgManagerPtr pkgManager = nullptr;
PkgBuffer buffer;
PkgManager::StreamPtr stream;
bool memory = false;
size_t expandedLen = 0;
int32_t ret = test.TestDecompressData(pkgManager, buffer, stream, memory, expandedLen);
EXPECT_EQ(ret, 0);
expandedLen = 1;
ret = test.TestDecompressData(pkgManager, buffer, stream, memory, expandedLen);
EXPECT_EQ(ret, -1);
pkgManager = PkgManager::CreatePackageInstance();
ret = test.TestDecompressData(pkgManager, buffer, stream, memory, expandedLen);
EXPECT_EQ(ret, -1);
PkgManager::ReleasePackageInstance(pkgManager);
}
}
......@@ -46,6 +46,7 @@ ohos_unittest("bin_flow_update_test") {
"${updater_path}/services/package",
"${updater_path}/services/package/pkg_algorithm",
"${updater_path}/services/package/pkg_manager",
"${updater_path}/services/package/pkg_package",
"${updater_path}/services/script",
"${updater_path}/services/flow_update/update_bin",
"${updater_path}/test/unittest",
......
......@@ -116,6 +116,8 @@ public:
devicePtnInfo[0].dispName = "TestIsPtableChanged1";
ret = context.TestIsPtableChanged(devicePtnInfo, pkgPtnInfo);
ASSERT_EQ(ret, true);
ret = context.WritePtableToDevice();
ASSERT_EQ(ret, false);
}
void TestInitPtableManagerAndSetDeviceStorageType()
......@@ -147,6 +149,8 @@ public:
partitionName = "testPartition";
ret = context.GetPartionInfoByName(partitionName, ptnInfo);
ASSERT_EQ(ret, false);
ret = context.WritePartitionTable();
ASSERT_EQ(ret, false);
}
void TestIsPartitionChanged()
......
......@@ -43,6 +43,10 @@ namespace {
class MockUScriptEnv : public UScriptEnv {
public:
explicit MockUScriptEnv(Hpackage::PkgManager::PkgManagerPtr pkgManager) : UScriptEnv(pkgManager) {}
virtual PostMessageFunction GetPostmsgFunc()
{
return nullptr;
}
MOCK_CONST_METHOD0(IsRetry, bool());
MOCK_METHOD2(PostMessage, void(const std::string &cmd, std::string content));
MOCK_METHOD0(GetInstructionFactory, UScriptInstructionFactoryPtr());
......
......@@ -38,6 +38,11 @@ public:
{
return isRetry;
}
virtual Updater::PostMessageFunction GetPostmsgFunc()
{
return nullptr;
}
UScriptInstructionFactory *factory_ = nullptr;
private:
bool isRetry = false;
......
......@@ -205,6 +205,11 @@ public:
{
return isRetry;
}
virtual PostMessageFunction GetPostmsgFunc()
{
return nullptr;
}
UScriptInstructionFactory *factory_ = nullptr;
private:
bool isRetry = false;
......
......@@ -107,7 +107,8 @@ public:
{
return PKG_SUCCESS;
}
int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName, Updater::RingBuffer *buffer) override
int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName,
uint64_t fileLen, Updater::RingBuffer *buffer) override
{
return PKG_SUCCESS;
}
......
......@@ -24,6 +24,7 @@
#include "fs_manager/mount.h"
#include "misc_info/misc_info.h"
#include "updater_main.h"
#include "updater_ui_stub.h"
#include "utils.h"
using namespace Updater;
......@@ -237,15 +238,17 @@ HWTEST_F(UpdaterUtilUnitTest, updater_ExtractUpdaterBinary, TestSize.Level1)
HWTEST_F(UpdaterUtilUnitTest, updater_IsSpaceCapacitySufficient, TestSize.Level1)
{
std::vector<std::string> packagePath;
UpdaterStatus status = IsSpaceCapacitySufficient(packagePath);
UpdaterParams upParams {};
UpdaterStatus status = IsSpaceCapacitySufficient(upParams);
EXPECT_EQ(status, UPDATE_ERROR);
packagePath.push_back("/data/updater/updater/updater_full.zip");
status = IsSpaceCapacitySufficient(packagePath);
upParams.updatePackage.push_back("/data/updater/updater/updater_full.zip");
status = IsSpaceCapacitySufficient(upParams);
EXPECT_EQ(status, UPDATE_SUCCESS);
packagePath.push_back("xxx");
upParams.updatePackage.push_back("xxx");
ProgressSmoothHandler(0, 0);
status = IsSpaceCapacitySufficient(packagePath);
ProgressSmoothHandler(-1, 0);
ProgressSmoothHandler(0, 1);
status = IsSpaceCapacitySufficient(upParams);
EXPECT_EQ(status, UPDATE_ERROR);
}
......@@ -280,4 +283,49 @@ HWTEST_F(UpdaterUtilUnitTest, updater_HandleChildOutput, TestSize.Level1)
HandleChildOutput(buf, buf.size(), retryUpdate, upParams);
EXPECT_EQ(retryUpdate, true);
}
HWTEST_F(UpdaterUtilUnitTest, InstallUpdaterPackageTest, TestSize.Level1)
{
UpdaterParams upParams;
upParams.retryCount = 0;
upParams.callbackProgress = [] (float value) { UPDATER_UI_INSTANCE.ShowProgress(value); };
upParams.updatePackage.push_back("/data/updater/updater/updater_full.zip");
Hpackage::PkgManager::PkgManagerPtr pkgManager = Hpackage::PkgManager::CreatePackageInstance();
EXPECT_EQ(InstallUpdaterPackage(upParams, pkgManager), UPDATE_ERROR);
upParams.updateMode = SDCARD_UPDATE;
upParams.retryCount = 1;
EXPECT_EQ(InstallUpdaterPackage(upParams, pkgManager), UPDATE_ERROR);
}
HWTEST_F(UpdaterUtilUnitTest, DoUpdatePackagesTest, TestSize.Level1)
{
UpdaterParams upParams;
EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_ERROR);
upParams.updatePackage.push_back("/data/updater/updater/updater_full.zip");
EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_CORRUPT);
upParams.callbackProgress = [] (float value) { UPDATER_UI_INSTANCE.ShowProgress(value); };
upParams.installTime.push_back(std::chrono::duration<double>(0));
EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_ERROR);
}
HWTEST_F(UpdaterUtilUnitTest, StartUpdaterEntryTest, TestSize.Level1)
{
UpdaterParams upParams;
upParams.factoryWipeData = true;
EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_ERROR);
upParams.factoryWipeData = false;
upParams.userWipeData = true;
EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_ERROR);
upParams.userWipeData = false;
EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_ERROR);
}
HWTEST_F(UpdaterUtilUnitTest, StartUpdaterProcTest, TestSize.Level1)
{
Hpackage::PkgManager::PkgManagerPtr pkgManager = Hpackage::PkgManager::CreatePackageInstance();
UpdaterParams upParams;
int maxTemperature = 0;
EXPECT_EQ(StartUpdaterProc(nullptr, upParams, maxTemperature), UPDATE_CORRUPT);
EXPECT_EQ(StartUpdaterProc(pkgManager, upParams, maxTemperature), UPDATE_ERROR);
}
}
\ No newline at end of file
......@@ -117,6 +117,7 @@
<option name="push" value="src/test_function.us -> /data/updater/src" src="res"/>
<option name="push" value="src/loadScript.us -> /data/updater/src" src="res"/>
<option name="push" value="src/Verse-script.us -> /data/updater/src" src="res"/>
<option name="push" value="src/updater_log_test -> /data/updater/log" src="res"/>
</preparer>
</target>
<target name="applypatch_unittest">
......@@ -218,6 +219,12 @@
<option name="push" value="updater/etc/fstab.ut.updater -> /data/updater/updater/etc" src="res"/>
</preparer>
</target>
<target name="utils_test">
<preparer>
<option name="push" value="src/updater_log_test -> /data/updater/log" src="res"/>
<option name="push" value="updater/etc/fstab.ut.updater -> /data/updater/updater/etc" src="res"/>
</preparer>
</target>
<target name="bin_flow_update_test">
<preparer>
<option name="push" value="updater/update.bin -> /data/updater/package" src="res"/>
......
......@@ -48,6 +48,11 @@ public:
return isRetry_ = retry;
}
virtual Updater::PostMessageFunction GetPostmsgFunc()
{
return nullptr;
}
Uscript::UScriptInstructionFactory *factory_ = nullptr;
private:
bool isRetry_ = false;
......
......@@ -117,7 +117,7 @@ HWTEST_F(UpdaterUnitTest, updater_UpdateSdcard, TestSize.Level1)
{
UpdaterStatus status;
UpdaterParams upParams;
upParams.sdcardUpdate = true;
upParams.updateMode = SDCARD_UPDATE;
status = UpdaterFromSdcard(upParams);
EXPECT_EQ(status, UPDATE_SUCCESS);
}
......
......@@ -68,31 +68,31 @@ HWTEST_F(UpdaterUiStrategyUnitTest, test_load_strategy_for_each_mode, TestSize.L
"ProgressUpdBoxDark_Progress", "bar", "OHOSIconDark_Image", "img", "PowerLongPressWarning_Image"},
ResPage {"upd:updateSuccess", "upd:normalUpdateFailed"}
};
std::unordered_map<Updater::UpdaterMode, Updater::UiStrategyCfg> expected {};
auto &sdCardCfg = expected[UpdaterMode::SDCARD];
std::unordered_map<std::string, Updater::UiStrategyCfg> expected {};
auto &sdCardCfg = expected[UPDATREMODE_SDCARD];
sdCardCfg = defaultCfg;
sdCardCfg.progressPage = ProgressPage {"upd:sdUpdate", "UpdBox_Progress", "bar",
"OHOSIcon_Image", "img", "PowerLongPressWarning_Image"};
sdCardCfg.labelLogResId = {"upd", "UpdateInfoDark_Label"};
sdCardCfg.resPage = {"upd:updateSuccess", "upd:updateFailedNoButton"};
auto &factoryRstCfg = expected[UpdaterMode::FACTORYRST];
auto &factoryRstCfg = expected[UPDATREMODE_FACTORYRST];
factoryRstCfg = defaultCfg;
factoryRstCfg.progressPage = ProgressPage {"upd:reset", "UpdBox_Progress", "bar", "OHOSIcon_Image", "img", ""};
factoryRstCfg.labelLogResId = {"upd", "UpdateInfoDark_Label"};
factoryRstCfg.labelUpdId = {"upd", "RstInfo_Label"};
factoryRstCfg.resPage = {"menu:normal", "upd:FactoryRstFailed"};
auto &rebootFactoryRstCfg = expected[UpdaterMode::REBOOTFACTORYRST];
auto &rebootFactoryRstCfg = expected[UPDATREMODE_REBOOTFACTORYRST];
rebootFactoryRstCfg = defaultCfg;
rebootFactoryRstCfg.labelLogResId = {"upd", "RstInfo_Label"};
rebootFactoryRstCfg.progressPage = {"upd:reset", "UpdBox_Progress", "bar", "OHOSIcon_Image", "img", ""};
rebootFactoryRstCfg.resPage = {"upd:reset", "upd:FactoryRstFailed"};
EXPECT_EQ(UiStrategy::GetStrategy(), (std::unordered_map<Updater::UpdaterMode, Updater::UiStrategyCfg> {
{UpdaterMode::SDCARD, sdCardCfg}, {UpdaterMode::FACTORYRST, factoryRstCfg},
{UpdaterMode::REBOOTFACTORYRST, rebootFactoryRstCfg}, {UpdaterMode::OTA, defaultCfg},
{UpdaterMode::RECOVER, defaultCfg}
EXPECT_EQ(UiStrategy::GetStrategy(), (std::unordered_map<std::string, Updater::UiStrategyCfg> {
{UPDATREMODE_SDCARD, sdCardCfg}, {UPDATREMODE_FACTORYRST, factoryRstCfg},
{UPDATREMODE_REBOOTFACTORYRST, rebootFactoryRstCfg}, {UPDATREMODE_OTA, defaultCfg},
{UPDATREMODE_RECOVER, defaultCfg}
}));
}
} // namespace
......@@ -46,11 +46,20 @@ ohos_unittest("utils_test") {
"init:libbegetutil",
]
deps = [
"${updater_path}/interfaces/kits/misc_info:libmiscinfo",
"${updater_path}/services/fs_manager:libfsmanager",
"${updater_path}/services/log:libupdaterlog",
"${updater_path}/services/package:libupdaterpackage",
"${updater_path}/utils:libutils",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/bzip2:libbz2",
"//third_party/cJSON:cjson",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
"//third_party/lz4:liblz4_static",
"//third_party/openssl:libcrypto_shared",
"//third_party/openssl:libssl_static",
"//third_party/zlib:libz",
]
configs = [ "${updater_path}/test/unittest:utest_config" ]
install_enable = true
......
......@@ -78,7 +78,9 @@ HWTEST_F(UtilsUnitTest, updater_utils_test_005, TestSize.Level0)
HWTEST_F(UtilsUnitTest, updater_utils_test_006, TestSize.Level0)
{
std::vector<std::string> files;
string path = "/data";
string path = "/data/updater/log";
Utils::SaveLogs();
Utils::CompressLogs("/data/updater/log/updater_log_test");
EXPECT_NE(Utils::GetFilesFromDirectory(path, files, true), -1);
}
......@@ -118,4 +120,26 @@ HWTEST_F(UtilsUnitTest, IsDirExist, TestSize.Level0)
EXPECT_EQ(Utils::IsDirExist("/bin"), true);
EXPECT_EQ(Utils::IsDirExist("/bin/"), true);
}
HWTEST_F(UtilsUnitTest, CopyUpdaterLogsTest, TestSize.Level0)
{
const std::string sLog = "/data/updater/main_data/updater.tab";
const std::string dLog = "/data/updater/main_data/ut_dLog.txt";
bool ret = Utils::CopyUpdaterLogs(sLog, dLog);
EXPECT_EQ(ret, false);
unlink(dLog.c_str());
}
HWTEST_F(UtilsUnitTest, GetDirSizeForFileTest, TestSize.Level0)
{
const std::string testNoPath = "xxx";
long long int ret = Utils::GetDirSizeForFile(testNoPath);
EXPECT_EQ(ret, -1);
const std::string testVaildPath = "xxx/xxx";
ret = Utils::GetDirSizeForFile(testVaildPath);
EXPECT_EQ(ret, 0);
const std::string testPath = "/data/updater/updater/etc/fstab.ut.updater";
ret = Utils::GetDirSizeForFile(testPath);
EXPECT_EQ(ret, 827); // 827 : file size
}
} // updater_ut
......@@ -77,7 +77,8 @@ bool DeleteOldFile(const std::string dest);
void SaveLogs();
std::vector<std::string> ParseParams(int argc, char **argv);
bool CheckUpdateMode(const std::string &mode);
std::string DurationToString(std::chrono::duration<double> duration, int precision = 2);
std::string DurationToString(std::vector<std::chrono::duration<double>> &durations, std::size_t pkgPosition,
int precision = 2);
#ifdef __cplusplus
#if __cplusplus
......
......@@ -504,7 +504,7 @@ bool CheckDumpResult()
const std::string resultPath = std::string(UPDATER_PATH) + "/" + std::string(UPDATER_RESULT_FILE);
ifs.open(resultPath, std::ios::in);
std::string buff;
if (ifs.is_open() && getline(ifs, buff) && buff.find("fail:") != std::string::npos) {
if (ifs.is_open() && getline(ifs, buff) && buff.find("fail|") != std::string::npos) {
return true;
}
LOG(ERROR) << "open result file failed";
......@@ -750,10 +750,15 @@ bool CheckUpdateMode(const std::string &mode)
return false;
}
std::string DurationToString(std::chrono::duration<double> duration, int precision)
std::string DurationToString(std::vector<std::chrono::duration<double>> &durations, std::size_t pkgPosition,
int precision)
{
if (pkgPosition >= durations.size()) {
LOG(ERROR) << "pkg position is " << pkgPosition << ", duration's size is " << durations.size();
return "0";
}
std::ostringstream oss;
oss << std::fixed << std::setprecision(precision) << duration.count();
oss << std::fixed << std::setprecision(precision) << durations[pkgPosition].count();
return oss.str();
}
} // Utils
......