mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-12 15:17:14 +03:00
Fix Narrowing conversion from 'ssize_t' to signed type 'int' is implementation-defined
This commit is contained in:
parent
d0a016221c
commit
ae7530e33f
17
common.c
17
common.c
@ -391,7 +391,7 @@ int connect_addr(struct connection *cnx, int fd_from, connect_blocking blocking)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Store some data to write to the queue later */
|
/* Store some data to write to the queue later */
|
||||||
int defer_write(struct queue *q, void* data, int data_size)
|
int defer_write(struct queue *q, void* data, ssize_t data_size)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
ptrdiff_t data_offset = q->deferred_data - q->begin_deferred_data;
|
ptrdiff_t data_offset = q->deferred_data - q->begin_deferred_data;
|
||||||
@ -403,7 +403,7 @@ int defer_write(struct queue *q, void* data, int data_size)
|
|||||||
q->begin_deferred_data = p;
|
q->begin_deferred_data = p;
|
||||||
q->deferred_data = p + data_offset;
|
q->deferred_data = p + data_offset;
|
||||||
p += data_offset + q->deferred_data_size;
|
p += data_offset + q->deferred_data_size;
|
||||||
q->deferred_data_size += data_size;
|
q->deferred_data_size += (int)data_size;
|
||||||
memcpy(p, data, data_size);
|
memcpy(p, data, data_size);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -415,13 +415,13 @@ int defer_write(struct queue *q, void* data, int data_size)
|
|||||||
* */
|
* */
|
||||||
int flush_deferred(struct queue *q)
|
int flush_deferred(struct queue *q)
|
||||||
{
|
{
|
||||||
int n;
|
ssize_t n;
|
||||||
|
|
||||||
print_message(msg_fd, "flushing deferred data to fd %d\n", q->fd);
|
print_message(msg_fd, "flushing deferred data to fd %d\n", q->fd);
|
||||||
|
|
||||||
n = write(q->fd, q->deferred_data, q->deferred_data_size);
|
n = write(q->fd, q->deferred_data, q->deferred_data_size);
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
return n;
|
return (int)n;
|
||||||
|
|
||||||
if (n == q->deferred_data_size) {
|
if (n == q->deferred_data_size) {
|
||||||
/* All has been written -- release the memory */
|
/* All has been written -- release the memory */
|
||||||
@ -432,10 +432,10 @@ int flush_deferred(struct queue *q)
|
|||||||
} else {
|
} else {
|
||||||
/* There is data left */
|
/* There is data left */
|
||||||
q->deferred_data += n;
|
q->deferred_data += n;
|
||||||
q->deferred_data_size -= n;
|
q->deferred_data_size -= (int)n;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return (int)n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -470,7 +470,8 @@ void dump_connection(struct connection *cnx)
|
|||||||
int fd2fd(struct queue *target_q, struct queue *from_q)
|
int fd2fd(struct queue *target_q, struct queue *from_q)
|
||||||
{
|
{
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
int target, from, size_r, size_w;
|
int target, from;
|
||||||
|
ssize_t size_r, size_w;
|
||||||
|
|
||||||
target = target_q->fd;
|
target = target_q->fd;
|
||||||
from = from_q->fd;
|
from = from_q->fd;
|
||||||
@ -515,7 +516,7 @@ int fd2fd(struct queue *target_q, struct queue *from_q)
|
|||||||
|
|
||||||
CHECK_RES_RETURN(size_w, "write", FD_CNXCLOSED);
|
CHECK_RES_RETURN(size_w, "write", FD_CNXCLOSED);
|
||||||
|
|
||||||
return size_w;
|
return (int)size_w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns a string that prints the IP and port of the sockaddr */
|
/* returns a string that prints the IP and port of the sockaddr */
|
||||||
|
2
common.h
2
common.h
@ -172,7 +172,7 @@ int resolve_split_name(struct addrinfo **out, char* hostname, char* port);
|
|||||||
|
|
||||||
int start_listen_sockets(struct listen_endpoint *sockfd[]);
|
int start_listen_sockets(struct listen_endpoint *sockfd[]);
|
||||||
|
|
||||||
int defer_write(struct queue *q, void* data, int data_size);
|
int defer_write(struct queue *q, void* data, ssize_t data_size);
|
||||||
int flush_deferred(struct queue *q);
|
int flush_deferred(struct queue *q);
|
||||||
|
|
||||||
extern struct sslhcfg_item cfg;
|
extern struct sslhcfg_item cfg;
|
||||||
|
@ -69,7 +69,7 @@ static void printsettings(void)
|
|||||||
strcpy(buf, "resolve on forward");
|
strcpy(buf, "resolve on forward");
|
||||||
if (!p->resolve_on_forward) {
|
if (!p->resolve_on_forward) {
|
||||||
sprintaddr(buf, sizeof(buf), p->saddr);
|
sprintaddr(buf, sizeof(buf), p->saddr);
|
||||||
int len = strlen(buf);
|
size_t len = strlen(buf);
|
||||||
sprintf(buf+len, " family %d %d",
|
sprintf(buf+len, " family %d %d",
|
||||||
p->saddr->ai_family,
|
p->saddr->ai_family,
|
||||||
p->saddr->ai_addr->sa_family);
|
p->saddr->ai_addr->sa_family);
|
||||||
@ -98,7 +98,8 @@ static void printsettings(void)
|
|||||||
static void setup_regex_probe(struct sslhcfg_protocols_item *p)
|
static void setup_regex_probe(struct sslhcfg_protocols_item *p)
|
||||||
#ifdef ENABLE_REGEX
|
#ifdef ENABLE_REGEX
|
||||||
{
|
{
|
||||||
int num_patterns, i, error;
|
size_t num_patterns, i;
|
||||||
|
int error;
|
||||||
pcre2_code** pattern_list;
|
pcre2_code** pattern_list;
|
||||||
PCRE2_SIZE error_offset;
|
PCRE2_SIZE error_offset;
|
||||||
PCRE2_UCHAR8 err_str[120];
|
PCRE2_UCHAR8 err_str[120];
|
||||||
@ -186,7 +187,7 @@ void config_sanity_check(struct sslhcfg_item* cfg)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < cfg->protocols_len; ++i) {
|
for (i = 0; i < cfg->protocols_len; ++i) {
|
||||||
if (strcmp(cfg->protocols[i].name, "tls")) {
|
if (strcmp(cfg->protocols[i].name, "tls") != 0) {
|
||||||
if (cfg->protocols[i].sni_hostnames_len) {
|
if (cfg->protocols[i].sni_hostnames_len) {
|
||||||
print_message(msg_config_error, "name: \"%s\"; host: \"%s\"; port: \"%s\": "
|
print_message(msg_config_error, "name: \"%s\"; host: \"%s\"; port: \"%s\": "
|
||||||
"Config option sni_hostnames is only applicable for tls\n",
|
"Config option sni_hostnames is only applicable for tls\n",
|
||||||
|
8
tls.c
8
tls.c
@ -224,7 +224,7 @@ parse_server_name_extension(const struct TLSProtocol *tls_data, const char *data
|
|||||||
switch (data[pos]) { /* name type */
|
switch (data[pos]) { /* name type */
|
||||||
case 0x00: /* host_name */
|
case 0x00: /* host_name */
|
||||||
if(has_match(tls_data->sni_hostname_list, tls_data->sni_list_len, data + pos + 3, len)) {
|
if(has_match(tls_data->sni_hostname_list, tls_data->sni_list_len, data + pos + 3, len)) {
|
||||||
return len;
|
return (int)len;
|
||||||
} else {
|
} else {
|
||||||
return TLS_ENOEXT;
|
return TLS_ENOEXT;
|
||||||
}
|
}
|
||||||
@ -253,7 +253,7 @@ parse_alpn_extension(const struct TLSProtocol *tls_data, const char *data, size_
|
|||||||
return TLS_EPROTOCOL;
|
return TLS_EPROTOCOL;
|
||||||
|
|
||||||
if (len > 0 && has_match(tls_data->alpn_protocol_list, tls_data->alpn_list_len, data + pos + 1, len)) {
|
if (len > 0 && has_match(tls_data->alpn_protocol_list, tls_data->alpn_list_len, data + pos + 1, len)) {
|
||||||
return len;
|
return (int)len;
|
||||||
} else if (len > 0) {
|
} else if (len > 0) {
|
||||||
print_message(msg_probe_error, "Unknown ALPN name: %.*s\n", (int)len, data + pos + 1);
|
print_message(msg_probe_error, "Unknown ALPN name: %.*s\n", (int)len, data + pos + 1);
|
||||||
}
|
}
|
||||||
@ -301,11 +301,11 @@ struct TLSProtocol *
|
|||||||
tls_data_set_list(struct TLSProtocol *tls_data, int alpn, const char** list, size_t list_len) {
|
tls_data_set_list(struct TLSProtocol *tls_data, int alpn, const char** list, size_t list_len) {
|
||||||
if (alpn) {
|
if (alpn) {
|
||||||
tls_data->alpn_protocol_list = list;
|
tls_data->alpn_protocol_list = list;
|
||||||
tls_data->alpn_list_len = list_len;
|
tls_data->alpn_list_len = (int)list_len;
|
||||||
tls_data->match_mode.tls_match_alpn = 1;
|
tls_data->match_mode.tls_match_alpn = 1;
|
||||||
} else {
|
} else {
|
||||||
tls_data->sni_hostname_list = list;
|
tls_data->sni_hostname_list = list;
|
||||||
tls_data->sni_list_len = list_len;
|
tls_data->sni_list_len = (int)list_len;
|
||||||
tls_data->match_mode.tls_match_sni = 1;
|
tls_data->match_mode.tls_match_sni = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,8 @@ struct connection* udp_c2s_forward(int sockfd, struct loop_info* fd_info)
|
|||||||
struct connection* cnx;
|
struct connection* cnx;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
int res, target, out = -1;
|
ssize_t res;
|
||||||
|
int target, out = -1;
|
||||||
char data[65536]; /* Theoretical max is 65507 (https://en.wikipedia.org/wiki/User_Datagram_Protocol).
|
char data[65536]; /* Theoretical max is 65507 (https://en.wikipedia.org/wiki/User_Datagram_Protocol).
|
||||||
This will do. Dynamic allocation is possible with the MSG_PEEK flag in recvfrom(2), but that'd imply
|
This will do. Dynamic allocation is possible with the MSG_PEEK flag in recvfrom(2), but that'd imply
|
||||||
malloc/free overhead for each packet, when really 64K is not that much */
|
malloc/free overhead for each packet, when really 64K is not that much */
|
||||||
@ -280,7 +281,7 @@ struct connection* udp_c2s_forward(int sockfd, struct loop_info* fd_info)
|
|||||||
len, target, sprintaddr(addr_str, sizeof(addr_str), &addrinfo));
|
len, target, sprintaddr(addr_str, sizeof(addr_str), &addrinfo));
|
||||||
|
|
||||||
if (target == -1) {
|
if (target == -1) {
|
||||||
res = probe_buffer(data, len, udp_protocols, udp_protocols_len, &proto);
|
res = probe_buffer(data, (int)len, udp_protocols, udp_protocols_len, &proto);
|
||||||
/* First version: if we can't work out the protocol from the first
|
/* First version: if we can't work out the protocol from the first
|
||||||
* packet, drop it. Conceivably, we could store several packets to
|
* packet, drop it. Conceivably, we could store several packets to
|
||||||
* run probes on packet sets */
|
* run probes on packet sets */
|
||||||
@ -324,7 +325,7 @@ void udp_s2c_forward(struct connection* cnx)
|
|||||||
{
|
{
|
||||||
int sockfd = cnx->target_sock;
|
int sockfd = cnx->target_sock;
|
||||||
char data[65536];
|
char data[65536];
|
||||||
int res;
|
ssize_t res;
|
||||||
|
|
||||||
res = recvfrom(sockfd, data, sizeof(data), 0, NULL, NULL);
|
res = recvfrom(sockfd, data, sizeof(data), 0, NULL, NULL);
|
||||||
if ((res == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))) return;
|
if ((res == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))) return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user