gpg-interface: handle bool user.signingkey
authorJeff King <peff@peff.net>
Fri, 13 Apr 2018 21:18:30 +0000 (15:18 -0600)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Apr 2018 05:15:02 +0000 (14:15 +0900)
The config handler for user.signingkey does not check for a
boolean value, and thus:

git -c user.signingkey tag

will segfault. We could fix this and even shorten the code
by using git_config_string(). But our set_signing_key()
helper is used by other code outside of gpg-interface.c, so
we must keep it (and we may as well use it, because unlike
git_config_string() it does not leak when we overwrite an
old value).

Ironically, the handler for gpg.program just below _could_
use git_config_string() but doesn't. But since we're going
to touch that in a future patch, we'll leave it alone for
now. We will add some whitespace and returns in preparation
for adding more config keys, though.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Ben Toews <mastahyeti@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gpg-interface.c
index 4feacf16e5bcd93dcde4a2ea769f6b61ca369593..61c0690e12245c2db62f3a807ce0aaf8b3282ba9 100644 (file)
@@ -128,13 +128,19 @@ void set_signing_key(const char *key)
 int git_gpg_config(const char *var, const char *value, void *cb)
 {
        if (!strcmp(var, "user.signingkey")) {
+               if (!value)
+                       return config_error_nonbool(var);
                set_signing_key(value);
+               return 0;
        }
+
        if (!strcmp(var, "gpg.program")) {
                if (!value)
                        return config_error_nonbool(var);
                gpg_program = xstrdup(value);
+               return 0;
        }
+
        return 0;
 }