From 693bf2aa529e55deb8b9bd658c0d0e1dc4051e50 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 11 Aug 2021 23:31:26 +0200 Subject: tss: Remove numerous free() calls and instead free at start of plist dictionary parsing loop --- src/tss.c | 55 ++++++++++++------------------------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/tss.c b/src/tss.c index c2292bd..ae46e15 100644 --- a/src/tss.c +++ b/src/tss.c @@ -730,143 +730,116 @@ int tss_request_add_ap_recovery_tags(plist_t request, plist_t parameters, plist_ plist_dict_iter iter = NULL; plist_dict_new_iter(manifest_node, &iter); while (1) { + free(key); + key = NULL; plist_dict_next_item(manifest_node, iter, &key, &manifest_entry); if (key == NULL) break; if (!manifest_entry || plist_get_node_type(manifest_entry) != PLIST_DICT) { error("ERROR: Unable to fetch BuildManifest entry\n"); + free(key); return -1; } /* do not populate BaseBandFirmware, only in basebaseband request */ if ((strcmp(key, "BasebandFirmware") == 0)) { - free(key); continue; } // Compared to ac2, not needed for RecoveryOSRootTicket if ((strcmp(key, "SE,UpdatePayload") == 0)) { - free(key); continue; } if ((strcmp(key, "BaseSystem") == 0)) { - free(key); continue; } if ((strcmp(key, "ANS") == 0)) { - free(key); continue; } if ((strcmp(key, "Ap,AudioBootChime") == 0)) { - free(key); continue; } if ((strcmp(key, "Ap,CIO") == 0)) { - free(key); continue; } if ((strcmp(key, "Ap,RestoreCIO") == 0)) { - free(key); continue; } if ((strcmp(key, "Ap,RestoreTMU") == 0)) { - free(key); continue; } if ((strcmp(key, "Ap,TMU") == 0)) { - free(key); continue; } if ((strcmp(key, "Ap,rOSLogo1") == 0)) { - free(key); continue; } if ((strcmp(key, "Ap,rOSLogo2") == 0)) { - free(key); continue; } if ((strcmp(key, "AppleLogo") == 0)) { - free(key); continue; } if ((strcmp(key, "DCP") == 0)) { - free(key); continue; } if ((strcmp(key, "LLB") == 0)) { - free(key); continue; } if ((strcmp(key, "RecoveryMode") == 0)) { - free(key); continue; } if ((strcmp(key, "RestoreANS") == 0)) { - free(key); continue; } if ((strcmp(key, "RestoreDCP") == 0)) { - free(key); continue; } if ((strcmp(key, "RestoreDeviceTree") == 0)) { - free(key); continue; } if ((strcmp(key, "RestoreKernelCache") == 0)) { - free(key); continue; } if ((strcmp(key, "RestoreLogo") == 0)) { - free(key); continue; } if ((strcmp(key, "RestoreRamDisk") == 0)) { - free(key); continue; } if ((strcmp(key, "RestoreSEP") == 0)) { - free(key); continue; } if ((strcmp(key, "SEP") == 0)) { - free(key); continue; } if ((strcmp(key, "ftap") == 0)) { - free(key); continue; } if ((strcmp(key, "ftsp") == 0)) { - free(key); continue; } if ((strcmp(key, "iBEC") == 0)) { - free(key); continue; } if ((strcmp(key, "iBSS") == 0)) { - free(key); continue; } if ((strcmp(key, "rfta") == 0)) { - free(key); continue; } if ((strcmp(key, "rfts") == 0)) { - free(key); continue; } /* FIXME: only used with diagnostics firmware */ if (strcmp(key, "Diags") == 0) { - free(key); continue; } if (_plist_dict_get_bool(parameters, "_OnlyFWComponents")) { if (!_plist_dict_get_bool(manifest_entry, "Trusted")) { - debug("DEBUG: %s: Skipping '%s' as it is not trusted", __func__, key); + debug("DEBUG: %s: Skipping '%s' as it is not trusted\n", __func__, key); continue; } @@ -903,9 +876,8 @@ int tss_request_add_ap_recovery_tags(plist_t request, plist_t parameters, plist_ /* finally add entry to request */ plist_dict_set_item(request, key, tss_entry); - - free(key); } + free(key); free(iter); /* apply overrides */ @@ -930,35 +902,34 @@ int tss_request_add_ap_tags(plist_t request, plist_t parameters, plist_t overrid plist_dict_iter iter = NULL; plist_dict_new_iter(manifest_node, &iter); while (1) { + free(key); + key = NULL; plist_dict_next_item(manifest_node, iter, &key, &manifest_entry); if (key == NULL) break; if (!manifest_entry || plist_get_node_type(manifest_entry) != PLIST_DICT) { error("ERROR: Unable to fetch BuildManifest entry\n"); + free(key); return -1; } /* do not populate BaseBandFirmware, only in basebaseband request */ if ((strcmp(key, "BasebandFirmware") == 0)) { - free(key); continue; } // Compared to ac2, not needed if ((strcmp(key, "SE,UpdatePayload") == 0)) { - free(key); continue; } // Compared to ac2, not needed if ((strcmp(key, "BaseSystem") == 0)) { - free(key); continue; } /* FIXME: only used with diagnostics firmware */ if (strcmp(key, "Diags") == 0) { - free(key); continue; } @@ -1001,9 +972,8 @@ int tss_request_add_ap_tags(plist_t request, plist_t parameters, plist_t overrid /* finally add entry to request */ plist_dict_set_item(request, key, tss_entry); - - free(key); } + free(key); free(iter); /* apply overrides */ @@ -1193,18 +1163,18 @@ int tss_request_add_se_tags(plist_t request, plist_t parameters, plist_t overrid plist_dict_iter iter = NULL; plist_dict_new_iter(manifest_node, &iter); while (1) { + free(key); key = NULL; plist_dict_next_item(manifest_node, iter, &key, &manifest_entry); if (key == NULL) break; if (!manifest_entry || plist_get_node_type(manifest_entry) != PLIST_DICT) { - free(key); error("ERROR: Unable to fetch BuildManifest entry\n"); + free(key); return -1; } if (strncmp(key, "SE,", 3)) { - free(key); continue; } @@ -1229,9 +1199,8 @@ int tss_request_add_se_tags(plist_t request, plist_t parameters, plist_t overrid /* add entry to request */ plist_dict_set_item(request, key, tss_entry); - - free(key); } + free(key); free(iter); /* apply overrides */ -- cgit v1.1-32-gdbae