elput - simplify and fix handling of string overflow with xdg runtimedir

this addresses an issue pointed to by CID 1357168
This commit is contained in:
Carsten Haitzler 2016-07-09 12:01:51 +09:00
parent 870c81fd72
commit 9c80c2b070
1 changed files with 2 additions and 11 deletions

View File

@ -60,24 +60,15 @@ _keyboard_modifiers_update(Elput_Keyboard *kbd, Elput_Seat *seat)
static int
_keyboard_fd_get(off_t size)
{
int fd = 0, blen = 0, len = 0;
int fd = 0;
const char *path;
char tmp[PATH_MAX];
long flags;
blen = sizeof(tmp) - 1;
if (!(path = getenv("XDG_RUNTIME_DIR")))
return -1;
len = strlen(path);
if (len < blen)
{
strcpy(tmp, path);
strcat(tmp, "/elput-keymap-XXXXXX");
}
else
return -1;
snprintf(tmp, sizeof(tmp), "%s/elput-keymap-XXXXXX", path);
fd = eina_file_mkstemp(tmp, NULL);
if (fd < 0) return -1;