diff options
author | Stefan Hacker <dd0t@users.sourceforge.net> | 2015-07-02 00:31:52 +0300 |
---|---|---|
committer | Stefan Hacker <dd0t@users.sourceforge.net> | 2015-07-04 16:12:49 +0300 |
commit | 4fe166486015b085a33569d6a6299087abce388e (patch) | |
tree | aeac6492e1ff041d14750c1049500974d273ae60 /overlay_gl | |
parent | 5acf4af54f4ad1d92b2f0e95a58992e14068849f (diff) |
Handle some possible failure cases in overlay_gl
Namely:
* fstat failure
* Dangerously large overlay texture size
Diffstat (limited to 'overlay_gl')
-rw-r--r-- | overlay_gl/overlay.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/overlay_gl/overlay.c b/overlay_gl/overlay.c index 99a2deb89..2384f693e 100644 --- a/overlay_gl/overlay.c +++ b/overlay_gl/overlay.c @@ -361,26 +361,31 @@ static void drawOverlay(Context *ctx, unsigned int width, unsigned int height) { int fd = shm_open(oms->a_cName, O_RDONLY, 0600); if (fd != -1) { struct stat buf; - fstat(fd, &buf); - if (buf.st_size >= ctx->uiWidth * ctx->uiHeight * 4) { - ctx->uiMappedLength = (unsigned int)buf.st_size; - ctx->a_ucTexture = mmap(NULL, (size_t)buf.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (ctx->a_ucTexture != MAP_FAILED) { - // mmap successfull; send a new bodyless sharedmemory overlay message and regenerate the overlay texture - struct OverlayMsg om; - om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; - om.omh.uiType = OVERLAY_MSGTYPE_SHMEM; - om.omh.iLength = 0; - - if (! sendMessage(ctx, &om)) - return; - - regenTexture(ctx); - continue; + + if (fstat(fd, &buf) != -1) { + if (buf.st_size >= ctx->uiWidth * ctx->uiHeight * 4 + && buf.st_size < 512 * 1024 * 1024) { + ctx->uiMappedLength = (unsigned int)buf.st_size; + ctx->a_ucTexture = mmap(NULL, (size_t)buf.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (ctx->a_ucTexture != MAP_FAILED) { + // mmap successfull; send a new bodyless sharedmemory overlay message and regenerate the overlay texture + struct OverlayMsg om; + om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; + om.omh.uiType = OVERLAY_MSGTYPE_SHMEM; + om.omh.iLength = 0; + + if (! sendMessage(ctx, &om)) + return; + + regenTexture(ctx); + continue; + } + ctx->a_ucTexture = NULL; } - ctx->a_ucTexture = NULL; + ctx->uiMappedLength = 0; + } else { + ods("Failed to fstat memory map"); } - ctx->uiMappedLength = 0; close(fd); } ods("Failed to map memory"); |