Hoernchen has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-abis/+/30908 ) Change subject: lapd_pcap: fix illegal VLA within struct ...................................................................... lapd_pcap: fix illegal VLA within struct Another weird and unique gcc supported extension, clang complains: CC input/lapd_pcap.lo input/lapd_pcap.c:134:8: error: fields must have a constant size: 'variable length array in structure' extension will never be supported char buf[msg->len]; ^ The kernel has been VLA-free since 2018, let's try not to make it worse. Change-Id: I547d900ba88c60bae5b53345e1aee104bacd310d --- M src/input/lapd_pcap.c 1 file changed, 22 insertions(+), 19 deletions(-) Approvals: dexter: Looks good to me, approved pespin: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/src/input/lapd_pcap.c b/src/input/lapd_pcap.c index 6e1faf5..f9d17ef 100644 --- a/src/input/lapd_pcap.c +++ b/src/input/lapd_pcap.c @@ -128,44 +128,47 @@ int osmo_pcap_lapd_write(int fd, int direction, struct msgb *msg) { struct timeval tv; - struct { + struct tmp_pkt { struct pcap_rechdr pcap_rechdr; struct pcap_lapdhdr header; - char buf[msg->len]; - } __attribute__((packed)) s; + char buf[0]; + } __attribute__((packed)); + const unsigned int total_pkt_len = sizeof(struct tmp_pkt) + msg->len; + + struct tmp_pkt *s = alloca(total_pkt_len); /* PCAP file has not been opened, skip. */ if (fd < 0) return 0; - memset(&s, 0, sizeof(s)); + memset(s, 0, total_pkt_len); - s.pcap_rechdr.ts_sec = 0; - s.pcap_rechdr.ts_usec = 0; - s.pcap_rechdr.incl_len = msg->len + sizeof(struct pcap_lapdhdr); - s.pcap_rechdr.orig_len = msg->len + sizeof(struct pcap_lapdhdr); + s->pcap_rechdr.ts_sec = 0; + s->pcap_rechdr.ts_usec = 0; + s->pcap_rechdr.incl_len = msg->len + sizeof(struct pcap_lapdhdr); + s->pcap_rechdr.orig_len = msg->len + sizeof(struct pcap_lapdhdr); if (direction == OSMO_LAPD_PCAP_OUTPUT) - s.header.pkttype = htons(LINUX_SLL_OUTGOING); + s->header.pkttype = htons(LINUX_SLL_OUTGOING); else - s.header.pkttype = htons(LINUX_SLL_HOST); - s.header.hatype = 0; - s.header.halen = 0; - s.header.addr[0] = 0x01; /* we are the network side */ - s.header.protocol = ntohs(48); + s->header.pkttype = htons(LINUX_SLL_HOST); + s->header.hatype = 0; + s->header.halen = 0; + s->header.addr[0] = 0x01; /* we are the network side */ + s->header.protocol = ntohs(48); gettimeofday(&tv, NULL); - s.pcap_rechdr.ts_sec = tv.tv_sec; - s.pcap_rechdr.ts_usec = tv.tv_usec; + s->pcap_rechdr.ts_sec = tv.tv_sec; + s->pcap_rechdr.ts_usec = tv.tv_usec; - memcpy(s.buf, msg->data, msg->len); + memcpy(s->buf, msg->data, msg->len); - if (write(fd, &s, sizeof(s)) != sizeof(s)) { + if (write(fd, s, total_pkt_len) != total_pkt_len) { LOGP(DLLAPD, LOGL_ERROR, "cannot write packet to PCAP: %s\n", strerror(errno)); return -1; } - return sizeof(s); + return total_pkt_len; } int osmo_pcap_lapd_close(int fd) -- To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/30908 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-abis Gerrit-Branch: master Gerrit-Change-Id: I547d900ba88c60bae5b53345e1aee104bacd310d Gerrit-Change-Number: 30908 Gerrit-PatchSet: 4 Gerrit-Owner: Hoernchen <ewild@sysmocom.de> Gerrit-Reviewer: Hoernchen <ewild@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier@sysmocom.de> Gerrit-Reviewer: laforge <laforge@osmocom.org> Gerrit-Reviewer: pespin <pespin@sysmocom.de> Gerrit-MessageType: merged