-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This patch looks good to me. acked. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk5WspYACgkQrlYvE4MpobNFCgCgvAPufQjW7RiDY5BTBvXUyzxs 1okAn2N4+Bs2pcxK6+fZYSYCqoDpTnvr =r8jn -----END PGP SIGNATURE-----
>From 277408abd3baa37a744f7bd808b3b0a783429cdc Mon Sep 17 00:00:00 2001 From: Dan Walsh <dwalsh@xxxxxxxxxx> Date: Tue, 9 Aug 2011 09:58:53 -0400 Subject: [PATCH 42/77] policycoreutils: restorecon: Always check return code on asprintf Do not assume it is always a success and error gracefully when it isn't. Signed-off-by: Eric Paris <eparis@xxxxxxxxxx> --- policycoreutils/restorecond/user.c | 6 +++++- policycoreutils/restorecond/watch.c | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/policycoreutils/restorecond/user.c b/policycoreutils/restorecond/user.c index c315b99..ade3fb8 100644 --- a/policycoreutils/restorecond/user.c +++ b/policycoreutils/restorecond/user.c @@ -190,7 +190,11 @@ int start() { static int local_server() { // ! dbus, run as local service char *ptr=NULL; - asprintf(&ptr, "%s/.restorecond", homedir); + if (asprintf(&ptr, "%s/.restorecond", homedir) < 0) { + if (debug_mode) + perror("asprintf"); + return -1; + } int fd = open(ptr, O_CREAT | O_WRONLY | O_NOFOLLOW, S_IRUSR | S_IWUSR); if (debug_mode) g_warning ("Lock file: %s", ptr); diff --git a/policycoreutils/restorecond/watch.c b/policycoreutils/restorecond/watch.c index d9e321e..6a833c3 100644 --- a/policycoreutils/restorecond/watch.c +++ b/policycoreutils/restorecond/watch.c @@ -226,7 +226,9 @@ static void process_config(int fd, FILE * cfg) if (buffer[0] == '~') { if (run_as_user) { char *ptr=NULL; - asprintf(&ptr, "%s%s", homedir, &buffer[1]); + if (asprintf(&ptr, "%s%s", homedir, &buffer[1]) < 0) + exitApp("Error allocating memory."); + watch_list_add(fd, ptr); free(ptr); } else { -- 1.7.6