From: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] Replace strncpy() with strlcpy()
Date: Tue, 21 Oct 2008 21:42:15 +0000 [thread overview]
Message-ID: <48FE4CB7.5020802@tuffmail.co.uk> (raw)
strncpy: just say no :).
<http://www.gratisoft.us/todd/papers/strlcpy.html>
Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c
index 6334af3..86c76cf 100644
--- a/extras/scsi_id/scsi_id.c
+++ b/extras/scsi_id/scsi_id.c
@@ -135,8 +135,7 @@ static void set_type(char *to, const char *from, size_t len)
break;
}
}
- strncpy(to, type, len);
- to[len-1] = '\0';
+ util_strlcpy(to, type, len);
}
/*
@@ -385,8 +384,7 @@ static int set_options(struct udev *udev,
case 'd':
dev_specified = 1;
- strncpy(maj_min_dev, optarg, MAX_PATH_LEN);
- maj_min_dev[MAX_PATH_LEN-1] = '\0';
+ util_strlcpy(maj_min_dev, optarg, MAX_PATH_LEN);
break;
case 'e':
@@ -394,8 +392,7 @@ static int set_options(struct udev *udev,
break;
case 'f':
- strncpy(config_file, optarg, MAX_PATH_LEN);
- config_file[MAX_PATH_LEN-1] = '\0';
+ util_strlcpy(config_file, optarg, MAX_PATH_LEN);
break;
case 'g':
@@ -461,8 +458,7 @@ static int set_options(struct udev *udev,
}
if (optind < argc && !dev_specified) {
dev_specified = 1;
- strncpy(maj_min_dev, argv[optind], MAX_PATH_LEN);
- maj_min_dev[MAX_PATH_LEN-1] = '\0';
+ util_strlcpy(maj_min_dev, argv[optind], MAX_PATH_LEN);
}
return 0;
}
diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c
index 5a43548..f56db7f 100644
--- a/udev/lib/libudev-device.c
+++ b/udev/lib/libudev-device.c
@@ -1001,7 +1001,7 @@ struct udev_list_entry *udev_device_add_property_from_string(struct udev_device
char name[UTIL_PATH_SIZE];
char *val;
- strncpy(name, property, sizeof(name));
+ util_strlcpy(name, property, sizeof(name));
val = strchr(name, '=');
if (val = NULL)
return NULL;
next reply other threads:[~2008-10-21 21:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-21 21:42 Alan Jenkins [this message]
2008-10-21 21:56 ` [PATCH] Replace strncpy() with strlcpy() Kay Sievers
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=48FE4CB7.5020802@tuffmail.co.uk \
--to=alan-jenkins@tuffmail.co.uk \
--cc=linux-hotplug@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).