From b416b15eb246444a30ed5fdea79f45dfe8cc4eab Mon Sep 17 00:00:00 2001
From: Patrick McDermott <patrick.mcdermott@libiquity.com>
Date: Wed, 03 May 2023 02:38:41 -0400
Subject: opk/read: Separate error handling

Only free member if opkg_opk_ustar_list() succeeds.
---
(limited to 'src')

diff --git a/src/opk/read.c b/src/opk/read.c
index a076dae..97187dc 100644
--- a/src/opk/read.c
+++ b/src/opk/read.c
@@ -493,8 +493,13 @@ opkg_opk_opk_read(struct opkg_opk_opk *opk, const char *file_name)
 	}
 
 	/* Check package version. */
-	if (opkg_opk_ustar_list(opk->outer_ustar, &member) != OPKG_OPK_OK ||
-			strcmp(member->name, "debian-binary") != 0) {
+	if (opkg_opk_ustar_list(opk->outer_ustar, &member) != OPKG_OPK_OK) {
+		fputs(_("Error: Failed to find \"debian-binary\" in archive\n"),
+				stderr);
+		ret = OPKG_OPK_ERROR;
+		goto out3;
+	}
+	if (strcmp(member->name, "debian-binary") != 0) {
 		free(member);
 		fputs(_("Error: Failed to find \"debian-binary\" in archive\n"),
 				stderr);
@@ -510,16 +515,19 @@ opkg_opk_opk_read(struct opkg_opk_opk *opk, const char *file_name)
 		ret = OPKG_OPK_ERROR;
 		goto out3;
 	}
-	if (version_size < 4 || strncmp(version_buffer, "2.", 2) != 0)
-	{
+	if (version_size < 4 || strncmp(version_buffer, "2.", 2) != 0) {
 		fputs(_("Error: Unsupported package version\n"), stderr);
 		ret = OPKG_OPK_ERROR;
 		goto out3;
 	}
 
 	/* Read control archive. */
-	if (opkg_opk_ustar_list(opk->outer_ustar, &member) != OPKG_OPK_OK ||
-			strcmp(member->name, "control.tar.gz") != 0) {
+	if (opkg_opk_ustar_list(opk->outer_ustar, &member) != OPKG_OPK_OK) {
+		fputs(_("Error: Failed to find \"control.tar.gz\" in archive\n")
+				, stderr);
+		return OPKG_OPK_ERROR;
+	}
+	if (strcmp(member->name, "control.tar.gz") != 0) {
 		free(member);
 		fputs(_("Error: Failed to find \"control.tar.gz\" in archive\n")
 				, stderr);
@@ -532,8 +540,12 @@ opkg_opk_opk_read(struct opkg_opk_opk *opk, const char *file_name)
 	}
 
 	/* Read data archive. */
-	if (opkg_opk_ustar_list(opk->outer_ustar, &member) != OPKG_OPK_OK ||
-			strcmp(member->name, "data.tar.gz") != 0) {
+	if (opkg_opk_ustar_list(opk->outer_ustar, &member) != OPKG_OPK_OK) {
+		fputs(_("Error: Failed to find \"data.tar.gz\" in archive\n"),
+				stderr);
+		return OPKG_OPK_ERROR;
+	}
+	if (strcmp(member->name, "data.tar.gz") != 0) {
 		free(member);
 		fputs(_("Error: Failed to find \"data.tar.gz\" in archive\n"),
 				stderr);
--
cgit v0.9.1