Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/lib Use a regular expres...



details:   https://anonhg.NetBSD.org/src/rev/6bac1b4f4add
branches:  trunk
changeset: 758772:6bac1b4f4add
user:      agc <agc%NetBSD.org@localhost>
date:      Mon Nov 15 08:27:40 2010 +0000

description:
Use a regular expression to match the various ASCII-armoured headers we
may encounter - fixes PR 44074 from Peter Pentchev in a different way.

diffstat:

 crypto/external/bsd/netpgp/dist/src/lib/netpgp.c |  17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diffs (56 lines):

diff -r 7dbbddf455e6 -r 6bac1b4f4add crypto/external/bsd/netpgp/dist/src/lib/netpgp.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c  Mon Nov 15 08:03:39 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c  Mon Nov 15 08:27:40 2010 +0000
@@ -34,7 +34,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: netpgp.c,v 1.83 2010/11/15 08:03:39 agc Exp $");
+__RCSID("$NetBSD: netpgp.c,v 1.84 2010/11/15 08:27:40 agc Exp $");
 #endif
 
 #include <sys/types.h>
@@ -462,23 +462,32 @@
 static unsigned
 isarmoured(pgp_io_t *io, const char *f, const void *memory, const char *text)
 {
+       regmatch_t       matches[10];
        unsigned         armoured;
+       regex_t          r;
        FILE            *fp;
        char             buf[BUFSIZ];
 
        armoured = 0;
+       (void) regcomp(&r, text, REG_EXTENDED);
        if (f) {
                if ((fp = fopen(f, "r")) == NULL) {
                        (void) fprintf(io->errs, "isarmoured: can't open '%s'\n", f);
+                       regfree(&r);
                        return 0;
                }
                if (fgets(buf, (int)sizeof(buf), fp) != NULL) {
-                       armoured = (strncmp(buf, text, strlen(text)) == 0);
+                       if (regexec(&r, buf, 10, matches, 0) == 0) {
+                               armoured = 1;
+                       }
                }
                (void) fclose(fp);
        } else {
-               armoured = (strncmp(memory, text, strlen(text)) == 0);
+               if (regexec(&r, memory, 10, matches, 0) == 0) {
+                       armoured = 1;
+               }
        }
+       regfree(&r);
        return armoured;
 }
 
@@ -1341,7 +1350,7 @@
        return ret;
 }
 
-#define ARMOR_SIG_HEAD "-----BEGIN PGP SIGNATURE-----\r\n"
+#define ARMOR_SIG_HEAD "-----BEGIN PGP (SIGNATURE|SIGNED MESSAGE)-----"
 
 /* verify a file */
 int



Home | Main Index | Thread Index | Old Index