[git] GnuPG - branch, master, updated. gnupg-2.1.15-328-g70215ff

by Justus Winter cvs at cvs.gnupg.org
Mon Nov 7 13:31:59 CET 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  70215ff470c82d144e872057dfa5a478cc9195f2 (commit)
       via  413cc50345557e0a516f33b98e8aab19bbc8b4fe (commit)
       via  6e677f9b55fdb610e93134042ee41ee5c641cbdf (commit)
       via  5840353d8bbcd9e75374f3bdb2547ffa7bbea897 (commit)
      from  4d7dc432b598d7d28d6caba78a94d12034134b96 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 70215ff470c82d144e872057dfa5a478cc9195f2
Author: Justus Winter <justus at g10code.com>
Date:   Mon Nov 7 12:28:07 2016 +0100

    tests,tools: Reimplement 'mk-tdata' in Scheme.
    
    * tests/openpgp/defs.scm (tools): Drop 'mk-tdata'.
    * tests/openpgp/setup.scm (make-test-data): New function.
    * tests/openpgp/verify.scm: Avoid 'mk-tdata'.
    * tools/Makefile.am (noinst_PROGRAMS): Drop 'mk-tdata'.
    * tools/mk-tdata.c: Drop file.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tests/openpgp/defs.scm b/tests/openpgp/defs.scm
index c911ea3..62bd1e2 100644
--- a/tests/openpgp/defs.scm
+++ b/tests/openpgp/defs.scm
@@ -59,7 +59,6 @@
     (gpgconf "GPGCONF" "tools/gpgconf")
     (gpg-preset-passphrase "GPG_PRESET_PASSPHRASE"
 			   "agent/gpg-preset-passphrase")
-    (mktdata "MKTDATA" "tools/mk-tdata")
     (gpgtar "GPGTAR" "tools/gpgtar")
     (gpg-zip "GPGZIP" "tools/gpg-zip")
     (pinentry "PINENTRY" "tests/openpgp/fake-pinentry")))
diff --git a/tests/openpgp/setup.scm b/tests/openpgp/setup.scm
index 99fbdea..d3ce0d6 100755
--- a/tests/openpgp/setup.scm
+++ b/tests/openpgp/setup.scm
@@ -19,11 +19,17 @@
 
 (load (with-path "defs.scm"))
 
