From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: udev - safer sprintf() use
Date: Sat, 28 Feb 2004 01:52:29 +0000 [thread overview]
Message-ID: <20040228015229.GA31877@vrfy.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 293 bytes --]
Here is for now my last patch to the string handling for a rather
theorethical case, where the node is very very very long. :)
We have accordant to strfieldcat(to, from) now a strintcat(to, i) macro,
which appends the ascii representation of a integer to a string in a
safe way.
thanks,
Kay
[-- Attachment #2: 01-strcat.patch --]
[-- Type: text/plain, Size: 2107 bytes --]
===== namedev.c 1.116 vs edited =====
--- 1.116/namedev.c Thu Feb 26 22:29:48 2004
+++ edited/namedev.c Sat Feb 28 02:41:27 2004
@@ -263,11 +263,11 @@
dbg("substitute kernel number '%s'", udev->kernel_number);
break;
case 'm':
- sprintf(pos, "%u", udev->minor);
+ strnintcat(string, udev->minor, maxsize);
dbg("substitute minor number '%u'", udev->minor);
break;
- case 'M':
- sprintf(pos, "%u", udev->major);
+ case 'M':
+ strnintcat(string, udev->major, maxsize);
dbg("substitute major number '%u'", udev->major);
break;
case 'c':
===== udev-add.c 1.52 vs edited =====
--- 1.52/udev-add.c Fri Feb 27 00:11:36 2004
+++ edited/udev-add.c Sat Feb 28 02:41:27 2004
@@ -211,7 +211,8 @@
info("creating device partition nodes '%s[1-%i]'", filename, dev->partitions);
if (!fake) {
for (i = 1; i <= dev->partitions; i++) {
- sprintf(partitionname, "%s%i", filename, i);
+ strfieldcpy(partitionname, filename);
+ strintcat(partitionname, i);
make_node(partitionname, dev->major,
dev->minor + i, dev->mode, uid, gid);
}
===== udev-remove.c 1.20 vs edited =====
--- 1.20/udev-remove.c Wed Feb 25 01:04:14 2004
+++ edited/udev-remove.c Sat Feb 28 02:41:28 2004
@@ -87,7 +87,8 @@
if (dev->partitions > 0) {
info("removing partitions '%s[1-%i]'", filename, dev->partitions);
for (i = 1; i <= dev->partitions; i++) {
- sprintf(partitionname, "%s%i", filename, i);
+ strfieldcpy(partitionname, filename);
+ strintcat(partitionname, i);
unlink(partitionname);
}
}
===== udev.h 1.47 vs edited =====
--- 1.47/udev.h Thu Feb 26 06:14:04 2004
+++ edited/udev.h Sat Feb 28 02:41:28 2004
@@ -85,6 +85,18 @@
strncat(to, from, maxsize - strlen(to)-1); \
} while (0)
+#define strintcat(to, i) \
+do { \
+ to[sizeof(to)-1] = '\0'; \
+ snprintf((to) + strlen(to), sizeof(to) - strlen(to)-1, "%u", i); \
+} while (0)
+
+#define strnintcat(to, i, maxsize) \
+do { \
+ to[maxsize-1] = '\0'; \
+ snprintf((to) + strlen(to), maxsize - strlen(to)-1, "%u", i); \
+} while (0)
+
static inline char *get_action(void)
{
char *action;
next reply other threads:[~2004-02-28 1:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-28 1:52 Kay Sievers [this message]
2004-02-28 2:00 ` udev - safer sprintf() use Greg KH
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=20040228015229.GA31877@vrfy.org \
--to=kay.sievers@vrfy.org \
--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).