Disable -Wformat-truncation and prevent potential string overflows.
authorShaun Ruffell <sruffell@sruffell.net>
Fri, 10 Aug 2018 03:27:40 +0000 (22:27 -0500)
committerShaun Ruffell <sruffell@sruffell.net>
Mon, 3 Sep 2018 15:27:18 +0000 (10:27 -0500)
GCC 7.3.0 complained about the potential to overflow the fixed size span and
channel names and descriptions. It also flagged potential truncations of the
strings.

The sprintf calls are now changed to snprintf to prevent the potential
overflows, but the warning about truncations are now disabled globally.

drivers/dahdi/Kbuild
drivers/dahdi/dahdi_dynamic.c
drivers/dahdi/wcte12xp/base.c
drivers/dahdi/wcte13xp-base.c
drivers/dahdi/wcte43x-base.c

index ee2cd59..25a8d37 100644 (file)
@@ -66,7 +66,7 @@ obj-m += dahdi_echocan_oslec.o
 obj-m += ../staging/echo/echo.o
 endif
 
-CFLAGS_MODULE += -I$(DAHDI_INCLUDE) -I$(src)
+CFLAGS_MODULE += -I$(DAHDI_INCLUDE) -I$(src) -Wno-format-truncation
 
 ifndef HOTPLUG_FIRMWARE
 ifneq (,$(filter y m,$(CONFIG_FW_LOADER)))
index 0a37e2a..7811f9d 100644 (file)
@@ -638,8 +638,8 @@ static int _create_dynamic(struct dahdi_dynamic_span *dds)
                DAHDI_CONFIG_HDB3 | DAHDI_CONFIG_CRC4 | DAHDI_CONFIG_NOTOPEN;
        d->span.ops = &dynamic_ops;
        for (x = 0; x < d->span.channels; x++) {
-               sprintf(d->chans[x]->name, "DYN/%s/%s/%d",
-                       dds->driver, dds->addr, x+1);
+               snprintf(d->chans[x]->name, sizeof(d->chans[x]->name),
+                        "DYN/%s/%s/%d", dds->driver, dds->addr, x+1);
                d->chans[x]->sigcap = DAHDI_SIG_EM | DAHDI_SIG_CLEAR |
                                      DAHDI_SIG_FXSLS | DAHDI_SIG_FXSKS |
                                      DAHDI_SIG_FXSGS | DAHDI_SIG_FXOLS |
index c327c5f..2164e63 100644 (file)
@@ -2069,7 +2069,8 @@ static int t1_software_init(struct t1 *wc, enum linemode type)
        t4_serial_setup(wc);
        set_bit(DAHDI_FLAGBIT_RBS, &wc->span.flags);
        for (x = 0; x < wc->span.channels; x++) {
-               sprintf(wc->chans[x]->name, "%s/%d", wc->span.name, x + 1);
+               snprintf(wc->chans[x]->name, sizeof(wc->chans[x]->name),
+                        "%s/%d", wc->span.name, x + 1);
                t1_chan_set_sigcap(&wc->span, x);
                wc->chans[x]->pvt = wc;
                wc->chans[x]->chanpos = x + 1;
index c5ebe9d..bb80f15 100644 (file)
@@ -1805,7 +1805,8 @@ static int t13x_software_init(struct t13x *wc, enum linemode type)
        t13x_serial_setup(wc);
        set_bit(DAHDI_FLAGBIT_RBS, &wc->span.flags);
        for (x = 0; x < wc->span.channels; x++) {
-               sprintf(wc->chans[x]->name, "%s/%d", wc->span.name, x + 1);
+               snprintf(wc->chans[x]->name, sizeof(wc->chans[x]->name),
+                        "%s/%d", wc->span.name, x + 1);
                t13x_chan_set_sigcap(&wc->span, x);
                wc->chans[x]->pvt = wc;
                wc->chans[x]->chanpos = x + 1;
index 3e6159b..c9b7978 100644 (file)
@@ -2536,7 +2536,8 @@ t43x_init_one_span(struct t43x *wc, struct t43x_span *ts, enum linemode type)
 
        set_bit(DAHDI_FLAGBIT_RBS, &ts->span.flags);
        for (x = 0; x < ts->span.channels; x++) {
-               sprintf(ts->chans[x]->name, "%s/%d", ts->span.name, x + 1);
+               snprintf(ts->chans[x]->name, sizeof(ts->chans[x]->name),
+                        "%s/%d", ts->span.name, x + 1);
                t43x_chan_set_sigcap(&ts->span, x);
                ts->chans[x]->pvt = wc;
                ts->chans[x]->chanpos = x + 1;