Fix 5243: Allocate buffers zero in uwac.

This commit is contained in:
Armin Novak 2019-02-11 11:54:19 +01:00
parent c237f247d9
commit 0d389d09a3
6 changed files with 12 additions and 11 deletions

View File

@ -259,7 +259,7 @@ void* UwacClipboardDataGet(UwacSeat* seat, const char* mime, size_t* size)
{ {
void* tmp; void* tmp;
alloc += 1024; alloc += 1024;
tmp = realloc(data, alloc); tmp = xrealloc(data, alloc);
if (!tmp) if (!tmp)
{ {
free(data); free(data);

View File

@ -165,7 +165,7 @@ static void registry_handle_global(void* data, struct wl_registry* registry, uin
{ {
UwacDisplay* d = data; UwacDisplay* d = data;
UwacGlobal* global; UwacGlobal* global;
global = xmalloc(sizeof * global); global = xzalloc(sizeof * global);
global->name = id; global->name = id;
global->interface = xstrdup(interface); global->interface = xstrdup(interface);
global->version = version; global->version = version;
@ -416,7 +416,7 @@ static void display_dispatch_events(UwacTask* task, uint32_t events)
UwacDisplay* UwacOpenDisplay(const char* name, UwacReturnCode* err) UwacDisplay* UwacOpenDisplay(const char* name, UwacReturnCode* err)
{ {
UwacDisplay* ret; UwacDisplay* ret;
ret = (UwacDisplay*)calloc(1, sizeof(*ret)); ret = (UwacDisplay*)xzalloc(sizeof(*ret));
if (!ret) if (!ret)
{ {
@ -745,7 +745,7 @@ UwacEvent* UwacDisplayNewEvent(UwacDisplay* display, int type)
return 0; return 0;
} }
ret = zalloc(sizeof(UwacEventListItem)); ret = xzalloc(sizeof(UwacEventListItem));
if (!ret) if (!ret)
{ {

View File

@ -899,7 +899,7 @@ static const struct wl_seat_listener seat_listener = {
UwacSeat *UwacSeatNew(UwacDisplay *d, uint32_t id, uint32_t version) { UwacSeat *UwacSeatNew(UwacDisplay *d, uint32_t id, uint32_t version) {
UwacSeat *ret; UwacSeat *ret;
ret = zalloc(sizeof(UwacSeat)); ret = xzalloc(sizeof(UwacSeat));
ret->display = d; ret->display = d;
ret->seat_id = id; ret->seat_id = id;
ret->seat_version = version; ret->seat_version = version;
@ -1041,7 +1041,7 @@ UwacReturnCode UwacSeatSetMouseCursor(UwacSeat* seat, const void* data, size_t l
/* There is a cursor provided */ /* There is a cursor provided */
if ((data != NULL) && (length != 0)) if ((data != NULL) && (length != 0))
{ {
seat->pointer_image = calloc(1, sizeof(struct wl_cursor_image)); seat->pointer_image = xzalloc(sizeof(struct wl_cursor_image));
if (!seat->pointer_image) if (!seat->pointer_image)
return UWAC_ERROR_NOMEMORY; return UWAC_ERROR_NOMEMORY;
seat->pointer_image->width = width; seat->pointer_image->width = width;
@ -1050,7 +1050,7 @@ UwacReturnCode UwacSeatSetMouseCursor(UwacSeat* seat, const void* data, size_t l
seat->pointer_image->hotspot_y = hot_y; seat->pointer_image->hotspot_y = hot_y;
free(seat->pointer_data); free(seat->pointer_data);
seat->pointer_data = malloc(length); seat->pointer_data = xmalloc(length);
memcpy(seat->pointer_data, data, length); memcpy(seat->pointer_data, data, length);
seat->pointer_size = length; seat->pointer_size = length;

View File

@ -48,6 +48,7 @@
#include "../config.h" #include "../config.h"
#include "uwac-os.h" #include "uwac-os.h"
#include "uwac-utils.h"
static int set_cloexec_or_close(int fd) static int set_cloexec_or_close(int fd)
{ {
@ -230,7 +231,7 @@ int uwac_create_anonymous_file(off_t size)
if (fd < 0) if (fd < 0)
{ {
length = strlen(path) + sizeof(template); length = strlen(path) + sizeof(template);
name = malloc(length); name = xmalloc(length);
if (!name) if (!name)
return -1; return -1;

View File

@ -110,7 +110,7 @@ static const struct wl_output_listener output_listener = {
UwacOutput *UwacCreateOutput(UwacDisplay *d, uint32_t id, uint32_t version) { UwacOutput *UwacCreateOutput(UwacDisplay *d, uint32_t id, uint32_t version) {
UwacOutput *o; UwacOutput *o;
o = zalloc(sizeof *o); o = xzalloc(sizeof *o);
if (!o) if (!o)
return NULL; return NULL;

View File

@ -304,7 +304,7 @@ int UwacWindowShmAllocBuffers(UwacWindow* w, int nbuffers, int allocSize, uint32
int i, fd; int i, fd;
void* data; void* data;
struct wl_shm_pool* pool; struct wl_shm_pool* pool;
newBuffers = realloc(w->buffers, (w->nbuffers + nbuffers) * sizeof(UwacBuffer)); newBuffers = xrealloc(w->buffers, (w->nbuffers + nbuffers) * sizeof(UwacBuffer));
if (!newBuffers) if (!newBuffers)
return UWAC_ERROR_NOMEMORY; return UWAC_ERROR_NOMEMORY;
@ -417,7 +417,7 @@ UwacWindow* UwacCreateWindowShm(UwacDisplay* display, uint32_t width, uint32_t h
return NULL; return NULL;
} }
w = zalloc(sizeof(*w)); w = xzalloc(sizeof(*w));
if (!w) if (!w)
{ {