summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-12-27 10:20:03 +0200
committerTimo Teräs <timo.teras@iki.fi>2021-12-27 10:20:03 +0200
commit0baf59627bb62a72de99ed05c77f6e39be00cd03 (patch)
treeacc92d5dd863c9c812b9088bd8dd4bd69b21cf1a /src
parent4ccf038a9f79bf0cbe62a6fe24fde8601754e3c2 (diff)
downloadapk-tools-0baf59627bb62a72de99ed05c77f6e39be00cd03.tar.gz
apk-tools-0baf59627bb62a72de99ed05c77f6e39be00cd03.tar.bz2
apk-tools-0baf59627bb62a72de99ed05c77f6e39be00cd03.tar.xz
apk-tools-0baf59627bb62a72de99ed05c77f6e39be00cd03.zip
io: fix tee error handling path
Make sure the from is not dereferenced/used on error path, and cancel the ostream. fixes #10800
Diffstat (limited to 'src')
-rw-r--r--src/io.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/io.c b/src/io.c
index 9f152f6..5c14ae1 100644
--- a/src/io.c
+++ b/src/io.c
@@ -462,9 +462,12 @@ struct apk_istream *apk_istream_tee(struct apk_istream *from, struct apk_ostream
err_free:
free(tee);
err:
- if (!IS_ERR(to)) apk_ostream_close(to);
- if (!IS_ERR(from) && (flags & APK_ISTREAM_TEE_OPTIONAL))
- return from;
+ if (!IS_ERR(to)) {
+ apk_ostream_cancel(to, r);
+ apk_ostream_close(to);
+ }
+ if (IS_ERR(from)) return ERR_CAST(from);
+ if (flags & APK_ISTREAM_TEE_OPTIONAL) return from;
return ERR_PTR(apk_istream_close_error(from, r));
}