ttls: Fix a crash on invalid cert in non-interactive mode - sacc - sacc (saccomys): simple gopher client.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 5b9bcbd0dcf3cf2c4edb995621de245ce6b80a9d
 (DIR) parent 4003310026b26f9c81b44fb07686e7301064c4bf
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Wed, 18 Jan 2023 23:52:32 +0100
       
       ttls: Fix a crash on invalid cert in non-interactive mode
       
       This is because uiprompt() cannot be used in non-interactive.
       
       To reproduce:
       
       Put a different certificate in ~/.share/sacc/cert/bitreich.org
       Then run:
       
               sacc gophers://bitreich.org > /tmp/plop
       
       Diffstat:
         M common.h                            |       2 ++
         M io_tls.c                            |       5 +++++
         M sacc.c                              |       2 +-
       
       3 files changed, 8 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/common.h b/common.h
       t@@ -23,6 +23,8 @@ struct dir {
                size_t curline;
        };
        
       +extern int interactive;
       +
        extern void (*diag)(char *, ...);
        
        extern void die(const char *, ...);
 (DIR) diff --git a/io_tls.c b/io_tls.c
       t@@ -210,6 +210,11 @@ connect_tls(struct cnx *c, struct addrinfo *ai, const char *host)
                        diag("Can't establish TLS with \"%s\": %s",
                             host, tls_error(t));
        
       +                if (!interactive) {
       +                        r = CONN_ABORT;
       +                        goto end;
       +                }
       +
                        if (pem.cert) {
                                s = uiprompt("Save certificate locally and retry? [yN]: ");
                                switch (*s) {
 (DIR) diff --git a/sacc.c b/sacc.c
       t@@ -49,6 +49,7 @@ enum {
        
        void (*diag)(char *, ...);
        
       +int interactive;
        const char ident[] = "@(#) sacc(omys): " VERSION;
        
        static char intbuf[256]; /* 256B ought to be enough for any URI */
       t@@ -56,7 +57,6 @@ static char *mainurl;
        static Item *mainentry;
        static int devnullfd;
        static int parent = 1;
       -static int interactive;
        
        static void
        stddiag(char *fmt, ...)