Module Name:    src
Committed By:   khorben
Date:           Mon Mar 27 20:50:19 UTC 2017

Modified Files:
        src/crypto/external/bsd/netpgp/dist/src/lib: reader.c

Log Message:
Do not truncate pass-phrases without a newline character

This also fixes a crash when the pass-phrase entered is empty.

Submitted on tech-pkg@ as:
[PATCH 02/11] Do not truncate pass-phrases without a newline character

Only modified for consistency with the coding style.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 \
    src/crypto/external/bsd/netpgp/dist/src/lib/reader.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/netpgp/dist/src/lib/reader.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/reader.c:1.51 src/crypto/external/bsd/netpgp/dist/src/lib/reader.c:1.52
--- src/crypto/external/bsd/netpgp/dist/src/lib/reader.c:1.51	Fri Feb 24 01:27:14 2017
+++ src/crypto/external/bsd/netpgp/dist/src/lib/reader.c	Mon Mar 27 20:50:19 2017
@@ -54,7 +54,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: reader.c,v 1.51 2017/02/24 01:27:14 khorben Exp $");
+__RCSID("$NetBSD: reader.c,v 1.52 2017/03/27 20:50:19 khorben Exp $");
 #endif
 
 #include <sys/types.h>
@@ -160,6 +160,7 @@ int
 pgp_getpassphrase(void *in, char *phrase, size_t size)
 {
 	char	*p;
+	size_t	 len;
 
 	if (in == NULL) {
 		while ((p = getpass("netpgp passphrase: ")) == NULL) {
@@ -169,7 +170,10 @@ pgp_getpassphrase(void *in, char *phrase
 		if (fgets(phrase, (int)size, in) == NULL) {
 			return 0;
 		}
-		phrase[strlen(phrase) - 1] = 0x0;
+		len = strlen(phrase);
+		if (len >= 1 && phrase[len - 1] == '\n') {
+			phrase[len - 1] = '\0';
+		}
 	}
 	return 1;
 }

Reply via email to