diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-09-01 08:52:55 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-01 08:52:55 +0300 |
| commit | 57ae56148c5519b9207ede623098d3cfad5211b8 (patch) | |
| tree | 78dbd6a720ad8bb727ed50c53af1c2e96d779bd3 | |
| parent | 40575b78b7bb043c7a0ff4dd29a048be056dee9f (diff) | |
| parent | 3b228d5c750ba76694bacf75e7be40a024927a31 (diff) | |
| download | accel-ppp-57ae56148c5519b9207ede623098d3cfad5211b8.tar.gz accel-ppp-57ae56148c5519b9207ede623098d3cfad5211b8.zip | |
Merge pull request #351 from nuclearcat/various-fixes-on-compiler-warnings
Various fixes on compiler warnings
| -rw-r--r-- | accel-pppd/ctrl/ipoe/dhcpv4_options.c | 33 | ||||
| -rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 8 | ||||
| -rw-r--r-- | accel-pppd/ipv6/dhcpv6_packet.c | 34 | ||||
| -rw-r--r-- | accel-pppd/triton/list.h | 4 |
4 files changed, 55 insertions, 24 deletions
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4_options.c b/accel-pppd/ctrl/ipoe/dhcpv4_options.c index bffcfa5c..042a7406 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4_options.c +++ b/accel-pppd/ctrl/ipoe/dhcpv4_options.c @@ -265,7 +265,9 @@ static void print_classless_route(const struct dhcpv4_option *opt, int elem_size { const uint8_t *ptr = opt->data; const uint8_t *endptr = ptr + opt->len; - int mask, i, mask1 = 0; + unsigned int prefix_len, i; + int mask; + uint32_t mask1; uint32_t ip; uint32_t gw; @@ -274,20 +276,23 @@ static void print_classless_route(const struct dhcpv4_option *opt, int elem_size print(","); mask = *ptr++; - ip = ntohl(*(uint32_t *)ptr); - for (i = 0; i < mask; i++) - mask1 |= (1 << (32 - i)); + if (mask > 32) + return; + + prefix_len = (mask + 7) / 8; + if ((size_t)(endptr - ptr) < prefix_len + sizeof(gw)) + return; + + ip = 0; + for (i = 0; i < prefix_len; i++) + ip |= (uint32_t)ptr[i] << (24 - i * 8); + mask1 = mask ? UINT32_MAX << (32 - mask) : 0; ip &= mask1; - if (mask <= 8) - ptr++; - else if (mask <= 16) - ptr += 2; - else if (mask <= 24) - ptr += 3; - else - ptr += 4; - gw = ntohl(*(uint32_t *)ptr); - ptr += 4; + ptr += prefix_len; + + memcpy(&gw, ptr, sizeof(gw)); + gw = ntohl(gw); + ptr += sizeof(gw); print("%i.%i.%i.%i/%i via %i.%i.%i.%i", (ip >> 24) & 0xff, diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 18e9228d..1e3f7054 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -3814,6 +3814,7 @@ static void parse_local_net(const char *opt) char str[17]; in_addr_t addr; int mask; + unsigned long val; char *endptr; struct local_net *n; @@ -3824,9 +3825,10 @@ static void parse_local_net(const char *opt) addr = inet_addr(str); if (addr == INADDR_NONE) goto out_err; - mask = strtoul(ptr + 1, &endptr, 10); - if (mask > 32) + val = strtoul(ptr + 1, &endptr, 10); + if (*endptr || val > 32) goto out_err; + mask = val; } else { addr = inet_addr(opt); if (addr == INADDR_NONE) @@ -3834,7 +3836,7 @@ static void parse_local_net(const char *opt) mask = 24; } - mask = htonl(mask ? ~0 << (32 - mask) : 0); + mask = htonl(mask ? UINT32_MAX << (32 - mask) : 0); addr = addr & mask; list_for_each_entry(n, &local_nets, entry) { diff --git a/accel-pppd/ipv6/dhcpv6_packet.c b/accel-pppd/ipv6/dhcpv6_packet.c index e0f2b5d9..c0c7bc81 100644 --- a/accel-pppd/ipv6/dhcpv6_packet.c +++ b/accel-pppd/ipv6/dhcpv6_packet.c @@ -133,6 +133,8 @@ struct dhcpv6_packet *dhcpv6_packet_parse(const void *buf, size_t size) endptr = ((void *)pkt->hdr) + size; while (pkt->hdr->type == D6_RELAY_FORW) { + struct dhcpv6_msg_hdr *prev_hdr = pkt->hdr; + rhdr = (struct dhcpv6_relay_hdr *)pkt->hdr; if (((void *)rhdr) + sizeof(*rhdr) > endptr) { log_warn("dhcpv6: invalid packet received\n"); @@ -162,11 +164,16 @@ struct dhcpv6_packet *dhcpv6_packet_parse(const void *buf, size_t size) if (opth->code == htons(D6_OPTION_RELAY_MSG)) { pkt->hdr = (struct dhcpv6_msg_hdr *)opth->data; - endptr = opth->data + sizeof(*opth) + ntohs(opth->len); + endptr = opth->data + ntohs(opth->len); } ptr += sizeof(*opth) + ntohs(opth->len); } + + if (pkt->hdr == prev_hdr) { + log_warn("dhcpv6: invalid packet received\n"); + goto error; + } } ptr = pkt->hdr->data; @@ -491,12 +498,21 @@ static void print_hex_array(struct dhcpv6_option *opt, void (*print)(const char static void print_uint8(struct dhcpv6_option *opt, void (*print)(const char *fmt, ...)) { + if (ntohs(opt->hdr->len) < sizeof(uint8_t)) + return; + print(" %i", *(uint8_t *)opt->hdr->data); } static void print_time(struct dhcpv6_option *opt, void (*print)(const char *fmt, ...)) { - print(" %u", *(uint32_t *)opt->hdr->data); + uint16_t val; + + if (ntohs(opt->hdr->len) < sizeof(val)) + return; + + memcpy(&val, opt->hdr->data, sizeof(val)); + print(" %u", ntohs(val)); } static void print_ipv6addr(struct dhcpv6_option *opt, void (*print)(const char *fmt, ...)) @@ -531,14 +547,20 @@ static void print_status(struct dhcpv6_option *opt, void (*print)(const char *fm "NoAddrsAvail", "NoBindings", "NotOnLink", - "UseMulticast" + "UseMulticast", "NoPrefixAvail" }; + unsigned int code; + + if ((unsigned int)ntohs(opt->hdr->len) < sizeof(o->code)) + return; + + code = ntohs(o->code); - if (ntohs(o->code) < 0 || ntohs(o->code) > sizeof(status_name)) - print(" %u", ntohs(o->code)); + if (code >= sizeof(status_name) / sizeof(status_name[0])) + print(" %u", code); else - print(" %s", status_name[ntohs(o->code)]); + print(" %s", status_name[code]); } static void print_reconf(struct dhcpv6_option *opt, void (*print)(const char *fmt, ...)) diff --git a/accel-pppd/triton/list.h b/accel-pppd/triton/list.h index 20b917d4..6352aa82 100644 --- a/accel-pppd/triton/list.h +++ b/accel-pppd/triton/list.h @@ -1,6 +1,8 @@ #ifndef _LINUX_LIST_H #define _LINUX_LIST_H +#include <stddef.h> + //#if defined(__KERNEL__) || defined(_LVM_H_INCLUDE) //#include <linux/prefetch.h> @@ -211,7 +213,7 @@ static inline void list_splice_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + ((type *)((char *)(ptr)-offsetof(type, member))) /** * list_first_entry - get the first element from a list |
