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.
5 * g10/tofu.c (show_statistics): If there are not records, return 0
9 Signed-off-by: Neal H. Walfield <neal@g10code.com>
14 If the subject sequence is empty or does not have the expected form,
15 no conversion is performed
17 If no conversion could be performed, 0 is returned and errno may be
20 http://pubs.opengroup.org/onlinepubs/007908799/xsh/strtol.html
22 It appears that MacOS X sets errno to EINVAL, but glibc doesn't.
23 Hence, we map NULL to 0 explicitly.
25 (cherry picked from commit 407f5f9baea5591f148974240a87dfb43e5efef3)
28 1 file changed, 4 insertions(+), 2 deletions(-)
30 diff --git a/g10/tofu.c b/g10/tofu.c
31 index 85347bb74..449e921b6 100644
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"
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"
52 " left join bindings on encryptions.binding = bindings.oid\n"
53 " where fingerprint = %Q and email = %Q;",