Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

Harden `mobileprovision.c` to avoid UB on OOM (#122)

Amlal El Mahrouss74d6a91537b6
diff --git a/Sources/CXKit/mobileprovision.c b/Sources/CXKit/mobileprovision.c
index 33d8b29..9057efd 100644
--- a/Sources/CXKit/mobileprovision.c
+++ b/Sources/CXKit/mobileprovision.c
@@ -18,6 +18,8 @@ struct mobileprovision {
static mobileprovision_t mobileprovision_create(PKCS7 *raw) {
mobileprovision_t profile = malloc(sizeof(struct mobileprovision));
+ if (!profile) return NULL;
+
profile->raw = raw;
return profile;
}
@@ -41,6 +43,12 @@ void *mobileprovision_copy_data(mobileprovision_t profile, size_t *len) {
if (data_len < 0) return NULL;
*len = data_len;
void *ret = malloc(data_len);
+
+ if (!ret) {
+ OPENSSL_free(data);
+ return NULL;
+ }
+
memcpy(ret, data, data_len);
OPENSSL_free(data);
return ret;