mirror of
https://github.com/SELinuxProject/selinux
synced 2024-12-22 22:12:16 +00:00
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:
parent
48681bb49c
commit
9961ca6499
@ -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);
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user