The winsock2 APIs are a bit weird at times...
Change-Id: I977bab08cb614c2d59c34ceebc112f3add9bd168
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1262
Message-Id: <20251010095706.3779-1-gert@greenie.muc.de>
URL: https://sourceforge.net/p/openvpn/mailman/message/59244802/
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -80,11 +80,6 @@ socks_proxy_close(struct socks_proxy_info *sp) |
| 80 | 80 |
free(sp); |
| 81 | 81 |
} |
| 82 | 82 |
|
| 83 |
-#if defined(__GNUC__) || defined(__clang__) |
|
| 84 |
-#pragma GCC diagnostic push |
|
| 85 |
-#pragma GCC diagnostic ignored "-Wconversion" |
|
| 86 |
-#endif |
|
| 87 |
- |
|
| 88 | 83 |
static bool |
| 89 | 84 |
socks_proxy_recv_char(char *c, const char *name, socket_descriptor_t sd, |
| 90 | 85 |
struct event_timeout *server_poll_timeout, |
| ... | ... |
@@ -98,7 +93,8 @@ socks_proxy_recv_char(char *c, const char *name, socket_descriptor_t sd, |
| 98 | 98 |
tv.tv_sec = get_server_poll_remaining_time(server_poll_timeout); |
| 99 | 99 |
tv.tv_usec = 0; |
| 100 | 100 |
|
| 101 |
- const int status = select(sd + 1, &reads, NULL, NULL, &tv); |
|
| 101 |
+ /* NB: first argument ignored on Windows where socket_descriptor_t != int */ |
|
| 102 |
+ const int status = select((int)sd + 1, &reads, NULL, NULL, &tv); |
|
| 102 | 103 |
|
| 103 | 104 |
get_signal(signal_received); |
| 104 | 105 |
if (*signal_received) |
| ... | ... |
@@ -139,10 +135,7 @@ socks_username_password_auth(struct socks_proxy_info *p, socket_descriptor_t sd, |
| 139 | 139 |
volatile int *signal_received) |
| 140 | 140 |
{
|
| 141 | 141 |
char to_send[516]; |
| 142 |
- char buf[2]; |
|
| 143 |
- int len = 0; |
|
| 144 | 142 |
struct user_pass creds; |
| 145 |
- ssize_t size; |
|
| 146 | 143 |
bool ret = false; |
| 147 | 144 |
|
| 148 | 145 |
CLEAR(creds); |
| ... | ... |
@@ -161,9 +154,10 @@ socks_username_password_auth(struct socks_proxy_info *p, socket_descriptor_t sd, |
| 161 | 161 |
|
| 162 | 162 |
int sret = snprintf(to_send, sizeof(to_send), "\x01%c%s%c%s", (int)strlen(creds.username), |
| 163 | 163 |
creds.username, (int)strlen(creds.password), creds.password); |
| 164 |
- ASSERT(sret <= sizeof(to_send)); |
|
| 164 |
+ ASSERT(sret >= 0 && sret <= sizeof(to_send)); |
|
| 165 | 165 |
|
| 166 |
- size = send(sd, to_send, strlen(to_send), MSG_NOSIGNAL); |
|
| 166 |
+ /* NB: int because Windows APIs */ |
|
| 167 |
+ ssize_t size = send(sd, to_send, (int)strlen(to_send), MSG_NOSIGNAL); |
|
| 167 | 168 |
|
| 168 | 169 |
if (size != strlen(to_send)) |
| 169 | 170 |
{
|
| ... | ... |
@@ -172,6 +166,8 @@ socks_username_password_auth(struct socks_proxy_info *p, socket_descriptor_t sd, |
| 172 | 172 |
goto cleanup; |
| 173 | 173 |
} |
| 174 | 174 |
|
| 175 |
+ int len = 0; |
|
| 176 |
+ char buf[2]; |
|
| 175 | 177 |
while (len < 2) |
| 176 | 178 |
{
|
| 177 | 179 |
char c; |
| ... | ... |
@@ -419,8 +415,10 @@ establish_socks_proxy_passthru(struct socks_proxy_info *p, |
| 419 | 419 |
buf[5 + len + 1] = (char)(port & 0xff); |
| 420 | 420 |
|
| 421 | 421 |
{
|
| 422 |
- const ssize_t size = send(sd, buf, 5 + len + 2, MSG_NOSIGNAL); |
|
| 423 |
- if ((int)size != 5 + (int)len + 2) |
|
| 422 |
+ /* int because Windows APIs */ |
|
| 423 |
+ int send_len = 5 + (int)len + 2; |
|
| 424 |
+ const ssize_t size = send(sd, buf, send_len, MSG_NOSIGNAL); |
|
| 425 |
+ if (size != send_len) |
|
| 424 | 426 |
{
|
| 425 | 427 |
msg(D_LINK_ERRORS | M_ERRNO, |
| 426 | 428 |
"establish_socks_proxy_passthru: TCP port write failed on send()"); |
| ... | ... |
@@ -443,10 +441,6 @@ error: |
| 443 | 443 |
return; |
| 444 | 444 |
} |
| 445 | 445 |
|
| 446 |
-#if defined(__GNUC__) || defined(__clang__) |
|
| 447 |
-#pragma GCC diagnostic pop |
|
| 448 |
-#endif |
|
| 449 |
- |
|
| 450 | 446 |
void |
| 451 | 447 |
establish_socks_proxy_udpassoc(struct socks_proxy_info *p, |
| 452 | 448 |
socket_descriptor_t ctrl_sd, /* already open to proxy */ |