xsel

Program for manipulating the X clipboard
git clone https://git.sinitax.com/kfish/xsel
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 294a7f1c0358a15037d39fe20b4ba29e0d16faf1
parent aa7f57eed805adb09e9c59c8ea841870e8206b81
Author: Carlos Maddela <e7appew@gmail.com>
Date:   Wed, 29 Mar 2017 21:15:31 +1100

Do not modify HOME environment variable.

https://github.com/kfish/xsel/pull/15 introduces some side-effects.
The HOME environment variable is modified, and more likely than not,
it overflows the string's buffer.

Make sure we return the string in memory we've allocated ourselves
to fix this.

Diffstat:
Mxsel.c | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/xsel.c b/xsel.c @@ -343,12 +343,21 @@ static char * get_xdg_cache_home (void) { char * cachedir; + char * homedir; + static const char * slashbasename = "/.cache"; if ((cachedir = getenv ("XDG_CACHE_HOME")) == NULL) { - cachedir = strcat(getenv ("HOME"), "/.cache"); + if ((homedir = getenv ("HOME")) == NULL) { + exit_err ("no HOME directory"); + } + cachedir = xs_malloc (strlen (homedir) + strlen (slashbasename) + 1); + strcpy (cachedir, homedir); + strcat (cachedir, slashbasename); + } else { + cachedir = _xs_strdup (cachedir); } - mkdir(cachedir, S_IRWXU|S_IRGRP|S_IXGRP); + mkdir (cachedir, S_IRWXU|S_IRGRP|S_IXGRP); return cachedir; } @@ -515,6 +524,8 @@ become_daemon (void) } set_daemon_timeout (); + + free (cachedir); } /*