dracut/0055-Always-check-the-return-number-of-asprintf.patch
Harald Hoyer 75f812af59 dracut-027-81.git20130531
- fix btrfs mount flags for /usr
- degrade message about missing tools for stripping
Resolves: rhbz#958519
- set environment vars DRACUT_SYSTEMD, NEWROOT in service file
Resolves: rhbz#963159
- don't add volatile swap partitions to host_devs
- add libssl.so.10 to make kdump work with fips mode
- readd selinux dracut module for kdump
- url-lib/url-lib.sh: turn off curl globbing
Resolves: rhbz#907497
- include btrfs-zero-log in the initramfs
Resolves: rhbz#963257
- proper NAME the network interfaces
Resolves: rhbz#965842
- install default font latarcyrheb-sun16
Resolves: rhbz#927564
- optionally install /etc/pcmcia/config.opts
Resolves: rhbz#920076
- fix ONBOOT for slaves, set TYPE=Bond for bonding
Resolves: rhbz#919001
- add nvme kernel module
Resolves: rhbz#910734
- add xfs_metadump
- selinux: load_policy script fix
- add hid-hyperv and hv-vmbus kernel modules
- add parameter rd.live.squashimg
Resolves: rhbz#789036 rhbz#782108
- wait for all required interfaces if "rd.neednet=1"
Resolves: rhbz#801829
- lvm: add tools for thin provisioning
Resolves: rhbz#921235
- ifcfg/write-ifcfg.sh: fixed ifcfg file generation
- do not wait for mpath* devices
Resolves: rhbz#969068
2013-05-31 10:01:36 +02:00

145 lines
5.6 KiB
Diff

From d9eff33ce203a9010067a15ddf1d279132abf437 Mon Sep 17 00:00:00 2001
From: Kamil Rytarowski <n54@gmx.com>
Date: Sat, 11 May 2013 14:40:19 +0200
Subject: [PATCH] Always check the return number of asprintf
asprintf prints to an allocated string. When successful, the
functions return the number of bytes printed. If memory allocation
wasn't possible, or some other error occurs, the function will return
-1.
Don't check strp as a result of asprintf, it's content may be undefined.
man 3 asprintf
---
install/dracut-install.c | 59 +++++++++++++++++++++++++++++++++++++++---------
1 file changed, 48 insertions(+), 11 deletions(-)
diff --git a/install/dracut-install.c b/install/dracut-install.c
index 0b9502e..c8328b0 100644
--- a/install/dracut-install.c
+++ b/install/dracut-install.c
@@ -83,6 +83,7 @@ static char *convert_abs_rel(const char *from, const char *target)
size_t level = 0, fromlevel = 0, targetlevel = 0;
int l;
size_t i, rl, dirlen;
+ int ret;
target_dir_p = strdup(target);
if (!target_dir_p)
@@ -103,7 +104,11 @@ static char *convert_abs_rel(const char *from, const char *target)
for (i = dirlen+1; i < rl; ++i)
if (target_dir_p[i] != '/')
break;
- asprintf(&realtarget, "%s/%s", realpath_p, &target_dir_p[i]);
+ ret = asprintf(&realtarget, "%s/%s", realpath_p, &target_dir_p[i]);
+ if (ret < 0) {
+ log_error("Out of memory!");
+ exit(EXIT_FAILURE);
+ }
/* now calculate the relative path from <from> to <target> and
store it in <relative_from>
@@ -282,8 +287,11 @@ static int resolve_deps(const char *src)
/* run ldd */
ret = asprintf(&cmd, "ldd %s 2>&1", src);
- if (ret < 0)
- return ret;
+ if (ret < 0) {
+ log_error("Out of memory!");
+ exit(EXIT_FAILURE);
+ }
+
ret = 0;
fptr = popen(cmd, "r");
@@ -352,6 +360,7 @@ static int hmac_install(const char *src, const char *dst, const char *hmacpath)
_cleanup_free_ char *dstpath = strdup(dst);
_cleanup_free_ char *srchmacname = NULL;
_cleanup_free_ char *dsthmacname = NULL;
+ int ret;
if (!(srcpath && dstpath))
return -ENOMEM;
@@ -371,11 +380,29 @@ static int hmac_install(const char *src, const char *dst, const char *hmacpath)
srcpath[dlen] = '\0';
dstpath[dir_len(dst)] = '\0';
if (hmacpath) {
- asprintf(&srchmacname, "%s/%s.hmac", hmacpath, &src[dlen + 1]);
- asprintf(&dsthmacname, "%s/%s.hmac", hmacpath, &src[dlen + 1]);
+ ret = asprintf(&srchmacname, "%s/%s.hmac", hmacpath, &src[dlen + 1]);
+ if (ret < 0) {
+ log_error("Out of memory!");
+ exit(EXIT_FAILURE);
+ }
+
+ ret = asprintf(&dsthmacname, "%s/%s.hmac", hmacpath, &src[dlen + 1]);
+ if (ret < 0) {
+ log_error("Out of memory!");
+ exit(EXIT_FAILURE);
+ }
} else {
- asprintf(&srchmacname, "%s/.%s.hmac", srcpath, &src[dlen + 1]);
- asprintf(&dsthmacname, "%s/.%s.hmac", dstpath, &src[dlen + 1]);
+ ret = asprintf(&srchmacname, "%s/.%s.hmac", srcpath, &src[dlen + 1]);
+ if (ret < 0) {
+ log_error("Out of memory!");
+ exit(EXIT_FAILURE);
+ }
+
+ ret = asprintf(&dsthmacname, "%s/.%s.hmac", dstpath, &src[dlen + 1]);
+ if (ret < 0) {
+ log_error("Out of memory!");
+ exit(EXIT_FAILURE);
+ }
}
log_debug("hmac cp '%s' '%s')", srchmacname, dsthmacname);
dracut_install(srchmacname, dsthmacname, false, false, true);
@@ -428,7 +455,11 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
hashmap_put(items, i, i);
- asprintf(&fulldstpath, "%s%s", destrootdir, dst);
+ ret = asprintf(&fulldstpath, "%s%s", destrootdir, dst);
+ if (ret < 0) {
+ log_error("Out of memory!");
+ exit(EXIT_FAILURE);
+ }
ret = stat(fulldstpath, &sb);
@@ -511,7 +542,11 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
if (lstat(fulldstpath, &sb) != 0) {
_cleanup_free_ char *absdestpath = NULL;
- asprintf(&absdestpath, "%s%s", destrootdir, abspath);
+ ret = asprintf(&absdestpath, "%s%s", destrootdir, abspath);
+ if (ret < 0) {
+ log_error("Out of memory!");
+ exit(EXIT_FAILURE);
+ }
ln_r(absdestpath, fulldstpath);
}
@@ -704,6 +739,8 @@ static char *find_binary(const char *src)
char *p, *q;
bool end = false;
char *newsrc = NULL;
+ int ret;
+
path = getenv("PATH");
if (path == NULL) {
@@ -730,8 +767,8 @@ static char *find_binary(const char *src)
else
*q = '\0';
- asprintf(&newsrc, "%s/%s", p, src);
- if (newsrc == NULL) {
+ ret = asprintf(&newsrc, "%s/%s", p, src);
+ if (ret < 0) {
log_error("Out of memory!");
exit(EXIT_FAILURE);
}