From: Roel Kluin <roel.kluin@gmail.com>
To: Roel Kluin <roel.kluin@gmail.com>
Cc: Randy Dunlap <rdunlap@xenotime.net>,
linux-doc@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
David Wagner <daw@cs.berkeley.edu>
Subject: Re: [PATCH] Documentation: Fix NUL termination of strncpy
Date: Mon, 16 Nov 2009 22:24:55 +0100 [thread overview]
Message-ID: <4B01C327.7050805@gmail.com> (raw)
In-Reply-To: <4B019F52.50509@gmail.com>
Ensure the copied strings are NUL terminated.
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
>> Rationale (please correct me if I'm wrong):
I was confused. strncpy requires explicit NUL termination
or it depends on a NUL in the source string.
Documentation/accounting/getdelays.c | 3 ++-
Documentation/hwmon/hpfall.c | 3 ++-
| 2 +-
.../networking/timestamping/timestamping.c | 6 ++++--
4 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
index 6e25c26..ba54b19 100644
--- a/Documentation/accounting/getdelays.c
+++ b/Documentation/accounting/getdelays.c
@@ -303,7 +303,8 @@ int main(int argc, char *argv[])
err(1, "Invalid rcv buf size\n");
break;
case 'm':
- strncpy(cpumask, optarg, sizeof(cpumask));
+ strncpy(cpumask, optarg, sizeof(cpumask) - 1);
+ cpumask[sizeof(cpumask) - 1] = '\0';
maskset = 1;
printf("cpumask %s maskset %d\n", cpumask, maskset);
break;
diff --git a/Documentation/hwmon/hpfall.c b/Documentation/hwmon/hpfall.c
index 681ec22..4a06c06 100644
--- a/Documentation/hwmon/hpfall.c
+++ b/Documentation/hwmon/hpfall.c
@@ -27,7 +27,8 @@ int set_unload_heads_path(char *device)
if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0)
return -EINVAL;
- strncpy(devname, device + 5, sizeof(devname));
+ strncpy(devname, device + 5, sizeof(devname) - 1);
+ devname[sizeof(devname) - 1] = '\0';
snprintf(unload_heads_path, sizeof(unload_heads_path),
"/sys/block/%s/device/unload_heads", devname);
--git a/Documentation/networking/radiotap-headers.txt b/Documentation/networking/radiotap-headers.txt
index 953331c..447e004 100644
--- a/Documentation/networking/radiotap-headers.txt
+++ b/Documentation/networking/radiotap-headers.txt
@@ -126,7 +126,7 @@ int MyFunction(u8 * buf, int buflen)
case IEEE80211_RADIOTAP_ANTENNA:
/* radiotap uses 0 for 1st ant */
- antenna = *iterator.this_arg);
+ antenna = *iterator.this_arg;
break;
case IEEE80211_RADIOTAP_DBM_TX_POWER:
diff --git a/Documentation/networking/timestamping/timestamping.c b/Documentation/networking/timestamping/timestamping.c
index a7936fe..e2a17a4 100644
--- a/Documentation/networking/timestamping/timestamping.c
+++ b/Documentation/networking/timestamping/timestamping.c
@@ -374,12 +374,14 @@ int main(int argc, char **argv)
bail("socket");
memset(&device, 0, sizeof(device));
- strncpy(device.ifr_name, interface, sizeof(device.ifr_name));
+ strncpy(device.ifr_name, interface, sizeof(device.ifr_name) - 1);
+ device.ifr_name[sizeof(device.ifr_name) - 1] = '\0';
if (ioctl(sock, SIOCGIFADDR, &device) < 0)
bail("getting interface IP address");
memset(&hwtstamp, 0, sizeof(hwtstamp));
- strncpy(hwtstamp.ifr_name, interface, sizeof(hwtstamp.ifr_name));
+ strncpy(hwtstamp.ifr_name, interface, sizeof(hwtstamp.ifr_name) - 1);
+ hwtstamp.ifr_name[sizeof(hwtstamp.ifr_name) - 1] = '\0';
hwtstamp.ifr_data = (void *)&hwconfig;
memset(&hwconfig, 0, sizeof(hwconfig));
hwconfig.tx_type =
next prev parent reply other threads:[~2009-11-16 21:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-16 16:55 [PATCH] Documentation: Fix NUL termination of strncpy Roel Kluin
2009-11-16 18:52 ` Roel Kluin
2009-11-16 21:24 ` Roel Kluin [this message]
2009-11-17 12:25 ` Pádraig Brady
2009-11-17 16:41 ` Valdis.Kletnieks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B01C327.7050805@gmail.com \
--to=roel.kluin@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=daw@cs.berkeley.edu \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@xenotime.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.