mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
[PATCH] udev - safer sprintf() use
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.
This commit is contained in:
parent
7eb136adb8
commit
c58e36c092
@ -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':
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
12
udev.h
12
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user