commit 5b9bcbd0dcf3cf2c4edb995621de245ce6b80a9d Hiltjo Posthuma <hiltjo@codemadness.org> 2023-01-18 23:52:32 +0100 tls: 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
common.h | 2 ++ io_tls.c | 5 +++++ sacc.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/common.h b/common.h index 09dc7ea..cbfc242 100644 --- a/common.h +++ b/common.h @@ -23,6 +23,8 @@ struct dir { size_t curline; }; +extern int interactive; + extern void (*diag)(char *, ...); extern void die(const char *, ...); diff --git a/io_tls.c b/io_tls.c index eea1015..cd71fc7 100644 --- a/io_tls.c +++ b/io_tls.c @@ -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) { diff --git a/sacc.c b/sacc.c index e76c42d..5116486 100644 --- a/sacc.c +++ b/sacc.c @@ -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 */ @@ -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, ...)