File pesign-fix-build-errors.patch of Package pesign

From 4e03c90bb48e6f9c9d9c9aed491fbcc5be684e7b Mon Sep 17 00:00:00 2001
From: Gary Ching-Pang Lin <glin@suse.com>
Date: Tue, 9 Jul 2013 12:17:31 +0800
Subject: [PATCH] Fix build errors

---
 src/daemon.c    | 36 +++++++++++++++++++++++++++++-------
 src/efikeygen.c |  3 ++-
 src/password.c  |  3 ++-
 src/pesign.c    | 10 ++++++++--
 4 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/src/daemon.c b/src/daemon.c
index b2801b9..832a0ea 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -432,7 +432,11 @@ malformed:
 		if (rc < 0) {
 err_attached:
 			pe_end(outpe);
-			ftruncate(outfd, 0);
+			if (ftruncate(outfd, 0) != 0) {
+				ctx->cms->log(ctx->cms, ctx->priority|LOG_ERR,
+					"pesignd: could not truncate output "
+					"file: %m");
+			}
 			goto finish;
 		}
 		ssize_t sigspace = calculate_signature_space(ctx->cms, outpe);
@@ -450,21 +454,34 @@ err_attached:
 				ctx->cms->num_signatures, outpe);
 		pe_end(outpe);
 	} else {
-		ftruncate(outfd, 0);
+		if (ftruncate(outfd, 0) != 0) {
+			ctx->cms->log(ctx->cms, ctx->priority|LOG_ERR,
+				"pesignd: could not truncate output "
+				"file: %m");
+		}
 		rc = generate_digest(ctx->cms, inpe, 1);
 		if (rc < 0) {
 err_detached:
-			ftruncate(outfd, 0);
+			if (ftruncate(outfd, 0) != 0) {
+				ctx->cms->log(ctx->cms, ctx->priority|LOG_ERR,
+					"pesignd: could not truncate output "
+					"file: %m");
+			}
 			goto finish;
 		}
 		rc = generate_signature(ctx->cms);
 		if (rc < 0)
 			goto err_detached;
 		rc = export_signature(ctx->cms, outfd, 0);
-		if (rc >= 0)
-			ftruncate(outfd, rc);
-		else if (rc < 0)
+		if (rc >= 0) {
+			if (ftruncate(outfd, rc) != 0) {
+				ctx->cms->log(ctx->cms, ctx->priority|LOG_ERR,
+					"pesignd: could not truncate output "
+					"file: %m");
+			}
+		} else if (rc < 0) {
 			goto err_detached;
+		}
 	}
 
 finish:
@@ -996,7 +1013,12 @@ daemonize(cms_context *cms_ctx, char *certdir, int do_fork)
 		exit(1);
 	}
 
-	chdir(homedir ? homedir : "/");
+	if (chdir(homedir ? homedir : "/") != 0) {
+		ctx.backup_cms->log(ctx.backup_cms, ctx.priority|LOG_ERR,
+			"pesignd: could not change working directory "
+			"for pesign: %m");
+		exit(1);
+	}
 
 	if (getuid() == 0) {
 		/* process is running as root, drop privileges */
diff --git a/src/efikeygen.c b/src/efikeygen.c
index ac27acc..8c3e814 100644
--- a/src/efikeygen.c
+++ b/src/efikeygen.c
@@ -330,10 +330,11 @@ populate_extensions(cms_context *cms, CERTCertificate *cert,
 {
 	CERTAttribute *attr = NULL;
 	SECOidData *oid;
+	int i;
 
 	oid = SECOID_FindOIDByTag(SEC_OID_PKCS9_EXTENSION_REQUEST);
 
-	for (int i; crq->attributes[i]; i++) {
+	for (i = 0; crq->attributes[i]; i++) {
 		attr = crq->attributes[i];
 		if (attr->attrType.len != oid->oid.len)
 			continue;
diff --git a/src/password.c b/src/password.c
index 43186df..9a9c911 100644
--- a/src/password.c
+++ b/src/password.c
@@ -76,7 +76,8 @@ static char *SEC_GetPassword(FILE *input, FILE *output, char *prompt,
 	    echoOff(infd);
 	}
 
-	fgets ( phrase, sizeof(phrase), input);
+	if (fgets(phrase, sizeof(phrase), input) == NULL)
+		phrase[0] = '\0';
 
 	if (isTTY) {
 	    fprintf(output, "\n");
diff --git a/src/pesign.c b/src/pesign.c
index 890ebfc..fe77c9d 100644
--- a/src/pesign.c
+++ b/src/pesign.c
@@ -164,9 +164,15 @@ open_output(pesign_context *ctx)
 
 	addr = pe_rawfile(ctx->inpe, &size);
 
-	ftruncate(ctx->outfd, size);
+	if (ftruncate(ctx->outfd, size) != 0) {
+		fprintf(stderr, "pesign: could not truncate output file: %m\n");
+		exit(1);
+	}
 	lseek(ctx->outfd, 0, SEEK_SET);
-	write(ctx->outfd, addr, size);
+	if (write(ctx->outfd, addr, size) != size) {
+		fprintf(stderr, "pesign: could not write output file: %m\n");
+		exit(1);
+	}
 
 	Pe_Cmd cmd = ctx->outfd == STDOUT_FILENO ? PE_C_RDWR : PE_C_RDWR_MMAP;
 	ctx->outpe = pe_begin(ctx->outfd, cmd, NULL);
-- 
1.8.1.4

openSUSE Build Service is sponsored by