now that gcc 11's static analyzer looks at array bounds in arguments
like "char ip[4]", let's be more strict about that
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include "fmt.h"
|
||||
#include "socket.h"
|
||||
|
||||
size_t fmt_ip6if(char* dest,const char* ip,uint32 scope_id) {
|
||||
size_t fmt_ip6if(char* dest,const char ip[16],uint32 scope_id) {
|
||||
size_t i=fmt_ip6(dest,ip);
|
||||
if (scope_id) {
|
||||
if (dest) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "socket.h"
|
||||
#include "havealloca.h"
|
||||
|
||||
size_t scan_ip6if(const char* src,char* ip,uint32* scope_id) {
|
||||
size_t scan_ip6if(const char* src,char ip[16],uint32* scope_id) {
|
||||
size_t i=scan_ip6(src,ip);
|
||||
*scope_id=0;
|
||||
if (src[i]=='%') {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "io_internal.h"
|
||||
#endif
|
||||
|
||||
int socket_accept4(int s,char *ip,uint16 *port) {
|
||||
int socket_accept4(int s,char ip[4],uint16 *port) {
|
||||
struct sockaddr_in si;
|
||||
socklen_t len = sizeof si;
|
||||
int fd;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string.h>
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
#include "iarray.h"
|
||||
#include "havesl.h"
|
||||
|
||||
#ifdef __MINGW32__
|
||||
@@ -22,13 +23,13 @@
|
||||
|
||||
#include "haveaccept4.h"
|
||||
|
||||
int socket_accept4_flags(int s, char *ip, uint16 *port, int flags) {
|
||||
int socket_accept4_flags(int s, char ip[4], uint16 *port, int flags) {
|
||||
struct sockaddr_in si;
|
||||
socklen_t len = sizeof si;
|
||||
int fd;
|
||||
|
||||
#ifdef __MINGW32__
|
||||
io_entry* e=array_get(&io_fds,sizeof(io_entry),s);
|
||||
io_entry* e=iarray_get(&io_fds,s);
|
||||
if (e && e->inuse) {
|
||||
int sa2len;
|
||||
fd=-1;
|
||||
@@ -42,14 +43,14 @@ incoming:
|
||||
{
|
||||
struct sockaddr* x,* y;
|
||||
GetAcceptExSockaddrs(e->inbuf,0,200,200,&x,&sa2len,&y,&len);
|
||||
if (len>sizeof(si)) len=sizeof(si);
|
||||
if ((size_t)len>sizeof(si)) len=sizeof(si);
|
||||
memcpy(&si,y,len);
|
||||
}
|
||||
fd=e->next_accept;
|
||||
e->next_accept=0;
|
||||
if (e->nonblock) {
|
||||
if (io_fd_canwrite(fd)) {
|
||||
io_entry* f=array_get(&io_fds,sizeof(io_entry),fd);
|
||||
io_entry* f=iarray_get(&io_fds,fd);
|
||||
if (f) {
|
||||
f->nonblock=1;
|
||||
// printf("setting fd %lu to non-blocking\n",(int)fd);
|
||||
@@ -61,7 +62,7 @@ incoming:
|
||||
/* no accept queued, queue one now. */
|
||||
if (e->next_accept==0) {
|
||||
e->next_accept=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
|
||||
if (e==-1)
|
||||
if (e->next_accept==(SOCKET)-1)
|
||||
return winsock2errno(-1);
|
||||
}
|
||||
if (AcceptEx(s,e->next_accept,e->inbuf,0,200,200,&e->errorcode,&e->or))
|
||||
@@ -98,6 +99,7 @@ incoming:
|
||||
/* if we get here, the kernel did not support accept4. */
|
||||
if ((fd=accept(s,(void*) &si,&len))==-1)
|
||||
return -1;
|
||||
#ifndef __MINGW32__
|
||||
if (flags & SOCKET_NONBLOCK) fl |= O_NDELAY;
|
||||
if (flags & SOCKET_CLOEXEC) fl |= O_CLOEXEC;
|
||||
/* On BSD the accepted socket inherits O_NDELAY and O_CLOEXEC, on
|
||||
@@ -114,6 +116,7 @@ incoming:
|
||||
#ifdef __linux__
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HAVE_ACCEPT4
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_accept4_makenonblocking(int s,char *ip,uint16 *port) {
|
||||
int socket_accept4_makenonblocking(int s,char ip[4],uint16 *port) {
|
||||
return socket_accept4_flags(s,ip,port,SOCKET_NONBLOCK);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_accept4_makenonblocking(int s,char *ip,uint16 *port) {
|
||||
int socket_accept4_makenonblocking(int s,char ip[4],uint16 *port) {
|
||||
return socket_accept4_flags(s,ip,port,SOCKET_NONBLOCK | SOCKET_CLOEXEC);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_accept4_makenonblocking(int s,char *ip,uint16 *port) {
|
||||
int socket_accept4_makenonblocking(int s,char ip[4],uint16 *port) {
|
||||
return socket_accept4_flags(s,ip,port,SOCKET_CLOEXEC);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "io_internal.h"
|
||||
#endif
|
||||
|
||||
int socket_accept6(int s,char* ip,uint16* port,uint32* scope_id)
|
||||
int socket_accept6(int s,char ip[16],uint16* port,uint32* scope_id)
|
||||
{
|
||||
#ifdef LIBC_HAS_IP6
|
||||
struct sockaddr_in6 sa;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#define _GNU_SOURCE
|
||||
#ifdef __MINGW32__
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
@@ -9,6 +12,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include "iarray.h"
|
||||
#include "windoze.h"
|
||||
#include "byte.h"
|
||||
#include "socket.h"
|
||||
@@ -27,7 +31,7 @@
|
||||
|
||||
#include "haveaccept4.h"
|
||||
|
||||
int socket_accept6_flags(int s, char* ip, uint16* port, uint32* scope_id, int flags)
|
||||
int socket_accept6_flags(int s, char ip[16], uint16* port, uint32* scope_id, int flags)
|
||||
{
|
||||
#ifdef LIBC_HAS_IP6
|
||||
struct sockaddr_in6 sa;
|
||||
@@ -39,7 +43,7 @@ int socket_accept6_flags(int s, char* ip, uint16* port, uint32* scope_id, int fl
|
||||
|
||||
#ifdef __MINGW32__
|
||||
// Windows uses overlapped I/O instead of non-blocking I/O
|
||||
io_entry* e=array_get(&io_fds,sizeof(io_entry),s);
|
||||
io_entry* e=iarray_get(&io_fds,s);
|
||||
if (e && e->inuse) {
|
||||
int sa2len;
|
||||
fd=-1;
|
||||
@@ -53,14 +57,14 @@ incoming:
|
||||
{
|
||||
struct sockaddr* x,* y;
|
||||
GetAcceptExSockaddrs(e->inbuf,0,200,200,&x,&sa2len,&y,&dummy);
|
||||
if (dummy>sizeof(sa)) dummy=sizeof(sa);
|
||||
if ((size_t)dummy>sizeof(sa)) dummy=sizeof(sa);
|
||||
memcpy(&sa,y,dummy);
|
||||
}
|
||||
fd=e->next_accept;
|
||||
e->next_accept=0;
|
||||
if (e->nonblock) {
|
||||
if (io_fd(fd)) {
|
||||
io_entry* f=array_get(&io_fds,sizeof(io_entry),fd);
|
||||
io_entry* f=iarray_get(&io_fds,fd);
|
||||
if (f) {
|
||||
f->nonblock=1;
|
||||
// printf("setting fd %lu to non-blocking\n",(int)fd);
|
||||
@@ -72,7 +76,7 @@ incoming:
|
||||
/* no accept queued, queue one now. */
|
||||
if (e->next_accept==0) {
|
||||
e->next_accept=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
|
||||
if (e==-1)
|
||||
if (e->next_accept==(SOCKET)-1)
|
||||
return winsock2errno(-1);
|
||||
}
|
||||
if (AcceptEx(s,e->next_accept,e->inbuf,0,200,200,&e->errorcode,&e->or))
|
||||
@@ -108,6 +112,7 @@ incoming:
|
||||
fd = accept(s, (struct sockaddr *) &sa, &dummy);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
#ifndef __MINGW32__
|
||||
if (flags & SOCKET_NONBLOCK) fl |= O_NDELAY;
|
||||
if (flags & SOCKET_CLOEXEC) fl |= O_CLOEXEC;
|
||||
/* On BSD the accepted socket inherits O_NDELAY and O_CLOEXEC, on
|
||||
@@ -124,6 +129,7 @@ incoming:
|
||||
#ifdef __linux__
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HAVE_ACCEPT4
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_accept6_makenonblocking(int s,char *ip,uint16 *port,uint32* scope_id) {
|
||||
int socket_accept6_makenonblocking(int s,char ip[16],uint16 *port,uint32* scope_id) {
|
||||
return socket_accept6_flags(s,ip,port,scope_id,SOCKET_NONBLOCK);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_accept6_makenonblocking(int s,char *ip,uint16 *port,uint32* scope_id) {
|
||||
int socket_accept6_makenonblocking(int s,char ip[16],uint16 *port,uint32* scope_id) {
|
||||
return socket_accept6_flags(s,ip,port,scope_id,SOCKET_NONBLOCK | SOCKET_CLOEXEC);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
#include "windoze.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_accept6_makenonblocking(int s,char *ip,uint16 *port,uint32* scope_id) {
|
||||
int socket_accept6_makenonblocking(int s,char ip[16],uint16 *port,uint32* scope_id) {
|
||||
return socket_accept6_flags(s,ip,port,scope_id,SOCKET_CLOEXEC);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "uint32.h"
|
||||
#include "socket.h"
|
||||
|
||||
int socket_bind4(int s,const char *ip,uint16 port) {
|
||||
int socket_bind4(int s,const char ip[4],uint16 port) {
|
||||
struct sockaddr_in si;
|
||||
byte_zero(&si,sizeof si);
|
||||
si.sin_family = AF_INET;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "socket.h"
|
||||
#include "windoze.h"
|
||||
|
||||
int socket_bind4_reuse(int s,const char *ip,uint16 port) {
|
||||
int socket_bind4_reuse(int s,const char ip[4],uint16 port) {
|
||||
int one=1;
|
||||
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
|
||||
#ifdef SO_REUSEPORT
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "socket.h"
|
||||
#include "windoze.h"
|
||||
|
||||
int socket_bind6_reuse(int s,const char *ip,uint16 port,uint32 scope_id) {
|
||||
int socket_bind6_reuse(int s,const char ip[16],uint16 port,uint32 scope_id) {
|
||||
int one=1;
|
||||
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
|
||||
#ifdef SO_REUSEPORT
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "uint16.h"
|
||||
#include "uint32.h"
|
||||
|
||||
int socket_connect4(int s,const char *ip,uint16 port) {
|
||||
int socket_connect4(int s,const char ip[4],uint16 port) {
|
||||
struct sockaddr_in si;
|
||||
byte_zero(&si,sizeof(si));
|
||||
si.sin_family=AF_INET;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
ssize_t socket_fastopen_connect4(int s,const char* ip,uint16 port,const char* buf,size_t len) {
|
||||
ssize_t socket_fastopen_connect4(int s,const char ip[4],uint16 port,const char* buf,size_t len) {
|
||||
int r;
|
||||
#ifndef MSG_FASTOPEN
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
ssize_t socket_fastopen_connect6(int s,const char* ip,uint16 port,uint32_t scope_id,const char* buf,size_t len) {
|
||||
ssize_t socket_fastopen_connect6(int s,const char ip[16],uint16 port,uint32_t scope_id,const char* buf,size_t len) {
|
||||
#ifndef MSG_FASTOPEN
|
||||
int r;
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user