diff --git a/appveyor.yml b/appveyor.yml index f8621519..25b10a5c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,8 @@ environment: matrix: + - LWS_METHOD: x64 + CMAKE_ARGS: -DCMAKE_GENERATOR_PLATFORM=x64 -DLWS_WITH_HTTP2=1 -DLWS_WITH_PLUGINS=1 -DLIBUV_INCLUDE_DIRS=C:\assets\libuv64\include -DLIBUV_LIBRARIES=C:\assets\libuv64\libuv.lib + - LWS_METHOD: lwsws CMAKE_ARGS: -DLWS_WITH_LWSWS=1 -DSQLITE3_INCLUDE_DIRS=C:\assets\sqlite3 -DSQLITE3_LIBRARIES=C:\assets\sqlite3\sqlite3.lib -DLIBUV_INCLUDE_DIRS=C:\assets\libuv\include -DLIBUV_LIBRARIES=C:\assets\libuv\libuv.lib @@ -21,6 +24,9 @@ install: - mkdir c:\assets - mkdir c:\assets\libuv - 7z x -oc:\assets\libuv win-libuv.zip + - appveyor DownloadFile https://libwebsockets.org:444/win-libuv64.zip + - mkdir c:\assets\libuv64 + - 7z x -oc:\assets\libuv64 win-libuv64.zip - appveyor DownloadFile https://libwebsockets.org:444/nsis-3.0rc1-setup.exe - cmd /c start /wait nsis-3.0rc1-setup.exe /S /D=C:\nsis - appveyor DownloadFile https://libwebsockets.org:444/sqlite-dll-win32-x86-3130000.zip diff --git a/lib/client/client-handshake.c b/lib/client/client-handshake.c index c2720d92..c07a630e 100644 --- a/lib/client/client-handshake.c +++ b/lib/client/client-handshake.c @@ -344,7 +344,7 @@ lws_client_connect_2(struct lws *wsi) goto failed; wsi->c_port = wsi->vhost->http_proxy_port; - n = send(wsi->desc.sockfd, (char *)pt->serv_buf, plen, + n = send(wsi->desc.sockfd, (char *)pt->serv_buf, (int)plen, MSG_NOSIGNAL); if (n < 0) { lwsl_debug("ERROR writing to proxy socket\n"); diff --git a/lib/client/client.c b/lib/client/client.c index 81950458..98365725 100644 --- a/lib/client/client.c +++ b/lib/client/client.c @@ -37,8 +37,7 @@ lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len) * we were accepting input but now we stopped doing so */ if (lws_is_flowcontrolled(wsi)) { - lwsl_debug("%s: caching %ld\n", __func__, - (long)len); + lwsl_debug("%s: caching %ld\n", __func__, (long)len); lws_rxflow_cache(wsi, *buf, 0, (int)len); return 0; } @@ -318,8 +317,7 @@ start_ws_handshake: /* send our request to the server */ lws_latency_pre(context, wsi); - n = lws_ssl_capable_write(wsi, (unsigned char *)sb, - (int)(p - sb)); + n = lws_ssl_capable_write(wsi, (unsigned char *)sb, (int)(p - sb)); lws_latency(context, wsi, "send lws_issue_raw", n, n == p - sb); switch (n) { @@ -809,7 +807,7 @@ lws_client_interpret_server_handshake(struct lws *wsi) } p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL); - len = strlen(p); + len = (int)strlen(p); while (pc && *pc && !okay) { if (!strncmp(pc, p, len) && @@ -966,8 +964,7 @@ check_extensions: if (ext_name[0] && lws_ext_parse_options(ext, wsi, wsi->act_ext_user[ - wsi->count_act_ext], opts, - ext_name, + wsi->count_act_ext], opts, ext_name, (int)strlen(ext_name))) { lwsl_err("%s: unable to parse user defaults '%s'", __func__, ext_name); @@ -980,7 +977,7 @@ check_extensions: */ if (a && lws_ext_parse_options(ext, wsi, wsi->act_ext_user[wsi->count_act_ext], - opts, a, c - a)) { + opts, a, lws_ptr_diff(c, a))) { lwsl_err("%s: unable to parse remote def '%s'", __func__, a); cce = "HS: EXT: failed parsing options"; @@ -1062,7 +1059,7 @@ check_accept: * size mentioned in the protocol definition. If 0 there, then * use a big default for compatibility */ - n = wsi->protocol->rx_buffer_size; + n = (int)wsi->protocol->rx_buffer_size; if (!n) n = context->pt_serv_buf_size; n += LWS_PRE; diff --git a/lib/event-libs/libuv.c b/lib/event-libs/libuv.c index e88f1cff..abacb16c 100644 --- a/lib/event-libs/libuv.c +++ b/lib/event-libs/libuv.c @@ -333,7 +333,7 @@ lws_libuv_accept(struct lws *wsi, lws_sock_file_fd_type desc) wsi->w_read.context = context; if (wsi->mode == LWSCM_RAW_FILEDESC || wsi->event_pipe) uv_poll_init(pt->io_loop_uv, &wsi->w_read.uv_watcher, - (int)desc.filefd); + (int)(long long)desc.filefd); else uv_poll_init_socket(pt->io_loop_uv, &wsi->w_read.uv_watcher, desc.sockfd); diff --git a/lib/ext/extension-permessage-deflate.c b/lib/ext/extension-permessage-deflate.c index 210d4629..d26f63af 100644 --- a/lib/ext/extension-permessage-deflate.c +++ b/lib/ext/extension-permessage-deflate.c @@ -51,7 +51,7 @@ lws_extension_pmdeflate_restrict_args(struct lws *wsi, n = wsi->context->pt_serv_buf_size; if (wsi->protocol->rx_buffer_size) - n = wsi->protocol->rx_buffer_size; + n = (int)wsi->protocol->rx_buffer_size; extra = 7; while (n >= 1 << (extra + 1)) @@ -120,7 +120,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context, n = context->pt_serv_buf_size; if (wsi->protocol->rx_buffer_size) - n = wsi->protocol->rx_buffer_size; + n = (int)wsi->protocol->rx_buffer_size; if (n < 128) { lwsl_info(" permessage-deflate requires the protocol (%s) to have an RX buffer >= 128\n", @@ -302,7 +302,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context, priv->rx_held_valid = 1; } - eff_buf->token_len = (char *)priv->rx.next_out - eff_buf->token; + eff_buf->token_len = lws_ptr_diff(priv->rx.next_out, eff_buf->token); priv->count_rx_between_fin += eff_buf->token_len; lwsl_ext(" %s: RX leaving with new effbuff len %d, " @@ -398,8 +398,8 @@ lws_extension_callback_pm_deflate(struct lws_context *context, } } priv->compressed_out = 1; - eff_buf->token_len = (int)(priv->tx.next_out - - (unsigned char *)eff_buf->token); + eff_buf->token_len = lws_ptr_diff(priv->tx.next_out, + eff_buf->token); /* * we must announce in our returncode now if there is more diff --git a/lib/ext/extension.c b/lib/ext/extension.c index ac282040..d4c227d2 100644 --- a/lib/ext/extension.c +++ b/lib/ext/extension.c @@ -121,7 +121,7 @@ lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, return -1; leap = LEAPS_SEEK_ARG_TERM; if (oa.start) - oa.len = in - oa.start; + oa.len = lws_ptr_diff(in, oa.start); if (len == 1) oa.len++; @@ -218,7 +218,7 @@ lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len) int ret, m, n = 0; eff_buf.token = (char *)buf; - eff_buf.token_len = len; + eff_buf.token_len = (int)len; /* * while we have original buf to spill ourselves, or extensions report @@ -294,7 +294,7 @@ lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len) ret = 0; } - return len; + return (int)len; } int diff --git a/lib/handshake.c b/lib/handshake.c index bc7609d9..94bd881f 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -82,7 +82,7 @@ lws_read(struct lws *wsi, unsigned char *buf, lws_filepos_t len) * we were accepting input but now we stopped doing so */ if (lws_is_flowcontrolled(wsi)) { - lws_rxflow_cache(wsi, buf, n, len); + lws_rxflow_cache(wsi, buf, (int)n, (int)len); return 1; } @@ -271,7 +271,7 @@ read_ok: /* Nothing more to do for now */ lwsl_info("%s: read_ok, used %ld\n", __func__, (long)(buf - oldbuf)); - return buf - oldbuf; + return lws_ptr_diff(buf, oldbuf); bail: lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS); diff --git a/lib/header.c b/lib/header.c index e2562cd6..7930e76b 100644 --- a/lib/header.c +++ b/lib/header.c @@ -196,7 +196,7 @@ lws_add_http_header_status(struct lws *wsi, unsigned int _code, if (lws_add_http_header_by_name(wsi, (const unsigned char *)headers->name, (unsigned char *)headers->value, - strlen(headers->value), p, end)) + (int)strlen(headers->value), p, end)) return 1; headers = headers->next; @@ -242,7 +242,7 @@ lws_return_http_status(struct lws *wsi, unsigned int code, &p, end)) return 1; - len = 35 + strlen(html_body) + sprintf(slen, "%d", code); + len = 35 + (int)strlen(html_body) + sprintf(slen, "%d", code); n = sprintf(slen, "%d", len); if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH, @@ -270,7 +270,7 @@ lws_return_http_status(struct lws *wsi, unsigned int code, * Solve it by writing the headers now... */ m = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS); - if (m != (int)(p - start)) + if (m != lws_ptr_diff(p, start)) return 1; /* @@ -305,7 +305,7 @@ lws_return_http_status(struct lws *wsi, unsigned int code, "

