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@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
Dan Walsh 2011-08-09 09:58:53 -04:00 committed by Eric Paris
parent 48681bb49c
commit 9961ca6499
2 changed files with 8 additions and 2 deletions

View File

@ -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);

View File

@ -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 {