chiark / gitweb /
Import gnupg2_2.1.18-8~deb9u1.debian.tar.bz2
[gnupg2.git] / patches / 0025-gpg-Don-t-assume-that-strtoul-interprets-as-0.patch
1 From: "Neal H. Walfield" <neal@g10code.com>
2 Date: Thu, 2 Feb 2017 15:48:45 +0100
3 Subject: gpg: Don't assume that strtoul interprets "" as 0.
4
5 * g10/tofu.c (show_statistics): If there are not records, return 0
6 instead of NULL.
7
8 --
9 Signed-off-by: Neal H. Walfield <neal@g10code.com>
10 GnuPG-bug-id: 2853
11
12 According to SUSv3:
13
14   If the subject sequence is empty or does not have the expected form,
15   no conversion is performed
16   ...
17   If no conversion could be performed, 0 is returned and errno may be
18   set to [EINVAL].
19
20   http://pubs.opengroup.org/onlinepubs/007908799/xsh/strtol.html
21
22 It appears that MacOS X sets errno to EINVAL, but glibc doesn't.
23 Hence, we map NULL to 0 explicitly.
24
25 (cherry picked from commit 407f5f9baea5591f148974240a87dfb43e5efef3)
26 ---
27  g10/tofu.c | 6 ++++--
28  1 file changed, 4 insertions(+), 2 deletions(-)
29
30 diff --git a/g10/tofu.c b/g10/tofu.c
31 index 85347bb74..449e921b6 100644
32 --- a/g10/tofu.c
33 +++ b/g10/tofu.c
34 @@ -2983,7 +2983,8 @@ show_statistics (tofu_dbs_t dbs,
35    /* Get the signature stats.  */
36    rc = gpgsql_exec_printf
37      (dbs->db, strings_collect_cb, &strlist, &err,
38 -     "select count (*), min (signatures.time), max (signatures.time)\n"
39 +     "select count (*), coalesce (min (signatures.time), 0),\n"
40 +     "  coalesce (max (signatures.time), 0)\n"
41       " from signatures\n"
42       " left join bindings on signatures.binding = bindings.oid\n"
43       " where fingerprint = %Q and email = %Q;",
44 @@ -3036,7 +3037,8 @@ show_statistics (tofu_dbs_t dbs,
45    /* Get the encryption stats.  */
46    rc = gpgsql_exec_printf
47      (dbs->db, strings_collect_cb, &strlist, &err,
48 -     "select count (*), min (encryptions.time), max (encryptions.time)\n"
49 +     "select count (*), coalesce (min (encryptions.time), 0),\n"
50 +     "  coalesce (max (encryptions.time), 0)\n"
51       " from encryptions\n"
52       " left join bindings on encryptions.binding = bindings.oid\n"
53       " where fingerprint = %Q and email = %Q;",