|
@@ -474,7 +474,8 @@ static int tcp_open (PAL_HANDLE *handle, const char * type, const char * uri,
|
|
}
|
|
}
|
|
|
|
|
|
/* 'read' operation of tcp stream */
|
|
/* 'read' operation of tcp stream */
|
|
-static int tcp_read (PAL_HANDLE handle, int offset, int len, void * buf)
|
|
|
|
|
|
+static int64_t tcp_read (PAL_HANDLE handle, uint64_t offset, uint64_t len,
|
|
|
|
+ void * buf)
|
|
{
|
|
{
|
|
if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
|
|
if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
@@ -482,6 +483,9 @@ static int tcp_read (PAL_HANDLE handle, int offset, int len, void * buf)
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
return -PAL_ERROR_ENDOFSTREAM;
|
|
return -PAL_ERROR_ENDOFSTREAM;
|
|
|
|
|
|
|
|
+ if (len >= (1ULL << (sizeof(unsigned int) * 8)))
|
|
|
|
+ return -PAL_ERROR_INVAL;
|
|
|
|
+
|
|
int bytes = ocall_sock_recv(handle->sock.fd, buf, len, NULL, NULL);
|
|
int bytes = ocall_sock_recv(handle->sock.fd, buf, len, NULL, NULL);
|
|
|
|
|
|
if (bytes < 0)
|
|
if (bytes < 0)
|
|
@@ -494,7 +498,8 @@ static int tcp_read (PAL_HANDLE handle, int offset, int len, void * buf)
|
|
}
|
|
}
|
|
|
|
|
|
/* write' operation of tcp stream */
|
|
/* write' operation of tcp stream */
|
|
-static int tcp_write (PAL_HANDLE handle, int offset, int len, const void * buf)
|
|
|
|
|
|
+static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
|
|
|
|
+ const void * buf)
|
|
{
|
|
{
|
|
if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
|
|
if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
@@ -502,6 +507,9 @@ static int tcp_write (PAL_HANDLE handle, int offset, int len, const void * buf)
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
return -PAL_ERROR_CONNFAILED;
|
|
return -PAL_ERROR_CONNFAILED;
|
|
|
|
|
|
|
|
+ if (len >= (1ULL << (sizeof(unsigned int) * 8)))
|
|
|
|
+ return -PAL_ERROR_INVAL;
|
|
|
|
+
|
|
int bytes = ocall_sock_send(handle->sock.fd, buf, len, NULL, 0);
|
|
int bytes = ocall_sock_send(handle->sock.fd, buf, len, NULL, 0);
|
|
|
|
|
|
if (bytes == -PAL_ERROR_TRYAGAIN)
|
|
if (bytes == -PAL_ERROR_TRYAGAIN)
|
|
@@ -621,7 +629,8 @@ static int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri,
|
|
return -PAL_ERROR_NOTSUPPORT;
|
|
return -PAL_ERROR_NOTSUPPORT;
|
|
}
|
|
}
|
|
|
|
|
|
-static int udp_receive (PAL_HANDLE handle, int offset, int len, void * buf)
|
|
|
|
|
|
+static int64_t udp_receive (PAL_HANDLE handle, uint64_t offset, uint64_t len,
|
|
|
|
+ void * buf)
|
|
{
|
|
{
|
|
if (!IS_HANDLE_TYPE(handle, udp))
|
|
if (!IS_HANDLE_TYPE(handle, udp))
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
@@ -629,11 +638,14 @@ static int udp_receive (PAL_HANDLE handle, int offset, int len, void * buf)
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
return -PAL_ERROR_BADHANDLE;
|
|
return -PAL_ERROR_BADHANDLE;
|
|
|
|
|
|
|
|
+ if (len >= (1ULL << (sizeof(unsigned int) * 8)))
|
|
|
|
+ return -PAL_ERROR_INVAL;
|
|
|
|
+
|
|
return ocall_sock_recv(handle->sock.fd, buf, len, NULL, NULL);
|
|
return ocall_sock_recv(handle->sock.fd, buf, len, NULL, NULL);
|
|
}
|
|
}
|
|
|
|
|
|
-static int udp_receivebyaddr (PAL_HANDLE handle, int offset, int len,
|
|
|
|
- void * buf, char * addr, int addrlen)
|
|
|
|
|
|
+static int64_t udp_receivebyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
|
|
|
|
+ void * buf, char * addr, int addrlen)
|
|
{
|
|
{
|
|
if (!IS_HANDLE_TYPE(handle, udpsrv))
|
|
if (!IS_HANDLE_TYPE(handle, udpsrv))
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
@@ -641,6 +653,9 @@ static int udp_receivebyaddr (PAL_HANDLE handle, int offset, int len,
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
return -PAL_ERROR_BADHANDLE;
|
|
return -PAL_ERROR_BADHANDLE;
|
|
|
|
|
|
|
|
+ if (len >= (1ULL << (sizeof(unsigned int) * 8)))
|
|
|
|
+ return -PAL_ERROR_INVAL;
|
|
|
|
+
|
|
struct sockaddr conn_addr;
|
|
struct sockaddr conn_addr;
|
|
socklen_t conn_addrlen = sizeof(struct sockaddr);
|
|
socklen_t conn_addrlen = sizeof(struct sockaddr);
|
|
|
|
|
|
@@ -662,7 +677,8 @@ static int udp_receivebyaddr (PAL_HANDLE handle, int offset, int len,
|
|
return bytes;
|
|
return bytes;
|
|
}
|
|
}
|
|
|
|
|
|
-static int udp_send (PAL_HANDLE handle, int offset, int len, const void * buf)
|
|
|
|
|
|
+static int64_t udp_send (PAL_HANDLE handle, uint64_t offset, uint64_t len,
|
|
|
|
+ const void * buf)
|
|
{
|
|
{
|
|
if (!IS_HANDLE_TYPE(handle, udp))
|
|
if (!IS_HANDLE_TYPE(handle, udp))
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
@@ -670,6 +686,9 @@ static int udp_send (PAL_HANDLE handle, int offset, int len, const void * buf)
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
if (handle->sock.fd == PAL_IDX_POISON)
|
|
return -PAL_ERROR_BADHANDLE;
|
|
return -PAL_ERROR_BADHANDLE;
|
|
|
|
|
|
|
|
+ if (len >= (1ULL << (sizeof(unsigned int) * 8)))
|
|
|
|
+ return -PAL_ERROR_INVAL;
|
|
|
|
+
|
|
int bytes = ocall_sock_send(handle->sock.fd, buf, len, NULL, 0);
|
|
int bytes = ocall_sock_send(handle->sock.fd, buf, len, NULL, 0);
|
|
|
|
|
|
if (bytes == -PAL_ERROR_TRYAGAIN)
|
|
if (bytes == -PAL_ERROR_TRYAGAIN)
|
|
@@ -686,8 +705,8 @@ static int udp_send (PAL_HANDLE handle, int offset, int len, const void * buf)
|
|
return bytes;
|
|
return bytes;
|
|
}
|
|
}
|
|
|
|
|
|
-static int udp_sendbyaddr (PAL_HANDLE handle, int offset, int len,
|
|
|
|
- const void * buf, const char * addr, int addrlen)
|
|
|
|
|
|
+static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
|
|
|
|
+ const void * buf, const char * addr, int addrlen)
|
|
{
|
|
{
|
|
if (!IS_HANDLE_TYPE(handle, udpsrv))
|
|
if (!IS_HANDLE_TYPE(handle, udpsrv))
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
return -PAL_ERROR_NOTCONNECTION;
|
|
@@ -698,6 +717,9 @@ static int udp_sendbyaddr (PAL_HANDLE handle, int offset, int len,
|
|
if (!strpartcmp_static(addr, "udp:"))
|
|
if (!strpartcmp_static(addr, "udp:"))
|
|
return -PAL_ERROR_INVAL;
|
|
return -PAL_ERROR_INVAL;
|
|
|
|
|
|
|
|
+ if (len >= (1ULL << (sizeof(unsigned int) * 8)))
|
|
|
|
+ return -PAL_ERROR_INVAL;
|
|
|
|
+
|
|
addr += static_strlen("udp:");
|
|
addr += static_strlen("udp:");
|
|
addrlen -= static_strlen("udp:");
|
|
addrlen -= static_strlen("udp:");
|
|
|
|
|
|
@@ -1036,12 +1058,15 @@ PAL_HANDLE _DkBroadcastStreamOpen (void)
|
|
return hdl;
|
|
return hdl;
|
|
}
|
|
}
|
|
|
|
|
|
-static int mcast_send (PAL_HANDLE handle, int offset, int size,
|
|
|
|
- const void * buf)
|
|
|
|
|
|
+static int64_t mcast_send (PAL_HANDLE handle, uint64_t offset, uint64_t size,
|
|
|
|
+ const void * buf)
|
|
{
|
|
{
|
|
if (handle->mcast.srv == PAL_IDX_POISON)
|
|
if (handle->mcast.srv == PAL_IDX_POISON)
|
|
return -PAL_ERROR_BADHANDLE;
|
|
return -PAL_ERROR_BADHANDLE;
|
|
|
|
|
|
|
|
+ if (size >= (1ULL << (sizeof(unsigned int) * 8)))
|
|
|
|
+ return -PAL_ERROR_INVAL;
|
|
|
|
+
|
|
int bytes = ocall_sock_send(handle->mcast.srv, buf, size,
|
|
int bytes = ocall_sock_send(handle->mcast.srv, buf, size,
|
|
NULL, 0);
|
|
NULL, 0);
|
|
|
|
|
|
@@ -1059,11 +1084,15 @@ static int mcast_send (PAL_HANDLE handle, int offset, int size,
|
|
return bytes;
|
|
return bytes;
|
|
}
|
|
}
|
|
|
|
|
|
-static int mcast_receive (PAL_HANDLE handle, int offset, int size, void * buf)
|
|
|
|
|
|
+static int64_t mcast_receive (PAL_HANDLE handle, uint64_t offset, uint64_t size,
|
|
|
|
+ void * buf)
|
|
{
|
|
{
|
|
if (handle->mcast.cli == PAL_IDX_POISON)
|
|
if (handle->mcast.cli == PAL_IDX_POISON)
|
|
return -PAL_ERROR_BADHANDLE;
|
|
return -PAL_ERROR_BADHANDLE;
|
|
|
|
|
|
|
|
+ if (size >= (1ULL << (sizeof(unsigned int) * 8)))
|
|
|
|
+ return -PAL_ERROR_INVAL;
|
|
|
|
+
|
|
int bytes = ocall_sock_recv(handle->mcast.cli, buf, size, NULL,
|
|
int bytes = ocall_sock_recv(handle->mcast.cli, buf, size, NULL,
|
|
NULL);
|
|
NULL);
|
|
|
|
|