diff options
author | Timo Teräs <timo.teras@iki.fi> | 2021-07-17 23:21:16 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-07-22 15:30:08 +0300 |
commit | 7e585512f4409eb4e1635ed4d58e9c9774495dfa (patch) | |
tree | a47e9a278ab9178e0dde9cc3ff937b0b4c5a96b2 /src/package.c | |
parent | 395e92b66e35ccbd2f07a4857d6da588ec9f51f2 (diff) | |
download | apk-tools-7e585512f4409eb4e1635ed4d58e9c9774495dfa.tar.gz apk-tools-7e585512f4409eb4e1635ed4d58e9c9774495dfa.tar.bz2 apk-tools-7e585512f4409eb4e1635ed4d58e9c9774495dfa.tar.xz apk-tools-7e585512f4409eb4e1635ed4d58e9c9774495dfa.zip |
io: make apk_istream_get/read() fail on incomplete read
Diffstat (limited to 'src/package.c')
-rw-r--r-- | src/package.c | 22 |
1 files changed, 6 insertions, 16 deletions
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; } |