diff options
author | Omar Polo <op@omarpolo.com> | 2023-07-22 15:47:07 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2023-07-22 15:47:07 +0000 |
commit | 800aa93c05250a0482e1767897cb80e3b52f0d07 (patch) | |
tree | aa56d57c5d639fddc611d2e2cc07c4a33aaeeb47 /gg.c | |
parent | 2ff1e2a9237514d5d473b2b3562ec767542b55bc (diff) |
gg: warn when the TLS layer is not closed properly
various servers are not handling correctly the close notify so for
the moment don't turn this into an hard error but just warn.
Hopefully, given some time, most servers will be fixed.
while here, drop the gotos and just use a break to exit the main
loop.
Diffstat (limited to 'gg.c')
-rw-r--r-- | gg.c | 29 |
1 files changed, 17 insertions, 12 deletions
@@ -239,7 +239,7 @@ get(const char *r) len = dorep(ctx, buf, sizeof(buf)); if (len == 0) - goto close; + break; if (foundhdr) { write(1, buf, len); @@ -258,7 +258,7 @@ get(const char *r) if (debug == DEBUG_CODE) { printf("%d\n", code); - goto close; + break; } if (debug == DEBUG_HEADER) { @@ -266,7 +266,7 @@ get(const char *r) assert(t != NULL); *t = '\0'; printf("%s\n", buf); - goto close; + break; } if (debug == DEBUG_META) { @@ -274,7 +274,7 @@ get(const char *r) assert(t != NULL); *t = '\0'; printf("%s\n", buf+3); - goto close; + break; } if (debug == DEBUG_ALL) { @@ -290,14 +290,19 @@ get(const char *r) write(1, t, len); } -close: - od = tls_close(ctx); - if (od == TLS_WANT_POLLIN || od == TLS_WANT_POLLOUT) - goto close; - - tls_close(ctx); - tls_free(ctx); - return code; + for (;;) { + switch (tls_close(ctx)) { + case TLS_WANT_POLLIN: + case TLS_WANT_POLLOUT: + continue; + case -1: + warnx("tls_close: %s", tls_error(ctx)); + /* fallthrough */ + default: + tls_free(ctx); + return code; + } + } } static void __attribute__((noreturn)) |