summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--namedev.c6
-rw-r--r--udev-add.c3
-rw-r--r--udev-remove.c3
-rw-r--r--udev.h12
4 files changed, 19 insertions, 5 deletions
diff --git a/namedev.c b/namedev.c
index 7c07e3b104..581a7f2218 100644
--- a/namedev.c
+++ b/namedev.c
@@ -263,11 +263,11 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
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':
diff --git a/udev-add.c b/udev-add.c
index 8fdd66fad5..3a72c544b8 100644
--- a/udev-add.c
+++ b/udev-add.c
@@ -211,7 +211,8 @@ static int create_node(struct udevice *dev, int fake)
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);
}
diff --git a/udev-remove.c b/udev-remove.c
index 8794429635..e62d1fb122 100644
--- a/udev-remove.c
+++ b/udev-remove.c
@@ -87,7 +87,8 @@ static int delete_node(struct udevice *dev)
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);
}
}
diff --git a/udev.h b/udev.h
index 3b676acf40..5737c84c9d 100644
--- a/udev.h
+++ b/udev.h
@@ -85,6 +85,18 @@ do { \
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;