libc: check raw IP socket type before using it
Previously, the libc sendto(3) and recvfrom(3) implementations would blindly assume that any unrecognized socket is a raw-IP socket. This is not only inconsistent but also messes with returned error codes. Change-Id: Id0328f04ea8ca0968a4e8636bc441caa0c3579b7
This commit is contained in:
parent
5ef5b27fc1
commit
17580212b4
@ -19,6 +19,7 @@
|
||||
#include <net/gen/udp_io.h>
|
||||
|
||||
#include <net/gen/ip_hdr.h>
|
||||
#include <net/gen/ip_io.h>
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
@ -42,6 +43,7 @@ ssize_t recvfrom(int sock, void *__restrict buffer, size_t length,
|
||||
int r;
|
||||
nwio_tcpconf_t tcpconf;
|
||||
nwio_udpopt_t udpopt;
|
||||
nwio_ipopt_t ipopt;
|
||||
struct sockaddr_un uds_addr;
|
||||
int uds_sotype = -1;
|
||||
|
||||
@ -85,11 +87,17 @@ ssize_t recvfrom(int sock, void *__restrict buffer, size_t length,
|
||||
}
|
||||
}
|
||||
|
||||
r= ioctl(sock, NWIOGIPOPT, &ipopt);
|
||||
if (r != -1 || errno != ENOTTY)
|
||||
{
|
||||
ip_hdr_t *ip_hdr;
|
||||
int rd;
|
||||
struct sockaddr_in sin;
|
||||
|
||||
if (r == -1) {
|
||||
return r;
|
||||
}
|
||||
|
||||
rd = read(sock, buffer, length);
|
||||
|
||||
if(rd < 0) return rd;
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include <net/gen/in.h>
|
||||
#include <net/gen/ip_hdr.h>
|
||||
#include <net/gen/ip_io.h>
|
||||
#include <net/gen/tcp.h>
|
||||
#include <net/gen/tcp_io.h>
|
||||
#include <net/gen/udp.h>
|
||||
@ -37,6 +38,7 @@ ssize_t sendto(int sock, const void *message, size_t length, int flags,
|
||||
int r;
|
||||
nwio_tcpopt_t tcpopt;
|
||||
nwio_udpopt_t udpopt;
|
||||
nwio_ipopt_t ipopt;
|
||||
int uds_sotype = -1;
|
||||
|
||||
r= ioctl(sock, NWIOGTCPOPT, &tcpopt);
|
||||
@ -75,12 +77,18 @@ ssize_t sendto(int sock, const void *message, size_t length, int flags,
|
||||
}
|
||||
}
|
||||
|
||||
r= ioctl(sock, NWIOGIPOPT, &ipopt);
|
||||
if (r != -1 || errno != ENOTTY)
|
||||
{
|
||||
ip_hdr_t *ip_hdr;
|
||||
const struct sockaddr_in *sinp;
|
||||
ssize_t retval;
|
||||
int saved_errno;
|
||||
|
||||
if (r == -1) {
|
||||
return r;
|
||||
}
|
||||
|
||||
sinp = (const struct sockaddr_in *)dest_addr;
|
||||
if (sinp->sin_family != AF_INET)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user