Modern Apps git

← xtool.git

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

Commit
74d6a91537b66ec26c76af3634bc3db82e558ab5
Author
Amlal El Mahrouss <[email protected]>
When
2025-06-28 21:34 UTC (1 year ago)
Parents
187fbfa
# fix: hardening `mobileprovision.c` to avoid future crashes.

## Context:

I found two common weakness inside `Sources/CXKit/mobileprovision.c`,
which seems to be an important layer of `xtool`'s signing logic.

### Common weaknesses found:

- CWE-476
- CWE-119

---------

Co-authored-by: Kabir Oberai <[email protected]>

Diff

Sources/CXKit/mobileprovision.c
diff --git a/Sources/CXKit/mobileprovision.c b/Sources/CXKit/mobileprovision.cindex 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;