Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg repo signing_command: Detect if the command fails and fail early
Bryan Drewery committed 12 years ago
commit 2bd04a40756f98c63a9de1796faa84f60e54a1c0
parent 772d332
1 file changed +11 -6
modified libpkg/pkg_repo.c
@@ -40,6 +40,7 @@
#define _WITH_GETLINE
#include <stdio.h>
#include <stdbool.h>
+
#include <sysexits.h>
#include <unistd.h>

#include "pkg.h"
@@ -451,7 +452,7 @@ cmd_sign(char *path, char **argv, int argc, struct sbuf **sig, struct sbuf **cer
	char *line = NULL;
	size_t linecap = 0;
	ssize_t linelen;
-
	int i;
+
	int i, ret = EPKG_OK;

	if (sha256_file(path, sha256) != EPKG_OK)
		return (EPKG_FATAL);
@@ -467,8 +468,8 @@ cmd_sign(char *path, char **argv, int argc, struct sbuf **sig, struct sbuf **cer
	sbuf_done(cmd);

	if ((fp = popen(sbuf_data(cmd), "r+")) == NULL) {
-
		sbuf_delete(cmd);
-
		return (EPKG_FATAL);
+
		ret = EPKG_FATAL;
+
		goto done;
	}

	fprintf(fp, "%s\n", sha256);
@@ -492,6 +493,11 @@ cmd_sign(char *path, char **argv, int argc, struct sbuf **sig, struct sbuf **cer
			sbuf_bcat(buf, line, linelen);
	}

+
	if (pclose(fp) != EX_OK) {
+
		ret = EPKG_FATAL;
+
		goto done;
+
	}
+

	if (sbuf_data(*sig)[sbuf_len(*sig) -1 ] == '\n')
		sbuf_setpos(*sig, sbuf_len(*sig) -1);
	if (sbuf_data(*cert)[sbuf_len(*cert) -1 ] == '\n')
@@ -499,12 +505,11 @@ cmd_sign(char *path, char **argv, int argc, struct sbuf **sig, struct sbuf **cer

	sbuf_finish(*sig);
	sbuf_finish(*cert);
-

+
done:
	if (cmd)
		sbuf_delete(cmd);
-
	pclose(fp);

-
	return (EPKG_OK);
+
	return (ret);
}

static int