diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-07-28 18:59:57 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-07-28 18:59:57 -0700 |
commit | a3d9c2a4ce11ea001c9ac97c8a6fb9a4f9a1d1ac (patch) | |
tree | f03127ba5f01cc430e93b09d510de01c5631343b /src/xrdb.c | |
parent | c26f25213a70687820290a58189e58e687ef498c (diff) | |
download | emacs-a3d9c2a4ce11ea001c9ac97c8a6fb9a4f9a1d1ac.tar.gz |
* xrdb.c: Integer and memory overflow issues.
(magic_file_p): Plug memory leak on size overflow.
(get_environ_db): Don't assume path length fits in int,
as sprintf is limited to int lengths.
Diffstat (limited to 'src/xrdb.c')
-rw-r--r-- | src/xrdb.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/xrdb.c b/src/xrdb.c index 6a16e3260bd..7c2cd586b09 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -204,7 +204,10 @@ magic_file_p (const char *string, EMACS_INT string_len, const char *class, if (path_size - path_len <= next_len) { if (min (PTRDIFF_MAX, SIZE_MAX) / 2 - 1 - path_len < next_len) - memory_full (SIZE_MAX); + { + xfree (path); + memory_full (SIZE_MAX); + } path_size = (path_len + next_len + 1) * 2; path = (char *) xrealloc (path, path_size); } @@ -426,24 +429,22 @@ get_environ_db (void) { XrmDatabase db; char *p; - char *path = 0, *home = 0; - const char *host; + char *path = 0; if ((p = getenv ("XENVIRONMENT")) == NULL) { - home = gethomedir (); - host = get_system_name (); - path = (char *) xmalloc (strlen (home) - + sizeof (".Xdefaults-") - + strlen (host)); - sprintf (path, "%s%s%s", home, ".Xdefaults-", host); + static char const xdefaults[] = ".Xdefaults-"; + char *home = gethomedir (); + char const *host = get_system_name (); + ptrdiff_t pathsize = strlen (home) + sizeof xdefaults + strlen (host); + path = (char *) xrealloc (home, pathsize); + strcat (strcat (path, xdefaults), host); p = path; } db = XrmGetFileDatabase (p); xfree (path); - xfree (home); return db; } |