From ea40fb5a534d6e78d403140307b48f966e3d0719 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sat, 7 Nov 2020 10:57:36 -0800 Subject: [PATCH] tls: fix crash when opening priv key for writing The open syscall will return a negative value if the call fails. Switch the check to look for this instead of 0. before: [gmnisrv] generating certificate for localhost gmnisrv: src/tls.c:68: tls_host_gencert: Assertion `pf' failed. abort (core dumped) ./gmnisrv -C config.ini after: [gmnisrv] generating certificate for localhost [gmnisrv] opening private key for writing failed: No such file or directory [gmnisrv] TLS initialization failed Signed-off-by: William Casarin --- src/tls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tls.c b/src/tls.c index ca8a307..f7ed344 100644 --- a/src/tls.c +++ b/src/tls.c @@ -58,7 +58,7 @@ tls_host_gencert(struct gmnisrv_tls *tlsconf, struct gmnisrv_host *host, assert(r); int pfd = open(keypath, O_CREAT | O_WRONLY, 0600); - if (!pfd) { + if (pfd < 0) { server_error("opening private key for writing failed: %s", strerror(errno)); return 1;