Hoernchen has uploaded this change for review. ( 
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:

Change-Id: I547d900ba88c60bae5b53345e1aee104bacd310d
---
M src/input/lapd_pcap.c
1 file changed, 22 insertions(+), 19 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/08/30908/1

diff --git a/src/input/lapd_pcap.c b/src/input/lapd_pcap.c
index 6e1faf5..e44b42e 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: 1
Gerrit-Owner: Hoernchen <[email protected]>
Gerrit-MessageType: newchange

Reply via email to