diff options
author | jpeeler <jpeeler@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2008-02-18 17:32:26 +0000 |
---|---|---|
committer | jpeeler <jpeeler@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2008-02-18 17:32:26 +0000 |
commit | 23a324c0a98aba6d1bd13718d0d49d503c5987e0 (patch) | |
tree | 726099eee04498d137f1d9a3da25c8bd6067a10f | |
parent | 517b95c8dd353100be49168eee07fc8966db23c2 (diff) |
Closes issue #11471. Replaced instances of strncpy with zap_copy_string (added to zaptel.h) to fix any off by one errors and ensure destination string is NULL terminated.
git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.4@3846 5390a7c7-147a-4af0-8ec9-7488f05a26cb
-rw-r--r-- | fxotune.c | 3 | ||||
-rw-r--r-- | kernel/hpec/hpec_zaptel.h | 2 | ||||
-rw-r--r-- | kernel/jpah.h | 2 | ||||
-rw-r--r-- | kernel/kb1ec.h | 2 | ||||
-rw-r--r-- | kernel/mg2ec.h | 2 | ||||
-rw-r--r-- | kernel/sec-2.h | 2 | ||||
-rw-r--r-- | kernel/sec.h | 2 | ||||
-rw-r--r-- | kernel/tor2.c | 2 | ||||
-rw-r--r-- | kernel/torisa.c | 4 | ||||
-rw-r--r-- | kernel/wcfxo.c | 2 | ||||
-rw-r--r-- | kernel/wct1xxp.c | 2 | ||||
-rw-r--r-- | kernel/wct4xxp/base.c | 2 | ||||
-rw-r--r-- | kernel/wct4xxp/wct4xxp-diag.c | 2 | ||||
-rw-r--r-- | kernel/wctdm.c | 2 | ||||
-rw-r--r-- | kernel/wctdm24xxp/base.c | 2 | ||||
-rw-r--r-- | kernel/wcte11xp.c | 2 | ||||
-rw-r--r-- | kernel/wcte12xp/base.c | 2 | ||||
-rw-r--r-- | kernel/wcusb.c | 2 | ||||
-rw-r--r-- | kernel/zaptel-base.c | 26 | ||||
-rw-r--r-- | kernel/zaptel.h | 26 | ||||
-rw-r--r-- | kernel/ztd-eth.c | 4 | ||||
-rw-r--r-- | kernel/ztdummy.c | 2 | ||||
-rw-r--r-- | kernel/ztdynamic.c | 4 | ||||
-rw-r--r-- | kernel/zttranscode.c | 2 | ||||
-rw-r--r-- | ppp/zaptel.c | 2 | ||||
-rw-r--r-- | sethdlc-new.c | 2 | ||||
-rw-r--r-- | sethdlc.c | 2 | ||||
-rw-r--r-- | tonezone.c | 2 | ||||
-rw-r--r-- | ztcfg-dude.c | 8 | ||||
-rw-r--r-- | ztcfg.c | 12 | ||||
-rw-r--r-- | ztmonitor.c | 4 |
31 files changed, 81 insertions, 54 deletions
@@ -167,7 +167,8 @@ static int ensure_silence(struct silence_info *info) memset(&dop, 0, sizeof(dop)); dop.op = ZT_DIAL_OP_REPLACE; dop.dialstr[0] = 'T'; - strncpy(dop.dialstr + 1, info->dialstr, sizeof(dop.dialstr) - 1); + zap_copy_string(dop.dialstr + 1, info->dialstr, sizeof(dop.dialstr)); + if (ioctl(info->device, ZT_DIAL, &dop)) { fprintf(stderr, "Unable to dial!\n"); diff --git a/kernel/hpec/hpec_zaptel.h b/kernel/hpec/hpec_zaptel.h index 2fb5a14..2f90571 100644 --- a/kernel/hpec/hpec_zaptel.h +++ b/kernel/hpec/hpec_zaptel.h @@ -67,7 +67,7 @@ static void echo_can_init(void) static void echo_can_identify(char *buf, size_t len) { - strncpy(buf, "HPEC", len); + zap_copy_string(buf, "HPEC", len); } static void echo_can_shutdown(void) diff --git a/kernel/jpah.h b/kernel/jpah.h index f72c5fa..fb661ed 100644 --- a/kernel/jpah.h +++ b/kernel/jpah.h @@ -49,7 +49,7 @@ static void echo_can_init(void) static void echo_can_identify(char *buf, size_t len) { - strncpy(buf, "JP1", len); + zap_copy_string(buf, "JP1", len); } static void echo_can_shutdown(void) diff --git a/kernel/kb1ec.h b/kernel/kb1ec.h index 33236b7..cfafdf6 100644 --- a/kernel/kb1ec.h +++ b/kernel/kb1ec.h @@ -140,7 +140,7 @@ static void echo_can_init(void) static void echo_can_identify(char *buf, size_t len) { - strncpy(buf, "KB1", len); + zap_copy_string(buf, "KB1", len); } static void echo_can_shutdown(void) diff --git a/kernel/mg2ec.h b/kernel/mg2ec.h index 2dc3597..1d4189b 100644 --- a/kernel/mg2ec.h +++ b/kernel/mg2ec.h @@ -166,7 +166,7 @@ static void echo_can_init(void) static void echo_can_identify(char *buf, size_t len) { - strncpy(buf, "MG2", len); + zap_copy_string(buf, "MG2", len); } static void echo_can_shutdown(void) diff --git a/kernel/sec-2.h b/kernel/sec-2.h index 49342ea..94ce6ab 100644 --- a/kernel/sec-2.h +++ b/kernel/sec-2.h @@ -107,7 +107,7 @@ static void echo_can_init(void) static void echo_can_identify(char *buf, size_t len) { - strncpy(buf, "STEVE2", len); + zap_copy_string(buf, "STEVE2", len); } static void echo_can_shutdown(void) diff --git a/kernel/sec.h b/kernel/sec.h index 6c4b7c0..be31807 100644 --- a/kernel/sec.h +++ b/kernel/sec.h @@ -107,7 +107,7 @@ static void echo_can_init(void) static void echo_can_identify(char *buf, size_t len) { - strncpy(buf, "STEVE", len); + zap_copy_string(buf, "STEVE", len); } static void echo_can_shutdown(void) diff --git a/kernel/tor2.c b/kernel/tor2.c index ef2cf05..b0962f2 100644 --- a/kernel/tor2.c +++ b/kernel/tor2.c @@ -272,7 +272,7 @@ static void init_spans(struct tor2 *tor) "Tormenta 2 (PCI) fQuad %s Card %d Span %d", (tor->cardtype == TYPE_T1) ? "T1" : "E1", tor->num, x + 1); tor->spans[x].manufacturer = "Digium"; - strncpy(tor->spans[x].devicetype, tor->type, sizeof(tor->spans[x].devicetype) - 1); + zap_copy_string(tor->spans[x].devicetype, tor->type, sizeof(tor->spans[x].devicetype)); snprintf(tor->spans[x].location, sizeof(tor->spans[x].location) - 1, "PCI Bus %02d Slot %02d", tor->pci->bus->number, PCI_SLOT(tor->pci->devfn) + 1); tor->spans[x].spanconfig = tor2_spanconfig; diff --git a/kernel/torisa.c b/kernel/torisa.c index a8fb9d3..8003415 100644 --- a/kernel/torisa.c +++ b/kernel/torisa.c @@ -1077,9 +1077,9 @@ static int __init tor_init(void) } strcpy(spans[0].name, "TorISA/1"); - strncpy(spans[0].desc, "ISA Tormenta Span 1", sizeof(spans[0].desc) - 1); + zap_copy_string(spans[0].desc, "ISA Tormenta Span 1", sizeof(spans[0].desc)); spans[0].manufacturer = "Digium"; - strncpy(spans[0].devicetype, "Tormenta ISA", sizeof(spans[0].devicetype) - 1); + zap_copy_string(spans[0].devicetype, "Tormenta ISA", sizeof(spans[0].devicetype)); spans[0].spanconfig = torisa_spanconfig; spans[0].chanconfig = torisa_chanconfig; spans[0].startup = torisa_startup; diff --git a/kernel/wcfxo.c b/kernel/wcfxo.c index 5f48051..6dbadc4 100644 --- a/kernel/wcfxo.c +++ b/kernel/wcfxo.c @@ -666,7 +666,7 @@ static int wcfxo_initialize(struct wcfxo *wc) snprintf(wc->span.location, sizeof(wc->span.location) - 1, "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1); wc->span.manufacturer = "Digium"; - strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1); + zap_copy_string(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype)); wc->chan.sigcap = ZT_SIG_FXSKS | ZT_SIG_FXSLS | ZT_SIG_SF; wc->chan.chanpos = 1; wc->span.chans = &wc->chan; diff --git a/kernel/wct1xxp.c b/kernel/wct1xxp.c index bcfed97..cfc5edd 100644 --- a/kernel/wct1xxp.c +++ b/kernel/wct1xxp.c @@ -762,7 +762,7 @@ static int t1xxp_software_init(struct t1xxp *wc) sprintf(wc->span.name, "WCT1/%d", wc->num); snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Card %d", wc->variety, wc->num); wc->span.manufacturer = "Digium"; - strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1); + zap_copy_string(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype)); snprintf(wc->span.location, sizeof(wc->span.location) - 1, "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1); wc->span.spanconfig = t1xxp_spanconfig; diff --git a/kernel/wct4xxp/base.c b/kernel/wct4xxp/base.c index 0b4a2d9..13fc2ae 100644 --- a/kernel/wct4xxp/base.c +++ b/kernel/wct4xxp/base.c @@ -1535,7 +1535,7 @@ static void init_spans(struct t4 *wc) snprintf(ts->span.desc, sizeof(ts->span.desc) - 1, "T%dXXP (PCI) Card %d Span %d", wc->numspans, wc->num, x+1); ts->span.manufacturer = "Digium"; - strncpy(ts->span.devicetype, wc->variety, sizeof(ts->span.devicetype) - 1); + zap_copy_string(ts->span.devicetype, wc->variety, sizeof(ts->span.devicetype)); if (wc->vpm == T4_VPM_PRESENT) { if (!wc->vpm450m) strncat(ts->span.devicetype, " with VPM400M", sizeof(ts->span.devicetype) - 1); diff --git a/kernel/wct4xxp/wct4xxp-diag.c b/kernel/wct4xxp/wct4xxp-diag.c index 50a328d..8c14611 100644 --- a/kernel/wct4xxp/wct4xxp-diag.c +++ b/kernel/wct4xxp/wct4xxp-diag.c @@ -378,7 +378,7 @@ int main(int argc, char *argv[]) exit(1); } if (*(argv[1]) == '/') - strncpy(fn, argv[1], sizeof(fn) - 1); + zap_copy_string(fn, argv[1], sizeof(fn)); else snprintf(fn, sizeof(fn), "/dev/zap/%d", atoi(argv[1])); fd = open(fn, O_RDWR); diff --git a/kernel/wctdm.c b/kernel/wctdm.c index 68a21e7..02ffa40 100644 --- a/kernel/wctdm.c +++ b/kernel/wctdm.c @@ -2098,7 +2098,7 @@ static int wctdm_initialize(struct wctdm *wc) snprintf(wc->span.location, sizeof(wc->span.location) - 1, "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1); wc->span.manufacturer = "Digium"; - strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1); + zap_copy_string(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype)); if (alawoverride) { printk("ALAW override parameter detected. Device will be operating in ALAW\n"); wc->span.deflaw = ZT_LAW_ALAW; diff --git a/kernel/wctdm24xxp/base.c b/kernel/wctdm24xxp/base.c index 886bdab..8f5ae14 100644 --- a/kernel/wctdm24xxp/base.c +++ b/kernel/wctdm24xxp/base.c @@ -3137,7 +3137,7 @@ static int wctdm_initialize(struct wctdm *wc) "PCI%s Bus %02d Slot %02d", (wc->flags[0] & FLAG_EXPRESS) ? " Express" : "", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1); wc->span.manufacturer = "Digium"; - strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1); + zap_copy_string(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype)); if (alawoverride) { printk("ALAW override parameter detected. Device will be operating in ALAW\n"); wc->span.deflaw = ZT_LAW_ALAW; diff --git a/kernel/wcte11xp.c b/kernel/wcte11xp.c index 68cc827..b322135 100644 --- a/kernel/wcte11xp.c +++ b/kernel/wcte11xp.c @@ -972,7 +972,7 @@ static int t1xxp_software_init(struct t1 *wc) sprintf(wc->span.name, "WCT1/%d", wc->num); snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Card %d", wc->variety, wc->num); wc->span.manufacturer = "Digium"; - strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1); + zap_copy_string(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype)); snprintf(wc->span.location, sizeof(wc->span.location) - 1, "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1); wc->span.spanconfig = t1xxp_spanconfig; diff --git a/kernel/wcte12xp/base.c b/kernel/wcte12xp/base.c index 477f293..ee58db8 100644 --- a/kernel/wcte12xp/base.c +++ b/kernel/wcte12xp/base.c @@ -1357,7 +1357,7 @@ static int t1_software_init(struct t1 *wc) sprintf(wc->span.name, "WCT1/%d", wc->num); snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Card %d", wc->variety, wc->num); wc->span.manufacturer = "Digium"; - strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1); + zap_copy_string(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype)); #if defined(VPM_SUPPORT) if (wc->vpm150m) diff --git a/kernel/wcusb.c b/kernel/wcusb.c index 615d4c0..51eaca7 100644 --- a/kernel/wcusb.c +++ b/kernel/wcusb.c @@ -1251,7 +1251,7 @@ static int wc_set_zaptel(struct wc_usb_pvt *p) snprintf(p->span.desc, sizeof(p->span.desc) - 1, "%s %d", p->span.name, x); sprintf(p->chan.name, "WCUSB/%d/%d", x, 0); p->span.manufacturer = "Digium"; - strncpy(p->span.devicetype, p->variety, sizeof(p->span.devicetype) - 1); + zap_copy_string(p->span.devicetype, p->variety, sizeof(p->span.devicetype)); p->chan.sigcap = ZT_SIG_FXOKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS; /* We're capabable of both FXOKS and FXOLS */ p->chan.chanpos = 1; diff --git a/kernel/zaptel-base.c b/kernel/zaptel-base.c index ce42499..4aa2161 100644 --- a/kernel/zaptel-base.c +++ b/kernel/zaptel-base.c @@ -1269,7 +1269,7 @@ static devfs_handle_t register_devfs_channel(struct zt_chan *chan, devfs_handle_ /* Set up the path of the file/link itself */ tmp_offset = devfs_generate_path(zaptel_devfs_dir, tmp, sizeof(tmp) - 1); sprintf(buf, "/%d", chan->channo); - strncpy(path, tmp+tmp_offset, sizeof(path) - 1); + zap_copy_string(path, tmp+tmp_offset, sizeof(path)); strncat(path, buf, sizeof(path) - 1); err = devfs_mk_symlink(NULL, path, DEVFS_FL_DEFAULT, link+link_offset, &chan->fhandle_symlink, NULL); @@ -2638,7 +2638,7 @@ static int ioctl_load_zone(unsigned long data) ptr += sizeof(*z); space -= sizeof(*z); - strncpy(z->name, th.name, sizeof(z->name) - 1); + zap_copy_string(z->name, th.name, sizeof(z->name)); for (x = 0; x < ZT_MAX_CADENCE; x++) z->ringcadence[x] = th.ringcadence[x]; @@ -3101,7 +3101,7 @@ static int zt_common_ioctl(struct inode *node, struct file *file, unsigned int c stack.param.pulseaftertime = chan->pulseaftertime; if (chan->span) stack.param.spanno = chan->span->spanno; else stack.param.spanno = 0; - strncpy(stack.param.name, chan->name, sizeof(stack.param.name) - 1); + zap_copy_string(stack.param.name, chan->name, sizeof(stack.param.name)); stack.param.chanpos = chan->chanpos; stack.param.sigcap = chan->sigcap; /* Return current law */ @@ -3236,8 +3236,8 @@ static int zt_common_ioctl(struct inode *node, struct file *file, unsigned int c stack.spaninfo.spanno = i; /* put the span # in here */ stack.spaninfo.totalspans = 0; if (maxspans) stack.spaninfo.totalspans = maxspans - 1; /* put total number of spans here */ - strncpy(stack.spaninfo.desc, spans[i]->desc, sizeof(stack.spaninfo.desc) - 1); - strncpy(stack.spaninfo.name, spans[i]->name, sizeof(stack.spaninfo.name) - 1); + zap_copy_string(stack.spaninfo.desc, spans[i]->desc, sizeof(stack.spaninfo.desc)); + zap_copy_string(stack.spaninfo.name, spans[i]->name, sizeof(stack.spaninfo.name)); stack.spaninfo.alarms = spans[i]->alarms; /* get alarm status */ stack.spaninfo.bpvcount = spans[i]->bpvcount; /* get BPV count */ stack.spaninfo.rxlevel = spans[i]->rxlevel; /* get rx level */ @@ -3259,15 +3259,15 @@ static int zt_common_ioctl(struct inode *node, struct file *file, unsigned int c /* version 3 fields */ stack.spaninfo.irq = spans[i]->irq; stack.spaninfo.linecompat = spans[i]->linecompat; - strncpy(stack.spaninfo.lboname, zt_lboname(spans[i]->lbo), sizeof(stack.spaninfo.lboname) - 1); + zap_copy_string(stack.spaninfo.lboname, zt_lboname(spans[i]->lbo), sizeof(stack.spaninfo.lboname)); if (spans[i]->manufacturer) - strncpy(stack.spaninfo.manufacturer, spans[i]->manufacturer, - sizeof(stack.spaninfo.manufacturer) - 1); + zap_copy_string(stack.spaninfo.manufacturer, spans[i]->manufacturer, + sizeof(stack.spaninfo.manufacturer)); if (spans[i]->devicetype) - strncpy(stack.spaninfo.devicetype, spans[i]->devicetype, sizeof(stack.spaninfo.devicetype) - 1); - strncpy(stack.spaninfo.location, spans[i]->location, sizeof(stack.spaninfo.location) - 1); + zap_copy_string(stack.spaninfo.devicetype, spans[i]->devicetype, sizeof(stack.spaninfo.devicetype)); + zap_copy_string(stack.spaninfo.location, spans[i]->location, sizeof(stack.spaninfo.location)); if (spans[i]->spantype) - strncpy(stack.spaninfo.spantype, spans[i]->spantype, sizeof(stack.spaninfo.spantype) - 1); + zap_copy_string(stack.spaninfo.spantype, spans[i]->spantype, sizeof(stack.spaninfo.spantype)); if (copy_to_user((struct zt_spaninfo *) data, &stack.spaninfo, size_to_copy)) return -EFAULT; @@ -3722,7 +3722,7 @@ static int zt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd break; case ZT_GETVERSION: memset(&vi, 0, sizeof(vi)); - strncpy(vi.version, ZAPTEL_VERSION, sizeof(vi.version) - 1); + zap_copy_string(vi.version, ZAPTEL_VERSION, sizeof(vi.version)); echo_can_identify(vi.echo_canceller, sizeof(vi.echo_canceller) - 1); if (copy_to_user((struct zt_versioninfo *) data, &vi, sizeof(vi))) return -EFAULT; @@ -3840,7 +3840,7 @@ static int zt_chanandpseudo_ioctl(struct inode *inode, struct file *file, unsign rv = -EBUSY; break; } - strncpy(chan->txdialbuf + strlen(chan->txdialbuf), stack.tdo.dialstr, ZT_MAX_DTMF_BUF - strlen(chan->txdialbuf) - 1); + zap_copy_string(chan->txdialbuf + strlen(chan->txdialbuf), stack.tdo.dialstr, ZT_MAX_DTMF_BUF - strlen(chan->txdialbuf)); if (!chan->dialing) { chan->dialing = 1; __do_dtmf(chan); diff --git a/kernel/zaptel.h b/kernel/zaptel.h index 53bebf3..baffaa1 100644 --- a/kernel/zaptel.h +++ b/kernel/zaptel.h @@ -2006,4 +2006,30 @@ struct torisa_debug { /* Special torisa ioctl */ #define TORISA_GETDEBUG _IOW (ZT_CODE, 60, struct torisa_debug) +/*! + \brief Size-limited null-terminating string copy. + \param dst The destination buffer + \param src The source string + \param size The size of the destination buffer + \return Nothing. + + This is similar to \a strncpy, with two important differences: + - the destination buffer will \b always be null-terminated + - the destination buffer is not filled with zeros past the copied string length + These differences make it slightly more efficient, and safer to use since it will + not leave the destination buffer unterminated. There is no need to pass an artificially + reduced buffer size to this function (unlike \a strncpy), and the buffer does not need + to be initialized to zeroes prior to calling this function. +*/ +static inline void zap_copy_string(char *dst, const char *src, unsigned int size) +{ + while (*src && size) { + *dst++ = *src++; + size--; + } + if (__builtin_expect(!size, 0)) + dst--; + *dst = '\0'; +} + #endif /* _LINUX_ZAPTEL_H */ diff --git a/kernel/ztd-eth.c b/kernel/ztd-eth.c index 97d3492..dfda1f0 100644 --- a/kernel/ztd-eth.c +++ b/kernel/ztd-eth.c @@ -316,12 +316,12 @@ static void *ztdeth_create(struct zt_span *span, char *addr) memset(z, 0, sizeof(struct ztdeth)); /* Address should be <dev>/<macaddr>[/subaddr] */ - strncpy(tmp, addr, sizeof(tmp) - 1); + zap_copy_string(tmp, addr, sizeof(tmp)); tmp2 = strchr(tmp, '/'); if (tmp2) { *tmp2 = '\0'; tmp2++; - strncpy(z->ethdev, tmp, sizeof(z->ethdev) - 1); + zap_copy_string(z->ethdev, tmp, sizeof(z->ethdev)); } else { printk("Invalid TDMoE address (no device) '%s'\n", addr); kfree(z); diff --git a/kernel/ztdummy.c b/kernel/ztdummy.c index 5cedaa3..18f1e9f 100644 --- a/kernel/ztdummy.c +++ b/kernel/ztdummy.c @@ -262,7 +262,7 @@ static int ztdummy_initialize(struct ztdummy *ztd) sprintf(ztd->span.name, "ZTDUMMY/1"); snprintf(ztd->span.desc, sizeof(ztd->span.desc) - 1, "%s (source: " CLOCK_SRC ") %d", ztd->span.name, 1); sprintf(ztd->chan.name, "ZTDUMMY/%d/%d", 1, 0); - strncpy(ztd->span.devicetype, "Zaptel Dummy Timing Driver", sizeof(ztd->span.devicetype) - 1); + zap_copy_string(ztd->span.devicetype, "Zaptel Dummy Timing Driver", sizeof(ztd->span.devicetype)); ztd->chan.chanpos = 1; ztd->span.chans = &ztd->chan; ztd->span.channels = 0; /* no channels on our span */ diff --git a/kernel/ztdynamic.c b/kernel/ztdynamic.c index 01b22e2..14f8361 100644 --- a/kernel/ztdynamic.c +++ b/kernel/ztdynamic.c @@ -611,8 +611,8 @@ static int create_dynamic(ZT_DYNAMIC_SPAN *zds) memset(z->msgbuf, 0, bufsize); /* Setup parameters properly assuming we're going to be okay. */ - strncpy(z->dname, zds->driver, sizeof(z->dname) - 1); - strncpy(z->addr, zds->addr, sizeof(z->addr) - 1); + zap_copy_string(z->dname, zds->driver, sizeof(z->dname)); + zap_copy_string(z->addr, zds->addr, sizeof(z->addr)); z->timing = zds->timing; sprintf(z->span.name, "ZTD/%s/%s", zds->driver, zds->addr); sprintf(z->span.desc, "Dynamic '%s' span at '%s'", zds->driver, zds->addr); diff --git a/kernel/zttranscode.c b/kernel/zttranscode.c index ca2cdd8..6a441df 100644 --- a/kernel/zttranscode.c +++ b/kernel/zttranscode.c @@ -314,7 +314,7 @@ static int zt_tc_getinfo(unsigned long data) if (!tc) return -ENOSYS; - strncpy(info.name, tc->name, sizeof(info.name) - 1); + zap_copy_string(info.name, tc->name, sizeof(info.name)); info.numchannels = tc->numchannels; info.srcfmts = tc->srcfmts; info.dstfmts = tc->dstfmts; diff --git a/ppp/zaptel.c b/ppp/zaptel.c index d231794..121bfec 100644 --- a/ppp/zaptel.c +++ b/ppp/zaptel.c @@ -223,7 +223,7 @@ int setdevname_zaptel(const char *cp) } } - strncpy(devnam, cp, sizeof(devnam) - 1); + zap_copy_string(devnam, cp, sizeof(devnam)); info("Using zaptel device '%s'\n", devnam); diff --git a/sethdlc-new.c b/sethdlc-new.c index 1765c32..376a3f4 100644 --- a/sethdlc-new.c +++ b/sethdlc-new.c @@ -673,7 +673,7 @@ int main(int arg_c, char *arg_v[]) if (sock < 0) error("Unable to create socket: %s\n", strerror(errno)); - strncpy(req.ifr_name, argv[1], sizeof(req.ifr_name) - 1); /* Device name */ + zap_copy_string(req.ifr_name, argv[1], sizeof(req.ifr_name)); /* Device name */ if (argc == 2) show_port(); @@ -293,7 +293,7 @@ int main(int argc, char *argv[]) if (sock<0) error("Unable to create socket: %s\n", strerror(errno)); - strncpy(req.ifr_name, argv[1], sizeof(req.ifr_name) - 1); /* Device name */ + zap_copy_string(req.ifr_name, argv[1], sizeof(req.ifr_name)); /* Device name */ if (argc == 2) { show_port(sock); @@ -323,7 +323,7 @@ int tone_zone_register_zone(int fd, struct tone_zone *z) space -= sizeof(*h); h->zone = z->zone; - strncpy(h->name, z->description, sizeof(h->name) - 1); + zap_copy_string(h->name, z->description, sizeof(h->name)); for (x = 0; x < ZT_MAX_CADENCE; x++) h->ringcadence[x] = z->ringcadence[x]; diff --git a/ztcfg-dude.c b/ztcfg-dude.c index 8f655ee..ab959fc 100644 --- a/ztcfg-dude.c +++ b/ztcfg-dude.c @@ -187,8 +187,8 @@ int dspanconfig(char *keyword, char *args) } - strncpy(zds[numdynamic].driver, realargs[0], sizeof(zds[numdynamic].driver)); - strncpy(zds[numdynamic].addr, realargs[1], sizeof(zds[numdynamic].addr)); + zap_copy_string(zds[numdynamic].driver, realargs[0], sizeof(zds[numdynamic].driver)); + zap_copy_string(zds[numdynamic].addr, realargs[1], sizeof(zds[numdynamic].addr)); zds[numdynamic].numchans = chans; zds[numdynamic].timing = timing; @@ -296,7 +296,7 @@ int apply_channels(int chans[], char *argstr) for (x=0;x<res;x++) { if (strchr(args[x], '-')) { /* It's a range */ - strncpy(argcopy, args[x], sizeof(argcopy)); + zap_copy_string(argcopy, args[x], sizeof(argcopy)); res2 = parseargs(argcopy, range, 2, '-'); if (res2 != 2) { error("Syntax error in range '%s'. Should be <val1>-<val2>.\n", args[x]); @@ -571,7 +571,7 @@ static int registerzone(char *keyword, char *args) error("Too many tone zones specified\n"); return 0; } - strncpy(zonestoload[numzones++], args, sizeof(zonestoload[0])); + zap_copy_string(zonestoload[numzones++], args, sizeof(zonestoload[0])); return 0; } @@ -268,8 +268,8 @@ int dspanconfig(char *keyword, char *args) } - strncpy(zds[numdynamic].driver, realargs[0], sizeof(zds[numdynamic].driver)); - strncpy(zds[numdynamic].addr, realargs[1], sizeof(zds[numdynamic].addr)); + zap_copy_string(zds[numdynamic].driver, realargs[0], sizeof(zds[numdynamic].driver)); + zap_copy_string(zds[numdynamic].addr, realargs[1], sizeof(zds[numdynamic].addr)); zds[numdynamic].numchans = chans; zds[numdynamic].timing = timing; @@ -377,7 +377,7 @@ int apply_channels(int chans[], char *argstr) for (x=0;x<res;x++) { if (strchr(args[x], '-')) { /* It's a range */ - strncpy(argcopy, args[x], sizeof(argcopy)); + zap_copy_string(argcopy, args[x], sizeof(argcopy)); res2 = parseargs(argcopy, range, 2, '-'); if (res2 != 2) { error("Syntax error in range '%s'. Should be <val1>-<val2>.\n", args[x]); @@ -571,7 +571,7 @@ static int chanconfig(char *keyword, char *args) } else { cc[x].sigtype = ZT_SIG_HDLCNET; if (idle) { - strncpy(cc[x].netdev_name, idle, sizeof(cc[x].netdev_name) - 1); + zap_copy_string(cc[x].netdev_name, idle, sizeof(cc[x].netdev_name)); } master = x; } @@ -631,7 +631,7 @@ static int registerzone(char *keyword, char *args) error("Too many tone zones specified\n"); return 0; } - strncpy(zonestoload[numzones++], args, sizeof(zonestoload[0])); + zap_copy_string(zonestoload[numzones++], args, sizeof(zonestoload[0])); return 0; } @@ -967,7 +967,7 @@ int rad_apply_channels(int chans[], char *argstr) for (x=0;x<res;x++) { if (strchr(args[x], '-')) { /* It's a range */ - strncpy(argcopy, args[x], sizeof(argcopy)); + zap_copy_string(argcopy, args[x], sizeof(argcopy)); res2 = parseargs(argcopy, range, 2, '-'); if (res2 != 2) { error("Syntax error in range '%s'. Should be <val1>-<val2>.\n", args[x]); diff --git a/ztmonitor.c b/ztmonitor.c index 13f355d..29fc721 100644 --- a/ztmonitor.c +++ b/ztmonitor.c @@ -165,10 +165,10 @@ void draw_barheader() memset(bar+barlen+2, '>', 1); memset(bar+barlen+3, '\0', 1); - strncpy(bar+(barlen/2), "(RX)", 4); + zap_copy_string(bar+(barlen/2), "(RX)", 4); printf("%s", bar); - strncpy(bar+(barlen/2), "(TX)", 4); + zap_copy_string(bar+(barlen/2), "(TX)", 4); printf(" %s\n", bar); } |