mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-04-14 08:22:20 -04:00
cursor/os-compatibility: remove strcpy/strcat usage
These functions don't perform bounds checking, so they are easy to misuse and complicate audits. Signed-off-by: Simon Ser <contact@emersion.fr>
This commit is contained in:
parent
355c8e885c
commit
0297c2c47a
1 changed files with 5 additions and 3 deletions
|
|
@ -32,6 +32,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef HAVE_MEMFD_CREATE
|
#ifdef HAVE_MEMFD_CREATE
|
||||||
|
|
@ -118,6 +119,7 @@ os_create_anonymous_file(off_t size)
|
||||||
static const char template[] = "/wayland-cursor-shared-XXXXXX";
|
static const char template[] = "/wayland-cursor-shared-XXXXXX";
|
||||||
const char *path;
|
const char *path;
|
||||||
char *name;
|
char *name;
|
||||||
|
size_t name_size;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef HAVE_MEMFD_CREATE
|
#ifdef HAVE_MEMFD_CREATE
|
||||||
|
|
@ -139,12 +141,12 @@ os_create_anonymous_file(off_t size)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = malloc(strlen(path) + sizeof(template));
|
name_size = strlen(path) + sizeof(template);
|
||||||
|
name = malloc(name_size);
|
||||||
if (!name)
|
if (!name)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strcpy(name, path);
|
snprintf(name, name_size, "%s%s", path, template);
|
||||||
strcat(name, template);
|
|
||||||
|
|
||||||
fd = create_tmpfile_cloexec(name);
|
fd = create_tmpfile_cloexec(name);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue