summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-11-02 22:44:36 -0600
committerGitHub <noreply@github.com>2016-11-02 22:44:36 -0600
commitb23f2b72bfad53e4420ac661d1771801fc2003f3 (patch)
tree288e2a20228ce10d387737c84bd74e6d2989e027 /src
parent7fa6328cc447a4a834ebc8d68ae6c335f4c9c9d3 (diff)
parente02c6135602bef7de81d7736d5c0959d45d5085c (diff)
Merge pull request #4546 from keszybz/xsprintf-revert
xsprintf revert
Diffstat (limited to 'src')
-rw-r--r--src/basic/log.c2
-rw-r--r--src/core/unit.c2
-rw-r--r--src/libsystemd/sd-bus/bus-kernel.c6
-rw-r--r--src/shared/switch-root.c25
-rw-r--r--src/udev/collect/collect.c6
-rw-r--r--src/udev/udev-builtin-net_id.c11
-rw-r--r--src/udev/udev-node.c4
-rw-r--r--src/udev/udev-watch.c6
8 files changed, 36 insertions, 26 deletions
diff --git a/src/basic/log.c b/src/basic/log.c
index 2ff70be255..4919d175da 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -782,7 +782,7 @@ static void log_assert(
return;
DISABLE_WARNING_FORMAT_NONLITERAL;
- xsprintf(buffer, format, text, file, line, func);
+ snprintf(buffer, sizeof buffer, format, text, file, line, func);
REENABLE_WARNING;
log_abort_msg = buffer;
diff --git a/src/core/unit.c b/src/core/unit.c
index 463e6d6a62..e664e23892 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1472,7 +1472,7 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
format = unit_get_status_message_format(u, t);
DISABLE_WARNING_FORMAT_NONLITERAL;
- xsprintf(buf, format, unit_description(u));
+ snprintf(buf, sizeof buf, format, unit_description(u));
REENABLE_WARNING;
mid = t == JOB_START ? SD_MESSAGE_UNIT_STARTING :
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 59398b841d..ad468572f3 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -848,8 +848,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
if (k->src_id == KDBUS_SRC_ID_KERNEL)
bus_message_set_sender_driver(bus, m);
else {
- xsprintf(m->sender_buffer, ":1.%llu",
- (unsigned long long)k->src_id);
+ xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
m->sender = m->creds.unique_name = m->sender_buffer;
}
@@ -860,8 +859,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
else if (k->dst_id == KDBUS_DST_ID_NAME)
m->destination = bus->unique_name; /* fill in unique name if the well-known name is missing */
else {
- xsprintf(m->destination_buffer, ":1.%llu",
- (unsigned long long)k->dst_id);
+ xsprintf(m->destination_buffer, ":1.%"PRIu64, k->dst_id);
m->destination = m->destination_buffer;
}
diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c
index 47d3a5a1fa..4eff4f692e 100644
--- a/src/shared/switch-root.c
+++ b/src/shared/switch-root.c
@@ -75,17 +75,29 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot,
NULSTR_FOREACH(i, move_mounts) {
char new_mount[PATH_MAX];
struct stat sb;
+ size_t n;
- xsprintf(new_mount, "%s%s", new_root, i);
+ n = snprintf(new_mount, sizeof new_mount, "%s%s", new_root, i);
+ if (n >= sizeof new_mount) {
+ bool move = mountflags & MS_MOVE;
+
+ log_warning("New path is too long, %s: %s%s",
+ move ? "forcing unmount instead" : "ignoring",
+ new_root, i);
+
+ if (move)
+ if (umount2(i, MNT_FORCE) < 0)
+ log_warning_errno(errno, "Failed to unmount %s: %m", i);
+ continue;
+ }
mkdir_p_label(new_mount, 0755);
- if ((stat(new_mount, &sb) < 0) ||
+ if (stat(new_mount, &sb) < 0 ||
sb.st_dev != new_root_stat.st_dev) {
/* Mount point seems to be mounted already or
- * stat failed. Unmount the old mount
- * point. */
+ * stat failed. Unmount the old mount point. */
if (umount2(i, MNT_DETACH) < 0)
log_warning_errno(errno, "Failed to unmount %s: %m", i);
continue;
@@ -97,10 +109,9 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot,
if (umount2(i, MNT_FORCE) < 0)
log_warning_errno(errno, "Failed to unmount %s: %m", i);
- }
- if (mountflags & MS_BIND)
- log_error_errno(errno, "Failed to bind mount %s to %s: %m", i, new_mount);
+ } else if (mountflags & MS_BIND)
+ log_error_errno(errno, "Failed to bind mount %s to %s: %m", i, new_mount);
}
}
diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c
index 349585b634..0e973cd521 100644
--- a/src/udev/collect/collect.c
+++ b/src/udev/collect/collect.c
@@ -85,16 +85,16 @@ static void usage(void)
*/
static int prepare(char *dir, char *filename)
{
- char buf[512];
+ char buf[PATH_MAX];
int r, fd;
r = mkdir(dir, 0700);
if (r < 0 && errno != EEXIST)
return -errno;
- xsprintf(buf, "%s/%s", dir, filename);
+ snprintf(buf, sizeof buf, "%s/%s", dir, filename);
- fd = open(buf,O_RDWR|O_CREAT|O_CLOEXEC, S_IRUSR|S_IWUSR);
+ fd = open(buf, O_RDWR|O_CREAT|O_CLOEXEC, S_IRUSR|S_IWUSR);
if (fd < 0)
fprintf(stderr, "Cannot open %s: %m\n", buf);
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index 0eb2500dd2..fe9d6f4482 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -211,7 +211,7 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
char *s;
const char *attr, *port_name;
struct udev_device *pci = NULL;
- char slots[256], str[256];
+ char slots[PATH_MAX];
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
int hotplug_slot = 0, err = 0;
@@ -248,7 +248,8 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
err = -ENOENT;
goto out;
}
- xsprintf(slots, "%s/slots", udev_device_get_syspath(pci));
+
+ snprintf(slots, sizeof slots, "%s/slots", udev_device_get_syspath(pci));
dir = opendir(slots);
if (!dir) {
err = -errno;
@@ -257,8 +258,7 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
int i;
- char *rest;
- char *address;
+ char *rest, *address, str[PATH_MAX];
if (dent->d_name[0] == '.')
continue;
@@ -267,7 +267,8 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
continue;
if (i < 1)
continue;
- xsprintf(str, "%s/%s/address", slots, dent->d_name);
+
+ snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
if (read_one_line_file(str, &address) >= 0) {
/* match slot address with device by stripping the function */
if (strneq(address, udev_device_get_sysname(names->pcidev), strlen(address)))
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index 5d2997fd8f..43004bc0bc 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -337,7 +337,7 @@ out:
void udev_node_add(struct udev_device *dev, bool apply,
mode_t mode, uid_t uid, gid_t gid,
struct udev_list *seclabel_list) {
- char filename[UTIL_PATH_SIZE];
+ char filename[sizeof("/dev/block/:") + 2*DECIMAL_STR_MAX(unsigned)];
struct udev_list_entry *list_entry;
log_debug("handling device node '%s', devnum=%s, mode=%#o, uid="UID_FMT", gid="GID_FMT,
@@ -360,7 +360,7 @@ void udev_node_add(struct udev_device *dev, bool apply,
void udev_node_remove(struct udev_device *dev) {
struct udev_list_entry *list_entry;
- char filename[UTIL_PATH_SIZE];
+ char filename[sizeof("/dev/block/:") + 2*DECIMAL_STR_MAX(unsigned)];
/* remove/update symlinks, remove symlinks from name index */
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev))
diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c
index 9ce5e975de..bc9096ed0c 100644
--- a/src/udev/udev-watch.c
+++ b/src/udev/udev-watch.c
@@ -89,7 +89,7 @@ unlink:
}
void udev_watch_begin(struct udev *udev, struct udev_device *dev) {
- char filename[UTIL_PATH_SIZE];
+ char filename[sizeof("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
int wd;
int r;
@@ -116,7 +116,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) {
void udev_watch_end(struct udev *udev, struct udev_device *dev) {
int wd;
- char filename[UTIL_PATH_SIZE];
+ char filename[sizeof("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
if (inotify_fd < 0)
return;
@@ -135,7 +135,7 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev) {
}
struct udev_device *udev_watch_lookup(struct udev *udev, int wd) {
- char filename[UTIL_PATH_SIZE];
+ char filename[sizeof("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
char device[UTIL_NAME_SIZE];
ssize_t len;