From 7e585512f4409eb4e1635ed4d58e9c9774495dfa Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Sat, 17 Jul 2021 23:21:16 +0300 Subject: io: make apk_istream_get/read() fail on incomplete read --- src/package.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/package.c') diff --git a/src/package.c b/src/package.c index dee15eb..fd0104a 100644 --- a/src/package.c +++ b/src/package.c @@ -976,23 +976,13 @@ int apk_ipkg_add_script(struct apk_installed_package *ipkg, struct apk_istream *is, unsigned int type, unsigned int size) { - void *ptr; - int r; - - if (type >= APK_SCRIPT_MAX) - return -1; - - ptr = malloc(size); - r = apk_istream_read(is, ptr, size); - if (r < 0) { - free(ptr); - return r; - } + apk_blob_t b; - if (ipkg->script[type].ptr) - free(ipkg->script[type].ptr); - ipkg->script[type].ptr = ptr; - ipkg->script[type].len = size; + if (type >= APK_SCRIPT_MAX) return -1; + b = apk_blob_from_istream(is, size); + if (APK_BLOB_IS_NULL(b)) return -1; + if (ipkg->script[type].ptr) free(ipkg->script[type].ptr); + ipkg->script[type] = b; return 0; } -- cgit v1.2.3-70-g09d2