+(define (make-test-data filename size)
+  (call-with-binary-output-file
+   filename
+   (lambda (port)
+     (display (make-random-string size) port))))
+
 (define (create-gpghome)
   (echo "Creating test environment...")
 
-  (letfd ((fd (open "random_seed" (logior O_WRONLY O_CREAT O_BINARY) #o600)))
-	 (call-with-fds (list (tool 'mktdata) "600") CLOSED_FD fd STDERR_FILENO))
+  (srandom (getpid))
+  (make-test-data "random_seed" 600)
 
   (for-each-p
    "Creating configuration files"
@@ -44,10 +50,8 @@
 
   (for-each-p "Creating sample data files"
 	      (lambda (size)
-		(letfd ((fd (open (string-append "data-" (number->string size))
-				  (logior O_WRONLY O_CREAT O_BINARY) #o600)))
-		       (call-with-fds (list (tool 'mktdata) (number->string size))
-				      CLOSED_FD fd STDERR_FILENO)))
+		(make-test-data (string-append "data-" (number->string size))
+				size))
 	      '(500 9000 32000 80000))
 
   (for-each-p "Unpacking samples"
diff --git a/tests/openpgp/verify.scm b/tests/openpgp/verify.scm
index e8aa7df..eb984b1 100755
--- a/tests/openpgp/verify.scm
+++ b/tests/openpgp/verify.scm
@@ -26,12 +26,14 @@
  "Checking bogus signature"
  (lambda (char)
    (lettmp (x)
-     (pipe:do
-      (pipe:spawn `(,(tool 'mktdata) --char ,char "64"))
-      (pipe:write-to x (logior O_WRONLY O_CREAT O_BINARY) #o600))
+     (call-with-binary-output-file
+      x
+      (lambda (port)
+	(display (make-string 64 (integer->char (string->number char)))
+		 port)))
      (if (= 0 (call `(, at GPG --verify ,x data-500)))
 	 (error "no error code from verify"))))
- '("0x2d" "0xca"))
+ '("#x2d" "#xca"))
 
 ;; A plain signed message created using
 ;;  echo abc | gpg --homedir . --passphrase-fd 0 -u Alpha -z0 -sa msg
diff --git a/tools/Makefile.am b/tools/Makefile.am
index c07a8b1..75750f7 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -66,7 +66,7 @@ libexec_PROGRAMS += gpg-check-pattern
 endif
 
 if !HAVE_W32CE_SYSTEM
-noinst_PROGRAMS = clean-sat mk-tdata make-dns-cert gpgsplit
+noinst_PROGRAMS = clean-sat make-dns-cert gpgsplit
 endif
 
 if !HAVE_W32CE_SYSTEM
diff --git a/tools/mk-tdata.c b/tools/mk-tdata.c
deleted file mode 100644
index 0aca035..0000000
--- a/tools/mk-tdata.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* mk-tdata.c -  Create some simple random testdata
- * Copyright (C) 1998, 1999, 2000, 2001, 2006 Free Software Foundation, Inc.
- *
- * This file is free software; as a special exception the author gives
- * unlimited permission to copy and/or distribute it, with or without
- * modifications, as long as this notice is preserved.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-
-#ifndef RAND_MAX   /* for SunOS */
-#define RAND_MAX 32767
-#endif
-
-int
-main(int argc, char **argv)
-{
-  int i, c = 0;
-  int limit =0;
-  int char_mode = 0;
-
-#if HAVE_W32_SYSTEM
-  if (setmode (fileno (stdout), O_BINARY) == -1)
-    perror ("setmode");
-#endif
-
-  if (argc)
-    {
-      argc--;
-      argv++;
-    }
-
-  /* Check for option --char N */
-  if (argc > 1 && !strcmp (argv[0], "--char"))
-    {
-      char_mode = 1;
-      c = strtol (argv[1], NULL, 0);
-      argc -= 2;
-      argv += 2;
-    }
-
-  limit = argc ? atoi(argv[0]) : 0;
-
-  srand(getpid());
-
-  for (i=0; !limit || i < limit; i++ )
-    {
-      if (char_mode)
-        {
-          putchar (c);
-        }
-      else
-        {
-#ifdef HAVE_RAND
-          c = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1);
-#else
-          c = ((unsigned)(1 + (int) (256.0*random()/(RAND_MAX+1.0)))-1);
-#endif
-          putchar (c);
-        }
-    }
-  return 0;
-}

commit 413cc50345557e0a516f33b98e8aab19bbc8b4fe
Author: Justus Winter <justus at g10code.com>
Date:   Mon Nov 7 13:12:01 2016 +0100

    gpgscm,w32: Provide schemish file handling for binary files.
    
    * tests/gpgscm/lib.scm (call-with-binary-input-file): New function.
    (call-with-binary-output-file): Likewise.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tests/gpgscm/lib.scm b/tests/gpgscm/lib.scm
index 270189d..a8ae2f8 100644
--- a/tests/gpgscm/lib.scm
+++ b/tests/gpgscm/lib.scm
@@ -187,6 +187,20 @@
 	(loop acc))))))
 
 ;;
+;; Windows support.
+;;
+
+;; Like call-with-input-file but opens the file in 'binary' mode.
+(define (call-with-binary-input-file filename proc)
+  (letfd ((fd (open filename (logior O_RDONLY O_BINARY))))
+	 (proc (fdopen fd "rb"))))
+
+;; Like call-with-output-file but opens the file in 'binary' mode.
+(define (call-with-binary-output-file filename proc)
+  (letfd ((fd (open filename (logior O_WRONLY O_CREAT O_BINARY) #o600)))
+	 (proc (fdopen fd "wb"))))
+
+;;
 ;; Libc functions.
 ;;
 

commit 6e677f9b55fdb610e93134042ee41ee5c641cbdf
Author: Justus Winter <justus at g10code.com>
Date:   Mon Nov 7 12:21:26 2016 +0100

    gpgscm: Add support for pseudo-random numbers.
    
    * tests/gpgscm/ffi.c (do_getpid): New function.
    (do_srandom): Likewise.
    (random_scaled): Likewise.
    (do_random): Likewise.
    (do_make_random_string): Likewise.
    (ffi_init): Expose the new functions.
    * tests/gpgscm/lib.scm: Document the new functions.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tests/gpgscm/ffi.c b/tests/gpgscm/ffi.c
index 49aeb97..8bb2652 100644
--- a/tests/gpgscm/ffi.c
+++ b/tests/gpgscm/ffi.c
@@ -472,6 +472,73 @@ do_get_isotime (scheme *sc, pointer args)
   FFI_RETURN_STRING (sc, timebuf);
 }
 
+static pointer
+do_getpid (scheme *sc, pointer args)
+{
+  FFI_PROLOG ();
+  FFI_ARGS_DONE_OR_RETURN (sc, args);
+  FFI_RETURN_INT (sc, getpid ());
+}
+
+static pointer
+do_srandom (scheme *sc, pointer args)
+{
+  FFI_PROLOG ();
+  int seed;
+  FFI_ARG_OR_RETURN (sc, int, seed, number, args);
+  FFI_ARGS_DONE_OR_RETURN (sc, args);
+  srand (seed);
+  FFI_RETURN (sc);
+}
+
+static int
+random_scaled (int scale)
+{
+  int v;
+#ifdef HAVE_RAND
+  v = rand ();
+#else
+  v = random ();
+#endif
+
+#ifndef RAND_MAX   /* for SunOS */
+#define RAND_MAX 32767
+#endif
+
+  return ((int) (1 + (int) ((float) scale * v / (RAND_MAX + 1.0))) - 1);
+}
+
+static pointer
+do_random (scheme *sc, pointer args)
+{
+  FFI_PROLOG ();
+  int scale;
+  FFI_ARG_OR_RETURN (sc, int, scale, number, args);
+  FFI_ARGS_DONE_OR_RETURN (sc, args);
+  FFI_RETURN_INT (sc, random_scaled (scale));
+}
+
+static pointer
+do_make_random_string (scheme *sc, pointer args)
+{
+  FFI_PROLOG ();
+  int size;
+  pointer chunk;
+  char *p;
+  FFI_ARG_OR_RETURN (sc, int, size, number, args);
+  FFI_ARGS_DONE_OR_RETURN (sc, args);
+  if (size < 0)
+    return ffi_sprintf (sc, "size must be positive");
+
+  chunk = sc->vptr->mk_counted_string (sc, NULL, size);
+  if (sc->no_memory)
+    FFI_RETURN_ERR (sc, ENOMEM);
+
+  for (p = sc->vptr->string_value (chunk); size; p++, size--)
+    *p = (char) random_scaled (256);
+  FFI_RETURN_POINTER (sc, chunk);
+}
+
 

 
 /* estream functions.  */
@@ -1233,6 +1300,12 @@ ffi_init (scheme *sc, const char *argv0, const char *scriptname,
   ffi_define_function (sc, mkdir);
   ffi_define_function (sc, rmdir);
   ffi_define_function (sc, get_isotime);
+  ffi_define_function (sc, getpid);
+
+  /* Random numbers.  */
+  ffi_define_function (sc, srandom);
+  ffi_define_function (sc, random);
+  ffi_define_function (sc, make_random_string);
 
   /* Process management.  */
   ffi_define_function (sc, spawn_process);
diff --git a/tests/gpgscm/lib.scm b/tests/gpgscm/lib.scm
index 316eacf..270189d 100644
--- a/tests/gpgscm/lib.scm
+++ b/tests/gpgscm/lib.scm
@@ -185,3 +185,24 @@
        (else
 	(write-char (apply read-char p) acc)
 	(loop acc))))))
+
+;;
+;; Libc functions.
+;;
+
+;; Get our process id.
+(ffi-define (getpid))
+
+;;
+;; Random numbers.
+;;
+
+;; Seed the random number generator.
+(ffi-define (srandom seed))
+
+;; Get a pseudo-random number between 0 (inclusive) and SCALE
+;; (exclusive).
+(ffi-define (random scale))
+
+;; Create a string of the given SIZE containing pseudo-random data.
+(ffi-define (make-random-string size))

commit 5840353d8bbcd9e75374f3bdb2547ffa7bbea897
Author: Justus Winter <justus at g10code.com>
Date:   Mon Nov 7 12:53:17 2016 +0100

    g10: Fix crash.
    
    * g10/getkey.c (get_best_pubkey_byname): If 'get_pubkey_byname' does
    not return a getkey context, then it can return at most one key,
    therefore there is nothing to rank.  Also, always initialize '*retctx'
    to be on the safe side.
    
    GnuPG-bug-id: 2828
    Fixes: ab89164be02012f1bf159c971853b8610e966301
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/g10/getkey.c b/g10/getkey.c
index 648c230..59625e7 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -1577,18 +1577,19 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
   int rc;
   struct getkey_ctx_s *ctx = NULL;
 
+  if (retctx)
+    *retctx = NULL;
+
   rc = get_pubkey_byname (ctrl, &ctx, pk, name, ret_keyblock,
                           NULL, include_unusable, no_akl);
   if (rc)
     {
       if (ctx)
         getkey_end (ctx);
-      if (retctx)
-        *retctx = NULL;
       return rc;
     }
 
-  if (is_valid_mailbox (name))
+  if (is_valid_mailbox (name) && ctx)
     {
       /* Rank results and return only the most relevant key.  */
       struct pubkey_cmp_cookie best = { 0 }, new;

-----------------------------------------------------------------------

Summary of changes:
 g10/getkey.c             |  7 +++--
 tests/gpgscm/ffi.c       | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/gpgscm/lib.scm     | 35 ++++++++++++++++++++++
 tests/openpgp/defs.scm   |  1 -
 tests/openpgp/setup.scm  | 16 +++++++----
 tests/openpgp/verify.scm | 10 ++++---
 tools/Makefile.am        |  2 +-
 tools/mk-tdata.c         | 75 ------------------------------------------------
 8 files changed, 129 insertions(+), 90 deletions(-)
 delete mode 100644 tools/mk-tdata.c


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list