%u

%s", code, html_body); - n = (int)(p - start); + n = lws_ptr_diff(p, start); m = lws_write(wsi, start, n, LWS_WRITE_HTTP); if (m != n) diff --git a/lib/http2/hpack.c b/lib/http2/hpack.c index 707de1f1..6533bcbc 100644 --- a/lib/http2/hpack.c +++ b/lib/http2/hpack.c @@ -357,7 +357,7 @@ lws_token_from_index(struct lws *wsi, int index, const char **arg, int *len, if (index < (int)ARRAY_SIZE(static_token)) { if (arg && index < (int)ARRAY_SIZE(http2_canned)) { *arg = http2_canned[index]; - *len = strlen(http2_canned[index]); + *len = (int)strlen(http2_canned[index]); } if (hdr_len) *hdr_len = static_hdr_len[index]; @@ -1301,7 +1301,7 @@ int lws_add_http2_header_by_name(struct lws *wsi, const unsigned char *name, lwsl_header("%s: %p %s:%s\n", __func__, *p, name, value); - len = strlen((char *)name); + len = (int)strlen((char *)name); if (len) if (name[len - 1] == ':') len--; diff --git a/lib/http2/http2.c b/lib/http2/http2.c index a78e1613..da893ff6 100644 --- a/lib/http2/http2.c +++ b/lib/http2/http2.c @@ -633,7 +633,8 @@ int lws_h2_do_pps_send(struct lws *wsi) h2n->we_told_goaway = 1; n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_GOAWAY, 0, LWS_H2_STREAM_ID_MASTER, - p - &set[LWS_PRE], &set[LWS_PRE]); + lws_ptr_diff(p, &set[LWS_PRE]), + &set[LWS_PRE]); if (n != 4) { lwsl_info("send %d %d\n", n, m); goto bail; diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 91bf5173..eee82e84 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -245,7 +245,7 @@ lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p) return 1; if (p > vp && p < &vp[wsi->vhost->count_protocols]) - lws_same_vh_protocol_insert(wsi, p - vp); + lws_same_vh_protocol_insert(wsi, (int)(p - vp)); else { int n = wsi->vhost->count_protocols; int hit = 0; @@ -255,7 +255,7 @@ lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p) while (n--) { if (p->name && vp->name && !strcmp(p->name, vp->name)) { hit = 1; - lws_same_vh_protocol_insert(wsi, vp - vpo); + lws_same_vh_protocol_insert(wsi, (int)(vp - vpo)); break; } vp++; @@ -847,7 +847,7 @@ lws_close_free_wsi_final(struct lws *wsi) LWS_VISIBLE LWS_EXTERN const char * lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len) { - int n = 0, sl = strlen(name); + int n = 0, sl = (int)strlen(name); while (lws_hdr_copy_fragment(wsi, buf, len, WSI_TOKEN_HTTP_URI_ARGS, n) >= 0) { @@ -1312,7 +1312,7 @@ lws_now_secs(void) #if LWS_POSIX -LWS_VISIBLE int +LWS_VISIBLE lws_sockfd_type lws_get_socket_fd(struct lws *wsi) { if (!wsi) @@ -1471,7 +1471,7 @@ lws_set_proxy(struct lws_vhost *vhost, const char *proxy) strncpy(authstring, proxy, p - proxy); // null termination not needed on input - if (lws_b64_encode_string(authstring, (p - proxy), + if (lws_b64_encode_string(authstring, lws_ptr_diff(p, proxy), vhost->proxy_basic_auth_token, sizeof vhost->proxy_basic_auth_token) < 0) goto auth_too_long; @@ -1985,7 +1985,7 @@ lws_close_reason(struct lws *wsi, enum lws_close_status status, while (len-- && p < start + budget) *p++ = *buf++; - wsi->u.ws.close_in_ping_buffer_len = p - start; + wsi->u.ws.close_in_ping_buffer_len = lws_ptr_diff(p, start); } LWS_EXTERN int @@ -2552,7 +2552,7 @@ lws_snprintf(char *str, size_t size, const char *format, ...) va_end(ap); if (n >= (int)size) - return size; + return (int)size; return n; } diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 9c756d30..f611b387 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -4752,7 +4752,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, * * \param wsi: Websocket connection instance */ -LWS_VISIBLE LWS_EXTERN int +LWS_VISIBLE LWS_EXTERN lws_sockfd_type lws_get_socket_fd(struct lws *wsi); /** @@ -5130,6 +5130,18 @@ lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, } \ } +/** + * lws_ptr_diff(): helper to report distance between pointers as an int + * + * \param head: the pointer with the larger address + * \param tail: the pointer with the smaller address + * + * This helper gives you an int representing the number of bytes further + * forward the first pointer is compared to the second pointer. + */ +#define lws_ptr_diff(head, tail) \ + ((int)((char *)(head) - (char *)(tail))) + /** * lws_snprintf(): snprintf that truncates the returned length too * diff --git a/lib/misc/lws-ring.c b/lib/misc/lws-ring.c index 60fc7cbe..c0fbe6dd 100644 --- a/lib/misc/lws-ring.c +++ b/lib/misc/lws-ring.c @@ -30,8 +30,8 @@ lws_ring_create(size_t element_len, size_t count, if (!ring) return NULL; - ring->buflen = count * element_len; - ring->element_len = element_len; + ring->buflen = (uint32_t)(count * element_len); + ring->element_len = (uint32_t)element_len; ring->head = 0; ring->oldest_tail = 0; ring->destroy_element = destroy_element; @@ -126,7 +126,7 @@ lws_ring_next_linear_insert_range(struct lws_ring *ring, void **start, int n; /* n is how many bytes the whole fifo can take */ - n = lws_ring_get_count_free_elements(ring) * ring->element_len; + n = (int)(lws_ring_get_count_free_elements(ring) * ring->element_len); if (!n) return 1; @@ -147,7 +147,7 @@ lws_ring_next_linear_insert_range(struct lws_ring *ring, void **start, LWS_VISIBLE LWS_EXTERN void lws_ring_bump_head(struct lws_ring *ring, size_t bytes) { - ring->head = (ring->head + bytes) % ring->buflen; + ring->head = (ring->head + (uint32_t)bytes) % ring->buflen; } LWS_VISIBLE LWS_EXTERN size_t @@ -157,11 +157,11 @@ lws_ring_insert(struct lws_ring *ring, const void *src, size_t max_count) int m, n; /* n is how many bytes the whole fifo can take */ - n = lws_ring_get_count_free_elements(ring) * ring->element_len; + n = (int)(lws_ring_get_count_free_elements(ring) * ring->element_len); /* restrict n to how much we want to insert */ - if ((size_t)n > max_count * ring->element_len) - n = max_count * ring->element_len; + if ((uint32_t)n > max_count * ring->element_len) + n = (int)(max_count * ring->element_len); /* * n is legal to insert, but as an optimization we can cut the @@ -206,11 +206,11 @@ lws_ring_consume(struct lws_ring *ring, uint32_t *tail, void *dest, } /* n is how many bytes the whole fifo has for us */ - n = lws_ring_get_count_waiting_elements(ring, tail) * ring->element_len; + n = (int)(lws_ring_get_count_waiting_elements(ring, tail) * ring->element_len); /* restrict n to how much we want to insert */ if ((size_t)n > max_count * ring->element_len) - n = max_count * ring->element_len; + n = (int)(max_count * ring->element_len); if (!dest) { *tail = ((*tail) + n) % ring->buflen; diff --git a/lib/output.c b/lib/output.c index c7d9d8e3..411a1d40 100644 --- a/lib/output.c +++ b/lib/output.c @@ -64,7 +64,7 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) /* just ignore sends after we cleared the truncation buffer */ if (wsi->state == LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE && !wsi->trunc_len) - return len; + return (int)len; if (wsi->trunc_len && (buf < wsi->trunc_alloc || buf > (wsi->trunc_alloc + wsi->trunc_len + wsi->trunc_offset))) { @@ -85,7 +85,7 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) return -1; } - m = lws_ext_cb_active(wsi, LWS_EXT_CB_PACKET_TX_DO_SEND, &buf, len); + m = lws_ext_cb_active(wsi, LWS_EXT_CB_PACKET_TX_DO_SEND, &buf, (int)len); if (m < 0) return -1; if (m) /* handled */ { @@ -98,15 +98,15 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) /* limit sending */ if (wsi->protocol->tx_packet_size) - n = wsi->protocol->tx_packet_size; + n = (int)wsi->protocol->tx_packet_size; else { - n = wsi->protocol->rx_buffer_size; + n = (int)wsi->protocol->rx_buffer_size; if (!n) n = context->pt_serv_buf_size; } n += LWS_PRE + 4; if (n > len) - n = len; + n = (int)len; #if defined(LWS_WITH_ESP8266) if (wsi->pending_send_completion) { n = 0; @@ -142,7 +142,7 @@ handle_truncated_send: if (!wsi->trunc_len) { lwsl_info("***** %p partial send completed\n", wsi); /* done with it, but don't free it */ - n = real_len; + n = (int)real_len; if (wsi->state == LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE) { lwsl_info("***** %p signalling to close now\n", wsi); return -1; /* retry closing now */ @@ -176,7 +176,7 @@ handle_truncated_send: if (!wsi->trunc_alloc || real_len - n > wsi->trunc_alloc_len) { lws_free(wsi->trunc_alloc); - wsi->trunc_alloc_len = real_len - n; + wsi->trunc_alloc_len = (unsigned int)(real_len - n); wsi->trunc_alloc = lws_malloc(real_len - n, "truncated send alloc"); if (!wsi->trunc_alloc) { lwsl_err("truncated send: unable to malloc %lu\n", @@ -185,13 +185,13 @@ handle_truncated_send: } } wsi->trunc_offset = 0; - wsi->trunc_len = real_len - n; + wsi->trunc_len = (unsigned int)(real_len - n); memcpy(wsi->trunc_alloc, buf + n, real_len - n); /* since something buffered, force it to get another chance to send */ lws_callback_on_writable(wsi); - return real_len; + return (int)real_len; } LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf, size_t len, @@ -219,7 +219,7 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf, size_t len, (void *)&pas, 0)) return 1; - return len; + return (int)len; } lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_API_LWS_WRITE, 1); @@ -297,7 +297,7 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf, size_t len, * interleaving of control frames and other connection service. */ eff_buf.token = (char *)buf; - eff_buf.token_len = len; + eff_buf.token_len = (int)len; switch ((int)wp) { case LWS_WRITE_PING: @@ -353,7 +353,7 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf, size_t len, if (!wsi->u.ws.stashed_write_pending) wsi->u.ws.stashed_write_type = (char)wp & 0x3f; wsi->u.ws.stashed_write_pending = 1; - return len; + return (int)len; } /* * extension recreated it: @@ -523,7 +523,7 @@ send_raw: } return lws_h2_frame_write(wsi, n, flags, - wsi->u.h2.my_sid, len, buf); + wsi->u.h2.my_sid, (int)len, buf); } #endif return lws_issue_raw(wsi, (unsigned char *)buf - pre, len + pre); @@ -558,7 +558,7 @@ send_raw: if (n == (int)len + pre) { /* everything in the buffer was handled (or rebuffered...) */ wsi->u.ws.inside_frame = 0; - return orig_len; + return (int)orig_len; } /* @@ -685,7 +685,7 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi) if (wsi->sending_chunked) n = (int)amount; else - n = (p - pstart) + (int)amount; + n = lws_ptr_diff(p, pstart) + (int)amount; lwsl_debug("%s: sending %d\n", __func__, n); diff --git a/lib/plat/lws-plat-win.c b/lib/plat/lws-plat-win.c index 8f1ecf75..7cbb7df7 100644 --- a/lib/plat/lws-plat-win.c +++ b/lib/plat/lws-plat-win.c @@ -148,7 +148,7 @@ lws_poll_listen_fd(struct lws_pollfd *fd) FD_ZERO(&readfds); FD_SET(fd->fd, &readfds); - return select(fd->fd + 1, &readfds, NULL, NULL, &tv); + return select(((int)fd->fd) + 1, &readfds, NULL, NULL, &tv); } LWS_VISIBLE void @@ -428,7 +428,7 @@ lws_interface_to_sa(int ipv6, if (address == INADDR_NONE) return -1; - addr->sin_addr.s_addr = (lws_intptr_t)address; + addr->sin_addr.s_addr = (unsigned long)(lws_intptr_t)address; return 0; } @@ -548,7 +548,7 @@ LWS_VISIBLE int lws_plat_inet_pton(int af, const char *src, void *dst) { WCHAR *buffer; - DWORD bufferlen = strlen(src) + 1; + DWORD bufferlen = (int)strlen(src) + 1; BOOL ok = FALSE; buffer = lws_malloc(bufferlen * 2, "inet_pton"); diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 1a5b25f7..7e1df5c6 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -733,8 +733,8 @@ enum { struct lws_ring { void *buf; void (*destroy_element)(void *element); - size_t buflen; - size_t element_len; + uint32_t buflen; + uint32_t element_len; uint32_t head; uint32_t oldest_tail; }; diff --git a/lib/server/fops-zip.c b/lib/server/fops-zip.c index 1f0bf416..8b68ce21 100644 --- a/lib/server/fops-zip.c +++ b/lib/server/fops-zip.c @@ -348,7 +348,7 @@ lws_fops_zip_open(const struct lws_plat_file_ops *fops, const char *vfs_path, m = sizeof(rp) - 1; if ((vpath - vfs_path - 1) < m) - m = vpath - vfs_path - 1; + m = lws_ptr_diff(vpath, vfs_path) - 1; strncpy(rp, vfs_path, m); rp[m] = '\0'; @@ -363,7 +363,7 @@ lws_fops_zip_open(const struct lws_plat_file_ops *fops, const char *vfs_path, if (*vpath == '/') vpath++; - m = lws_fops_zip_scan(priv, vpath, strlen(vpath)); + m = lws_fops_zip_scan(priv, vpath, (int)strlen(vpath)); if (m) { lwsl_err("unable to find record matching '%s' %d\n", vpath, m); goto bail2; diff --git a/lib/server/parsers.c b/lib/server/parsers.c index b75740c6..872fda0d 100644 --- a/lib/server/parsers.c +++ b/lib/server/parsers.c @@ -1733,18 +1733,18 @@ lws_payload_until_length_exhausted(struct lws *wsi, unsigned char **buf, char *rx_ubuf; if (wsi->protocol->rx_buffer_size) - buffer_size = wsi->protocol->rx_buffer_size; + buffer_size = (int)wsi->protocol->rx_buffer_size; else buffer_size = wsi->context->pt_serv_buf_size; avail = buffer_size - wsi->u.ws.rx_ubuf_head; /* do not consume more than we should */ if (avail > wsi->u.ws.rx_packet_length) - avail = wsi->u.ws.rx_packet_length; + avail = (unsigned int)wsi->u.ws.rx_packet_length; /* do not consume more than what is in the buffer */ if (avail > *len) - avail = *len; + avail = (unsigned int)(*len); /* we want to leave 1 byte for the parser to handle properly */ if (avail <= 1) diff --git a/lib/server/server-handshake.c b/lib/server/server-handshake.c index ba471b29..8f2b77a9 100644 --- a/lib/server/server-handshake.c +++ b/lib/server/server-handshake.c @@ -190,7 +190,7 @@ lws_extension_server_handshake(struct lws *wsi, char **p, int budget) !strncmp(args, po->name, strlen(po->name))) { oa.option_name = NULL; - oa.option_index = po - opts; + oa.option_index = (int)(po - opts); oa.start = NULL; lwsl_debug("setting %s\n", po->name); if (!ext->callback( @@ -303,7 +303,8 @@ handshake_0405(struct lws_context *context, struct lws *wsi) LWS_CPYAPP(p, "\x0d\x0a"); args.p = p; - args.max_len = ((char *)pt->serv_buf + context->pt_serv_buf_size) - p; + args.max_len = lws_ptr_diff((char *)pt->serv_buf + + context->pt_serv_buf_size, p); if (user_callback_handle_rxflow(wsi->protocol->callback, wsi, LWS_CALLBACK_ADD_HEADERS, wsi->user_space, &args, 0)) @@ -320,7 +321,7 @@ handshake_0405(struct lws_context *context, struct lws *wsi) /* okay send the handshake response accepting the connection */ - lwsl_parser("issuing resp pkt %d len\n", (int)(p - response)); + lwsl_parser("issuing resp pkt %d len\n", lws_ptr_diff(p, response)); #if defined(DEBUG) && ! defined(LWS_WITH_ESP8266) fwrite(response, 1, p - response, stderr); #endif diff --git a/lib/server/server.c b/lib/server/server.c index dd0ec645..997a6008 100644 --- a/lib/server/server.c +++ b/lib/server/server.c @@ -240,11 +240,11 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername) const char *p; int n, m, colon; - n = strlen(servername); + n = (int)strlen(servername); colon = n; p = strchr(servername, ':'); if (p) - colon = p - servername; + colon = lws_ptr_diff(p, servername); /* Priotity 1: first try exact matches */ @@ -266,7 +266,7 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername) */ vhost = context->vhost_list; while (vhost) { - m = strlen(vhost->name); + m = (int)strlen(vhost->name); if (port == vhost->listen_port && m <= (colon - 2) && servername[colon - m - 1] == '.' && @@ -298,7 +298,7 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername) LWS_VISIBLE LWS_EXTERN const char * lws_get_mimetype(const char *file, const struct lws_http_mount *m) { - int n = strlen(file); + int n = (int)strlen(file); const struct lws_protocol_vhost_options *pvo = NULL; if (m) @@ -549,7 +549,7 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin, * a protocol */ while (pvo) { - n = strlen(path); + n = (int)strlen(path); if (n > (int)strlen(pvo->name) && !strcmp(&path[n - strlen(pvo->name)], pvo->name)) { wsi->sending_chunked = 1; @@ -574,14 +574,15 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin, if (lws_bind_protocol(wsi, pp)) return 1; args.p = (char *)p; - args.max_len = end - p; + args.max_len = lws_ptr_diff(end, p); if (pp->callback(wsi, LWS_CALLBACK_ADD_HEADERS, wsi->user_space, &args, 0)) return -1; p = (unsigned char *)args.p; } - n = lws_serve_http_file(wsi, path, mimetype, (char *)start, p - start); + n = lws_serve_http_file(wsi, path, mimetype, (char *)start, + lws_ptr_diff(p, start)); if (n < 0 || ((n > 0) && lws_http_transaction_completed(wsi))) return -1; /* error or can't reuse connection: close the socket */ @@ -1195,7 +1196,7 @@ lws_http_action(struct lws *wsi) } #endif - n = strlen(s); + n = (int)strlen(s); if (s[0] == '\0' || (n == 1 && s[n - 1] == '/')) s = (char *)hit->def; if (!s) @@ -1290,7 +1291,7 @@ lws_server_init_wsi_for_ws(struct lws *wsi) * a big default for compatibility */ - n = wsi->protocol->rx_buffer_size; + n = (int)wsi->protocol->rx_buffer_size; if (!n) n = wsi->context->pt_serv_buf_size; n += LWS_PRE; @@ -2204,7 +2205,7 @@ adopt_socket_readbuf(struct lws *wsi, const char *readbuf, size_t len) goto bail; } memcpy(wsi->u.hdr.preamble_rx, readbuf, len); - wsi->u.hdr.preamble_rx_len = len; + wsi->u.hdr.preamble_rx_len = (int)len; return wsi; @@ -2548,9 +2549,9 @@ try_pollout: * we could, not accepting it due to PEER_LIMITS would * block the connect queue for other legit peers. */ - accept_fd = accept(pollfd->fd, (struct sockaddr *)&cli_addr, + accept_fd = accept((int)pollfd->fd, (struct sockaddr *)&cli_addr, &clilen); - lws_latency(context, wsi, "listener accept", accept_fd, + lws_latency(context, wsi, "listener accept", (int)accept_fd, accept_fd >= 0); if (accept_fd < 0) { if (LWS_ERRNO == LWS_EAGAIN || @@ -2712,7 +2713,7 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, content_type && content_type[0]) if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, (unsigned char *)content_type, - strlen(content_type), &p, end)) + (int)strlen(content_type), &p, end)) return -1; #if defined(LWS_WITH_RANGES) @@ -2855,7 +2856,7 @@ lws_interpret_incoming_packet(struct lws *wsi, unsigned char **buf, size_t len) * we were accepting input but now we stopped doing so */ if (wsi->rxflow_bitmap) { - lws_rxflow_cache(wsi, *buf, 0, len); + lws_rxflow_cache(wsi, *buf, 0, (int)len); lwsl_parser("%s: cached %ld\n", __func__, (long)len); return 1; } @@ -2972,7 +2973,7 @@ skip: pc = s->replace(s->data, hit); if (!pc) pc = "NULL"; - n = strlen(pc); + n = (int)strlen(pc); s->swallow[s->pos] = '\0'; if (n != s->pos) { memmove(s->start + n, diff --git a/lib/service.c b/lib/service.c index fa1cc8bd..1b9c2adf 100644 --- a/lib/service.c +++ b/lib/service.c @@ -633,7 +633,7 @@ int lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len) assert ((char *)buf >= (char *)h2n->rx_scratch && (char *)&buf[len] <= (char *)&h2n->rx_scratch[LWS_H2_RX_SCRATCH_SIZE]); - h2n->rx_scratch_pos = ((char *)buf - (char *)h2n->rx_scratch); + h2n->rx_scratch_pos = lws_ptr_diff(buf, h2n->rx_scratch); h2n->rx_scratch_len = len; lwsl_info("%s: %p: pausing h2 rx_scratch\n", __func__, wsi); @@ -1227,6 +1227,7 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd, int t case LWSCM_EVENT_PIPE: { struct lws_vhost *v = context->vhost_list; +#if !defined(WIN32) && !defined(_WIN32) char s[10]; /* @@ -1238,6 +1239,7 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd, int t (void)n; if (n < 0) goto close_and_handled; +#endif /* * the poll() wait, or the event loop for libuv etc is a diff --git a/lib/tls/openssl/client.c b/lib/tls/openssl/client.c index 1eb9f19b..50a280d2 100644 --- a/lib/tls/openssl/client.c +++ b/lib/tls/openssl/client.c @@ -184,7 +184,7 @@ lws_ssl_client_bio_create(struct lws *wsi) #endif #endif /* USE_WOLFSSL */ - wsi->client_bio = BIO_new_socket(wsi->desc.sockfd, BIO_NOCLOSE); + wsi->client_bio = BIO_new_socket((int)(long long)wsi->desc.sockfd, BIO_NOCLOSE); SSL_set_bio(wsi->ssl, wsi->client_bio, wsi->client_bio); #ifdef USE_WOLFSSL diff --git a/lib/tls/openssl/lws-genhash.c b/lib/tls/openssl/lws-genhash.c index df2ce46c..c81aca3d 100644 --- a/lib/tls/openssl/lws-genhash.c +++ b/lib/tls/openssl/lws-genhash.c @@ -146,7 +146,7 @@ lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type, if (EVP_DigestInit_ex(ctx->ctx, md, NULL) != 1) return -1; - pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, key, key_len); + pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, key, (int)key_len); if (EVP_DigestSignInit(ctx->ctx, NULL, md, NULL, pkey) != 1) return -1; diff --git a/lib/tls/openssl/lws-genrsa.c b/lib/tls/openssl/lws-genrsa.c index 6bdcde48..b86068e2 100644 --- a/lib/tls/openssl/lws-genrsa.c +++ b/lib/tls/openssl/lws-genrsa.c @@ -163,11 +163,11 @@ cleanup_1: LWS_VISIBLE int lws_genrsa_public_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, - size_t in_len, uint8_t *out, size_t out_max) + size_t in_len, uint8_t *out, size_t out_max) { uint32_t m; - m = RSA_public_decrypt(in_len, in, out, ctx->rsa, RSA_PKCS1_PADDING); + m = RSA_public_decrypt((int)in_len, in, out, ctx->rsa, RSA_PKCS1_PADDING); /* the bignums are also freed by freeing the RSA */ RSA_free(ctx->rsa); @@ -208,12 +208,12 @@ lws_genrsa_public_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t sig_len) { int n = lws_genrsa_genrsa_hash_to_NID(hash_type), - h = lws_genhash_size(hash_type); + h = (int)lws_genhash_size(hash_type); if (n < 0) return -1; - n = RSA_verify(n, in, h, (uint8_t *)sig, sig_len, ctx->rsa); + n = RSA_verify(n, in, h, (uint8_t *)sig, (int)sig_len, ctx->rsa); if (n != 1) { lwsl_notice("%s: -0x%x\n", __func__, -n); @@ -229,7 +229,7 @@ lws_genrsa_public_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t sig_len) { int n = lws_genrsa_genrsa_hash_to_NID(hash_type), - h = lws_genhash_size(hash_type); + h = (int)lws_genhash_size(hash_type); unsigned int used = 0; if (n < 0) diff --git a/lib/tls/openssl/server.c b/lib/tls/openssl/server.c index 2a5032fa..729abfcd 100644 --- a/lib/tls/openssl/server.c +++ b/lib/tls/openssl/server.c @@ -340,7 +340,7 @@ lws_tls_server_new_nonblocking(struct lws *wsi, lws_sockfd_type accept_fd) } SSL_set_ex_data(wsi->ssl, openssl_websocket_private_data_index, wsi); - SSL_set_fd(wsi->ssl, accept_fd); + SSL_set_fd(wsi->ssl, (int)(long long)accept_fd); #ifdef USE_WOLFSSL #ifdef USE_OLD_CYASSL diff --git a/lib/tls/openssl/ssl.c b/lib/tls/openssl/ssl.c index 5b46809d..7da354fe 100644 --- a/lib/tls/openssl/ssl.c +++ b/lib/tls/openssl/ssl.c @@ -103,7 +103,7 @@ lws_context_init_ssl_pem_passwd_cb(char * buf, int size, int rwflag, strncpy(buf, info->ssl_private_key_password, size); buf[size - 1] = '\0'; - return strlen(buf); + return (int)strlen(buf); } void diff --git a/plugins/generic-table/protocol_table_dirlisting.c b/plugins/generic-table/protocol_table_dirlisting.c index f8787980..dd1300a2 100644 --- a/plugins/generic-table/protocol_table_dirlisting.c +++ b/plugins/generic-table/protocol_table_dirlisting.c @@ -262,7 +262,7 @@ callback_lws_table_dirlisting(struct lws *wsi, enum lws_callback_reasons reason, s1[0] = '\0'; q += strlen(q); } else { - n = q1 - q; + n = lws_ptr_diff(q1, q); if (n > (int)sizeof(s) - 1) n = sizeof(s) - 1; if (first) { @@ -272,7 +272,7 @@ callback_lws_table_dirlisting(struct lws *wsi, enum lws_callback_reasons reason, strncpy(s, q, n); s[n] = '\0'; - n = q1 - pss->reldir; + n = lws_ptr_diff(q1, pss->reldir); if (n > (int)sizeof(s1) - 1) n = sizeof(s1) - 1; strncpy(s1, pss->reldir, n); diff --git a/plugins/protocol_lws_meta.c b/plugins/protocol_lws_meta.c index 4944cff1..69324db0 100644 --- a/plugins/protocol_lws_meta.c +++ b/plugins/protocol_lws_meta.c @@ -112,7 +112,7 @@ lws_get_channel_wsi(struct per_session_data__lws_meta *pss, int ch) static int lws_get_channel_id(struct lws *wsi) { - return (lws_intptr_t)lws_get_opaque_parent_data(wsi); + return (int)(lws_intptr_t)lws_get_opaque_parent_data(wsi); } static void diff --git a/plugins/protocol_lws_mirror.c b/plugins/protocol_lws_mirror.c index 8affca99..80b11d7f 100644 --- a/plugins/protocol_lws_mirror.c +++ b/plugins/protocol_lws_mirror.c @@ -108,7 +108,8 @@ mirror_update_worst_tail(struct mirror_instance *mi) lws_start_foreach_ll(struct per_session_data__lws_mirror *, pss, mi->same_mi_pss_list) { - wai = lws_ring_get_count_waiting_elements(mi->ring, &pss->tail); + wai = (uint32_t)lws_ring_get_count_waiting_elements(mi->ring, + &pss->tail); if (wai >= worst) { worst = wai; worst_tail = pss->tail; @@ -370,7 +371,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason, break; case LWS_CALLBACK_RECEIVE: - n = lws_ring_get_count_free_elements(pss->mi->ring); + n = (int)lws_ring_get_count_free_elements(pss->mi->ring); if (!n) { lwsl_notice("dropping!\n"); if (pss->mi->rx_enabled) diff --git a/plugins/protocol_lws_sshd_demo.c b/plugins/protocol_lws_sshd_demo.c index 47f7471e..ca2fe3eb 100644 --- a/plugins/protocol_lws_sshd_demo.c +++ b/plugins/protocol_lws_sshd_demo.c @@ -102,7 +102,7 @@ enter_state(struct sshd_instance_priv *priv, enum states state) priv->state = state; priv->ptr = strings[state]; priv->pos = 0; - priv->len = strlen(priv->ptr); + priv->len = (int)strlen(priv->ptr); lws_callback_on_writable(priv->wsi); } @@ -168,7 +168,7 @@ ssh_ops_tx(void *_priv, int stdch, uint8_t *buf, size_t len) return 0; memcpy(buf, priv->ptr + priv->pos, chunk); - priv->pos += chunk; + priv->pos += (int)chunk; if (priv->state == SSH_TEST_DONE && priv->pos == priv->len) { /* @@ -208,7 +208,7 @@ ssh_ops_get_server_key(struct lws *wsi, uint8_t *buf, size_t len) int n; lseek(vhd->privileged_fd, 0, SEEK_SET); - n = read(vhd->privileged_fd, buf, len); + n = read(vhd->privileged_fd, buf, (int)len); if (n < 0) { lwsl_err("%s: read failed: %d\n", __func__, n); n = 0; @@ -226,7 +226,7 @@ ssh_ops_set_server_key(struct lws *wsi, uint8_t *buf, size_t len) lws_get_protocol(wsi)); int n; - n = write(vhd->privileged_fd, buf, len); + n = write(vhd->privileged_fd, buf, (int)len); if (n < 0) { lwsl_err("%s: read failed: %d\n", __func__, errno); n = 0; @@ -242,7 +242,7 @@ ssh_ops_is_pubkey_authorized(const char *username, const char *type, const uint8_t *peer, int peer_len) { char *aps = NULL, *p, *ps; - int n = strlen(type), alen = 2048, ret = 2, len; + int n = (int)strlen(type), alen = 2048, ret = 2, len; size_t s = 0; lwsl_info("%s: checking pubkey for %s\n", __func__, username); diff --git a/plugins/protocol_post_demo.c b/plugins/protocol_post_demo.c index b5d5e828..434901ec 100644 --- a/plugins/protocol_post_demo.c +++ b/plugins/protocol_post_demo.c @@ -77,7 +77,7 @@ file_upload_cb(void *data, const char *name, const char *filename, * simple demo use a fixed name so we don't have to deal with * attacks */ #if !defined(LWS_WITH_ESP8266) && !defined(LWS_WITH_ESP32) - pss->fd = (lws_filefd_type)open("/tmp/post-file", + pss->fd = (lws_filefd_type)(long long)open("/tmp/post-file", O_CREAT | O_TRUNC | O_RDWR, 0600); #endif break; @@ -91,7 +91,7 @@ file_upload_cb(void *data, const char *name, const char *filename, return 1; #if !defined(LWS_WITH_ESP8266) && !defined(LWS_WITH_ESP32) - n = write((int)pss->fd, buf, len); + n = write((int)(long long)pss->fd, buf, len); lwsl_notice("%s: write %d says %d\n", __func__, len, n); #else lwsl_notice("%s: Received chunk size %d\n", __func__, len); @@ -100,7 +100,7 @@ file_upload_cb(void *data, const char *name, const char *filename, if (state == LWS_UFS_CONTENT) break; #if !defined(LWS_WITH_ESP8266) && !defined(LWS_WITH_ESP32) - close((int)pss->fd); + close((int)(long long)pss->fd); pss->fd = LWS_INVALID_FILE; #endif break; @@ -134,7 +134,7 @@ callback_post_demo(struct lws *wsi, enum lws_callback_reasons reason, } /* let it parse the POST data */ - if (lws_spa_process(pss->spa, in, len)) + if (lws_spa_process(pss->spa, in, (int)len)) return -1; break; @@ -160,7 +160,7 @@ callback_post_demo(struct lws *wsi, enum lws_callback_reasons reason, pss->filename, pss->file_length); p += lws_snprintf((char *)p, end - p, ""); - pss->result_len = p - (unsigned char *)(pss->result + LWS_PRE); + pss->result_len = lws_ptr_diff(p, pss->result + LWS_PRE); n = LWS_PRE + 1024; buffer = malloc(n); diff --git a/plugins/ssh-base/kex-25519.c b/plugins/ssh-base/kex-25519.c index 3e9eaa7d..526125f3 100644 --- a/plugins/ssh-base/kex-25519.c +++ b/plugins/ssh-base/kex-25519.c @@ -109,7 +109,7 @@ lws_mpint_rfc4251(uint8_t *dest, const uint8_t *src, int bytes, int uns) while (bytes--) *dest++ = *src++; - return dest - odest; + return lws_ptr_diff(dest, odest); } int @@ -154,7 +154,7 @@ ed25519_key_parse(uint8_t *p, size_t len, char *type, size_t type_len, return 8; m = l; if (m > type_len) - m = type_len -1 ; + m = (uint32_t)type_len -1 ; strncpy(type, (const char *)p, m); type[m] = '\0'; @@ -198,7 +198,7 @@ _genhash_update_len(struct lws_genhash_ctx *ctx, const void *input, size_t ilen) { uint32_t be; - lws_p32((uint8_t *)&be, ilen); + lws_p32((uint8_t *)&be, (uint32_t)ilen); if (lws_genhash_update(ctx, (uint8_t *)&be, 4)) return 1; @@ -315,7 +315,7 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) char keyt[33]; int r, c; - r = get_gen_server_key_25519(pss, servkey, sizeof(servkey)); + r = (int)get_gen_server_key_25519(pss, servkey, (int)sizeof(servkey)); if (!r) { lwsl_err("%s: Failed to get or gen server key\n", __func__); @@ -426,7 +426,7 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) * name length: name * key length: key * ---> */ - lws_p32((uint8_t *)&be, 8 + strlen(keyt) + LWS_SIZE_EC25519); + lws_p32((uint8_t *)&be, 8 + (int)strlen(keyt) + LWS_SIZE_EC25519); if (lws_genhash_update(&ctx, (void *)&be, 4)) goto hash_probs; @@ -481,9 +481,9 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) lp = p; p +=4; - lws_sized_blob(&p, keyt, strlen(keyt)); + lws_sized_blob(&p, keyt, (int)strlen(keyt)); lws_sized_blob(&p, pss->K_S, LWS_SIZE_EC25519); - lws_p32(lp, p - lp - 4); + lws_p32(lp, lws_ptr_diff(p, lp) - 4); /* Q_S (exchange value sent by the server) */ @@ -493,14 +493,14 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) lp = p; p +=4; - lws_sized_blob(&p, keyt, strlen(keyt)); + lws_sized_blob(&p, keyt, (int)strlen(keyt)); lws_sized_blob(&p, payload_sig, 64); - lws_p32(lp, p - lp - 4); + lws_p32(lp, lws_ptr_diff(p, lp) - 4); /* end of message */ lws_pad_set_length(pss, reply, &p, &pss->active_keys_stc); - *plen = p - reply; + *plen = lws_ptr_diff(p, reply); if (!pss->active_keys_stc.valid) memcpy(pss->session_id, temp, LWS_SIZE_EC25519); diff --git a/plugins/ssh-base/sshd.c b/plugins/ssh-base/sshd.c index a419cfef..c121178f 100644 --- a/plugins/ssh-base/sshd.c +++ b/plugins/ssh-base/sshd.c @@ -62,7 +62,7 @@ lws_p32(uint8_t *p, uint32_t v) int lws_cstr(uint8_t **p, const char *s, uint32_t max) { - uint32_t n = strlen(s); + uint32_t n = (uint32_t)strlen(s); if (n > max) return 1; @@ -122,7 +122,7 @@ void lws_pad_set_length(struct per_session_data__sshd *pss, void *start, uint8_t **p, struct lws_ssh_keys *keys) { - uint32_t len = *p - (uint8_t *)start; + uint32_t len = lws_ptr_diff(*p, start); uint8_t padc = 4, *bs = start; if (keys->full_length) @@ -157,7 +157,7 @@ offer(struct per_session_data__sshd *pss, uint8_t *p, uint32_t len, int first, char keyt[32]; uint8_t keybuf[256]; - keylen = get_gen_server_key_25519(pss, keybuf, sizeof(keybuf)); + keylen = (int)get_gen_server_key_25519(pss, keybuf, (int)sizeof(keybuf)); if (!keylen) { lwsl_notice("get_gen_server_key failed\n"); return 1; @@ -281,7 +281,7 @@ offer(struct per_session_data__sshd *pss, uint8_t *p, uint32_t len, int first, *p++ = 0; *p++ = 0; - len = p - op; + len = lws_ptr_diff(p, op); if (payload_len) /* starts at buf + 5 and excludes padding */ *payload_len = len - 5; @@ -317,7 +317,7 @@ handle_name(struct per_session_data__sshd *pss) kex->match_bitfield |= 1; break; case SSH_KEX_NL_SHK_ALGS: - len = get_gen_server_key_25519(pss, keybuf, sizeof(keybuf)); + len = (int)get_gen_server_key_25519(pss, keybuf, (int)sizeof(keybuf)); if (!len) break; if (ed25519_key_parse(keybuf, len, @@ -1174,12 +1174,12 @@ again: */ n = 4 + 32 + 1 + - 4 + strlen(pss->ua->username) + - 4 + strlen(pss->ua->service) + + 4 + (int)strlen(pss->ua->username) + + 4 + (int)strlen(pss->ua->service) + 4 + 9 + 1 + - 4 + strlen(pss->ua->alg) + - 4 + pss->ua->pubkey_len; + 4 + (int)strlen(pss->ua->alg) + + 4 + (int)pss->ua->pubkey_len; ps = sshd_zalloc(n); if (!ps) { @@ -1854,7 +1854,7 @@ parse(struct per_session_data__sshd *pss, uint8_t *p, size_t len) uint8_t pt[2048]; len++; - cp = len; + cp = (uint32_t)len; if (cp > l - pss->pa_pos) cp = l - pss->pa_pos; @@ -1920,7 +1920,7 @@ pad_and_encrypt(uint8_t *dest, void *ps, uint8_t *pp, if (!skip_pad) lws_pad_set_length(pss, ps, &pp, &pss->active_keys_stc); - n = pp - (uint8_t *)ps; + n = lws_ptr_diff(pp, ps); if (!pss->active_keys_stc.valid) { memcpy(dest, ps, n); @@ -2171,9 +2171,9 @@ lws_callback_raw_sshd(struct lws *wsi, enum lws_callback_reasons reason, pp = ps + 5; *pp++ = SSH_MSG_USERAUTH_BANNER; if (pss->vhd && pss->vhd->ops->banner) - n = pss->vhd->ops->banner((char *)&buf[650], + n = (int)pss->vhd->ops->banner((char *)&buf[650], 150 - 1, - lang, sizeof(lang)); + lang, (int)sizeof(lang)); lws_p32(pp, n); pp += 4; strcpy((char *)pp, (char *)&buf[650]); @@ -2362,12 +2362,12 @@ lws_callback_raw_sshd(struct lws *wsi, enum lws_callback_reasons reason, pp += pss->vhd->ops->tx(ch->priv, n, pp, &buf[sizeof(buf) - 1] - pp); - lws_p32(ps + m - 4, pp - (ps + m)); + lws_p32(ps + m - 4, lws_ptr_diff(pp, (ps + m))); if (pss->vhd->ops->tx_waiting(ch->priv) > 0) lws_callback_on_writable(wsi); - ch->window -= (pp - ps) - m; + ch->window -= lws_ptr_diff(pp, ps) - m; //lwsl_debug("our send window: %d\n", ch->window); /* fallthru */ @@ -2465,7 +2465,7 @@ bail: case LWS_CALLBACK_CGI_PROCESS_ATTACH: ch = ssh_get_server_ch(pss, pss->channel_doing_spawn); if (ch) { - ch->spawn_pid = len; /* child process PID */ + ch->spawn_pid = (int)len; /* child process PID */ lwsl_notice("associated PID %d to ch %d\n", (int)len, pss->channel_doing_spawn); } diff --git a/plugins/ssh-base/telnet.c b/plugins/ssh-base/telnet.c index 62d7a808..9d908fa2 100644 --- a/plugins/ssh-base/telnet.c +++ b/plugins/ssh-base/telnet.c @@ -202,8 +202,8 @@ lws_callback_raw_telnet(struct lws *wsi, enum lws_callback_reasons reason, * in the worst case of all 0xff, doubling the size */ pu = buf + LWS_PRE + 400; - m = pss->vhd->ops->tx(pss->priv, LWS_STDOUT, pu, - (sizeof(buf) - LWS_PRE - n - 401) / 2); + m = (int)pss->vhd->ops->tx(pss->priv, LWS_STDOUT, pu, + ((int)sizeof(buf) - LWS_PRE - n - 401) / 2); /* * apply telnet line discipline and copy into place diff --git a/test-apps/test-fraggle.c b/test-apps/test-fraggle.c index 1de73603..dd1e84e1 100644 --- a/test-apps/test-fraggle.c +++ b/test-apps/test-fraggle.c @@ -99,7 +99,7 @@ callback_fraggle(struct lws *wsi, enum lws_callback_reasons reason, for (n = 0; (unsigned int)n < len; n++) psf->sum += p[n]; - psf->total_message += len; + psf->total_message += (int)len; psf->packets_left++; if (lws_is_final_fragment(wsi)) diff --git a/test-apps/test-server-http.c b/test-apps/test-server-http.c index 3507d3c0..5ef640a1 100644 --- a/test-apps/test-server-http.c +++ b/test-apps/test-server-http.c @@ -95,7 +95,7 @@ dump_handshake_info(struct lws *wsi) const char * get_mimetype(const char *file) { - int n = strlen(file); + int n = (int)strlen(file); if (n < 5) return NULL; @@ -149,7 +149,7 @@ file_upload_cb(void *data, const char *name, const char *filename, /* we get the original filename in @filename arg, but for * simple demo use a fixed name so we don't have to deal with * attacks */ - pss->post_fd = (lws_filefd_type)open("/tmp/post-file", + pss->post_fd = (lws_filefd_type)(long long)open("/tmp/post-file", O_CREAT | O_TRUNC | O_RDWR, 0600); break; case LWS_UFS_FINAL_CONTENT: @@ -161,12 +161,12 @@ file_upload_cb(void *data, const char *name, const char *filename, if (pss->file_length > 100000) return 1; - n = write((int)pss->post_fd, buf, len); + n = write((int)(long long)pss->post_fd, buf, len); lwsl_notice("%s: write %d says %d\n", __func__, len, n); } if (state == LWS_UFS_CONTENT) break; - close((int)pss->post_fd); + close((int)(long long)pss->post_fd); pss->post_fd = LWS_INVALID_FILE; break; } @@ -417,7 +417,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, sizeof(leaf_path))) return 1; #endif - n = (char *)p - leaf_path; + n = lws_ptr_diff(p, leaf_path); n = lws_serve_http_file(wsi, buf, mimetype, other_headers, n); if (n < 0) @@ -450,7 +450,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, } /* let it parse the POST data */ - if (lws_spa_process(pss->spa, in, len)) + if (lws_spa_process(pss->spa, in, (int)len)) return -1; break; @@ -482,7 +482,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, pss->filename, pss->file_length); p += lws_snprintf((char *)p, end - p, ""); - pss->result_len = p - (unsigned char *)(pss->result + LWS_PRE); + pss->result_len = lws_ptr_diff(p, pss->result + LWS_PRE); p = buffer + LWS_PRE; start = p; @@ -567,7 +567,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, n = sizeof(buffer) - LWS_PRE; /* but if the peer told us he wants less, we can adapt */ - m = lws_get_peer_write_allowance(wsi); + m = (int)lws_get_peer_write_allowance(wsi); /* -1 means not using a protocol that has this info */ if (m == 0) @@ -712,7 +712,7 @@ bail: * called before any other POLL related callback * if protecting wsi lifecycle change, len == 1 */ - test_server_lock(len); + test_server_lock((int)len); break; case LWS_CALLBACK_UNLOCK_POLL: @@ -721,7 +721,7 @@ bail: * called after any other POLL related callback * if protecting wsi lifecycle change, len == 1 */ - test_server_unlock(len); + test_server_unlock((int)len); break; #ifdef EXTERNAL_POLL diff --git a/win32port/win32helpers/getopt_long.c b/win32port/win32helpers/getopt_long.c index 43a5cba7..22e5fa89 100644 --- a/win32port/win32helpers/getopt_long.c +++ b/win32port/win32helpers/getopt_long.c @@ -38,6 +38,9 @@ #include #include "getopt.h" +#define lws_ptr_diff(head, tail) \ + ((int)((char *)(head) - (char *)(tail))) + extern int opterr; /* if error message should be printed */ extern int optind; /* index into parent argv vector */ extern int optopt; /* character checked for validity */ @@ -183,10 +186,10 @@ getopt_long(nargc, nargv, options, long_options, index) return(-1); } if ((has_equal = strchr(current_argv, '=')) != NULL) { - current_argv_len = has_equal - current_argv; + current_argv_len = lws_ptr_diff(has_equal, current_argv); has_equal++; } else - current_argv_len = strlen(current_argv); + current_argv_len = (int)strlen(current_argv); for (i = 0; long_options[i].name; i++) { if (strncmp(current_argv, long_options[i].name, current_argv_len))