Skip to content

Commit

Permalink
update amalgamation
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Jul 12, 2024
1 parent bdafb4b commit 8471142
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
28 changes: 24 additions & 4 deletions amalgamation/toxcore_amalgamation.c
Original file line number Diff line number Diff line change
Expand Up @@ -39769,6 +39769,9 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)

#elif !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && (defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__))

non_null()
static bool ip4_is_local(const IP4 *ip4);

non_null()
static Broadcast_Info *fetch_broadcast_info(const Network *ns)
{
Expand Down Expand Up @@ -39811,7 +39814,9 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
const int n = ifc.ifc_len / sizeof(struct ifreq);

for (int i = 0; i < n; ++i) {
/* there are interfaces with are incapable of broadcast */
/* there are interfaces with are incapable of broadcast
* on Linux, `lo` has no broadcast address, but this function returns >=0
*/
if (ioctl(sock.sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) {
continue;
}
Expand All @@ -39821,18 +39826,33 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
continue;
}

const struct sockaddr_in *sock4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_broadaddr;
const struct sockaddr_in *broadaddr4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_broadaddr;

if (broadcast->count >= MAX_INTERFACES) {
break;
}

IP *ip = &broadcast->ips[broadcast->count];
ip->family = net_family_ipv4();
ip->ip.v4.uint32 = sock4->sin_addr.s_addr;
ip->ip.v4.uint32 = broadaddr4->sin_addr.s_addr;

/* if no broadcast address */
if (ip->ip.v4.uint32 == 0) {
continue;
if (ioctl(sock.sock, SIOCGIFADDR, &i_faces[i]) < 0) {
continue;
}

const struct sockaddr_in *addr4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_addr;
IP4 ip4_staging;
ip4_staging.uint32 = addr4->sin_addr.s_addr;

if (ip4_is_local(&ip4_staging)) {
/* this is 127.x.x.x */
ip->ip.v4.uint32 = ip4_staging.uint32;
} else {
/* give up. */
continue;
}
}

++broadcast->count;
Expand Down
28 changes: 24 additions & 4 deletions amalgamation/toxcore_amalgamation_no_toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -37269,6 +37269,9 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)

#elif !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && (defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__))

non_null()
static bool ip4_is_local(const IP4 *ip4);

non_null()
static Broadcast_Info *fetch_broadcast_info(const Network *ns)
{
Expand Down Expand Up @@ -37311,7 +37314,9 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
const int n = ifc.ifc_len / sizeof(struct ifreq);

for (int i = 0; i < n; ++i) {
/* there are interfaces with are incapable of broadcast */
/* there are interfaces with are incapable of broadcast
* on Linux, `lo` has no broadcast address, but this function returns >=0
*/
if (ioctl(sock.sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) {
continue;
}
Expand All @@ -37321,18 +37326,33 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
continue;
}

const struct sockaddr_in *sock4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_broadaddr;
const struct sockaddr_in *broadaddr4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_broadaddr;

if (broadcast->count >= MAX_INTERFACES) {
break;
}

IP *ip = &broadcast->ips[broadcast->count];
ip->family = net_family_ipv4();
ip->ip.v4.uint32 = sock4->sin_addr.s_addr;
ip->ip.v4.uint32 = broadaddr4->sin_addr.s_addr;

/* if no broadcast address */
if (ip->ip.v4.uint32 == 0) {
continue;
if (ioctl(sock.sock, SIOCGIFADDR, &i_faces[i]) < 0) {
continue;
}

const struct sockaddr_in *addr4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_addr;
IP4 ip4_staging;
ip4_staging.uint32 = addr4->sin_addr.s_addr;

if (ip4_is_local(&ip4_staging)) {
/* this is 127.x.x.x */
ip->ip.v4.uint32 = ip4_staging.uint32;
} else {
/* give up. */
continue;
}
}

++broadcast->count;
Expand Down

0 comments on commit 8471142

Please sign in to comment.