From 562f0caba97e862f07c64aca733c9f32ba9f6970 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 15 Jan 2024 15:32:56 +0000 Subject: [PATCH] clean: avoid maybe-uninitialized https://github.com/warmcat/libwebsockets/issues/3049 --- lib/core-net/wol.c | 3 ++- lib/core/logs.c | 6 +++--- lib/roles/http/client/client-http.c | 28 ++++++++++++---------------- lib/roles/http/date.c | 2 +- lib/roles/http/server/server.c | 2 +- lib/system/smd/smd.c | 4 ++-- lib/tls/tls-network.c | 4 ++-- 7 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lib/core-net/wol.c b/lib/core-net/wol.c index 8edada9064..eb6f6c6f67 100644 --- a/lib/core-net/wol.c +++ b/lib/core-net/wol.c @@ -79,7 +79,8 @@ lws_wol(struct lws_context *ctx, const char *ip_or_NULL, uint8_t *mac_6_bytes) ret = 0; bail: - close(fd); + if (fd >= 0) /* coverity */ + close(fd); return ret; } diff --git a/lib/core/logs.c b/lib/core/logs.c index 269f309882..bbda17a123 100644 --- a/lib/core/logs.c +++ b/lib/core/logs.c @@ -179,11 +179,11 @@ __lws_lc_untag(struct lws_context *context, lws_lifecycle_t *lc) //grp = lws_container_of(lc->list.owner, lws_lifecycle_group_t, owner); - lws_humanize(buf, sizeof(buf), +#if defined(LWS_LOG_TAG_LIFECYCLE) + if (lws_humanize(buf, sizeof(buf), (uint64_t)lws_now_usecs() - lc->us_creation, - humanize_schema_us); + humanize_schema_us) > 0) -#if defined(LWS_LOG_TAG_LIFECYCLE) lwsl_cx_notice(context, " -- %s (%d) %s", lc->gutag, (int)lc->list.owner->count - 1, buf); #endif diff --git a/lib/roles/http/client/client-http.c b/lib/roles/http/client/client-http.c index 57397fce90..8ff602cf10 100644 --- a/lib/roles/http/client/client-http.c +++ b/lib/roles/http/client/client-http.c @@ -591,7 +591,7 @@ static const char *digest_toks[] = { "response", // 1 << 5 "opaque", // 1 << 6 "qop", // 1 << 7 - "algorithm" // 1 << 8 + "algorithm", // 1 << 8 "nc", // 1 << 9 "cnonce", // 1 << 10 "domain", // 1 << 11 @@ -1062,27 +1062,23 @@ lws_client_interpret_server_handshake(struct lws *wsi) n = atoi(p); #if defined(LWS_WITH_HTTP_DIGEST_AUTH) - if (n == 401 && lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_WWW_AUTHENTICATE)) { - if (!(wsi->stash && wsi->stash->cis[CIS_USERNAME] && - wsi->stash->cis[CIS_PASSWORD])) { - lwsl_err( - "Digest auth requested by server but no credentials provided " - "by user\n"); - return LCBA_FAILED_AUTH; - } - - if (0 != lws_http_digest_auth(wsi)) { - if (wsi) - goto bail3; - return 1; - } + if (n == 401 && lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_WWW_AUTHENTICATE)) { + if (!(wsi->stash && wsi->stash->cis[CIS_USERNAME] && + wsi->stash->cis[CIS_PASSWORD])) { + lwsl_err("Digest auth requested by server but no credentials provided by user\n"); + + return LCBA_FAILED_AUTH; + } + + if (lws_http_digest_auth(wsi)) + goto bail3; opaque = wsi->a.opaque_user_data; lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "digest_auth_step2"); wsi->a.opaque_user_data = opaque; return -1; - } + } ah = wsi->http.ah; #endif diff --git a/lib/roles/http/date.c b/lib/roles/http/date.c index 6ac42ba9cb..327ca601b1 100644 --- a/lib/roles/http/date.c +++ b/lib/roles/http/date.c @@ -150,7 +150,7 @@ lws_http_date_parse_unix(const char *b, size_t len, time_t *t) #endif #endif - return (int)*t == -1 ? -1 : 0; + return (int)(*t == -1 ? -1 : 0); } #if defined(LWS_WITH_CLIENT) diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index ff5b1255ea..e976e89d5e 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -93,7 +93,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a) int n, opt = 1, limit = 1, san = 2; lws_sockfd_type sockfd; struct lws *wsi; - int m = 0, is; + int m = 0, is = 0; #if defined(LWS_WITH_IPV6) int value = 1; #endif diff --git a/lib/system/smd/smd.c b/lib/system/smd/smd.c index f412b61817..643f7ccabf 100644 --- a/lib/system/smd/smd.c +++ b/lib/system/smd/smd.c @@ -534,9 +534,9 @@ _lws_smd_msg_deliver_peer(struct lws_context *ctx, lws_smd_peer_t *pr) msg = lws_container_of(pr->tail, lws_smd_msg_t, list); - lwsl_cx_info(ctx, "deliver cl 0x%x, len %d, refc %d, to peer %p", + lwsl_cx_info(ctx, "deliver cl 0x%x, len %d, to peer %p", (unsigned int)msg->_class, (int)msg->length, - (int)msg->refcount, pr); + pr); pr->cb(pr->opaque, msg->_class, msg->timestamp, ((uint8_t *)&msg[1]) + LWS_SMD_SS_RX_HEADER_LEN_EFF, diff --git a/lib/tls/tls-network.c b/lib/tls/tls-network.c index 4d6ab95e7a..4a1e14391e 100644 --- a/lib/tls/tls-network.c +++ b/lib/tls/tls-network.c @@ -90,8 +90,8 @@ lws_tls_check_cert_lifetime(struct lws_vhost *v) return 1; life = (ir.time - now) / (24 * 3600); - lwsl_vhost_notice(v, " vhost %s: cert expiry: %dd", v->name, - (int)life); + lwsl_vhost_notice(v, " vhost %s: cert expiry: %lldd", v->name, + (long long)life); } else lwsl_vhost_info(v, " vhost %s: no cert", v->name);