diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index f5987d950..3ed49c983 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,13 @@ +2008-03-11 Corinna Vinschen + + * environ.cc (parse_options): Use tmp_pathbuf to allocate buffer. + (regopt): Take tmp buffer as additional argument. + (environ_init): Alllcate tmpbuf earlier. Use as temporary buffer in + call to regopt. + * tls_pbuf.cc (tmp_pathbuf::c_get): Allocate one additional char. + (tmp_pathbuf::w_get): Allocate one additional WCHAR. + * winf.cc (av::unshift): Use tmp_pathbuf to allocate buffer. + 2008-03-11 Corinna Vinschen * syscalls.cc (sync): Use MAX_PATH rather than CYG_MAX_PATH. diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index 3a427bb06..76c6820fb 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -626,7 +626,8 @@ parse_options (char *buf) if (buf == NULL) { - char newbuf[CYG_MAX_PATH + 7]; + tmp_pathbuf tp; + char *newbuf = tp.c_get (); newbuf[0] = '\0'; for (k = known; k->name != NULL; k++) if (k->remember) @@ -705,10 +706,9 @@ parse_options (char *buf) /* Set options from the registry. */ static bool __stdcall -regopt (const char *name) +regopt (const char *name, char *buf) { bool parsed_something = false; - char buf[CYG_MAX_PATH]; char lname[strlen (name) + 1]; strlwr (strcpy (lname, name)); @@ -716,7 +716,7 @@ regopt (const char *name) { reg_key r (i, KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL); - if (r.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS) + if (r.get_string (lname, buf, NT_MAX_PATH, "") == ERROR_SUCCESS) { parse_options (buf); parsed_something = true; @@ -754,9 +754,11 @@ environ_init (char **envp, int envc) conv_start_chars[(int) cyg_toupper (conv_envvars[i].name[0])] = 1; } - got_something_from_registry = regopt ("default"); + char *tmpbuf = tp.t_get (); + got_something_from_registry = regopt ("default", tmpbuf); if (myself->progname[0]) - got_something_from_registry = regopt (myself->progname) || got_something_from_registry; + got_something_from_registry = regopt (myself->progname, tmpbuf) + || got_something_from_registry; if (!envp) envp_passed_in = 0; @@ -807,7 +809,6 @@ environ_init (char **envp, int envc) form "=X:=X:\foo\bar; these must be changed into something legal (we could just ignore them but maybe an application will eventually want to use them). */ - char *tmpbuf = tp.t_get (); for (i = 0, w = rawenv; *w != L'\0'; w = wcschr (w, L'\0') + 1, i++) { sys_wcstombs_alloc (&newp, HEAP_NOTHEAP, w); diff --git a/winsup/cygwin/tls_pbuf.cc b/winsup/cygwin/tls_pbuf.cc index 704f3bfc9..802885ebc 100644 --- a/winsup/cygwin/tls_pbuf.cc +++ b/winsup/cygwin/tls_pbuf.cc @@ -42,7 +42,7 @@ tmp_pathbuf::c_get () if (tls_pbuf.c_cnt >= TP_NUM_C_BUFS) api_fatal ("Internal error: TP_NUM_C_BUFS too small."); if (!tls_pbuf.c_buf[tls_pbuf.c_cnt] - && !(tls_pbuf.c_buf[tls_pbuf.c_cnt] = (char *) malloc (NT_MAX_PATH))) + && !(tls_pbuf.c_buf[tls_pbuf.c_cnt] = (char *) malloc (NT_MAX_PATH + 1))) api_fatal ("Internal error: Out of memory for new path buf."); return tls_pbuf.c_buf[tls_pbuf.c_cnt++]; } @@ -54,7 +54,7 @@ tmp_pathbuf::w_get () api_fatal ("Internal error: TP_NUM_W_BUFS too small."); if (!tls_pbuf.w_buf[tls_pbuf.w_cnt] && !(tls_pbuf.w_buf[tls_pbuf.w_cnt] - = (PWCHAR) malloc (NT_MAX_PATH * sizeof (WCHAR)))) + = (PWCHAR) malloc ((NT_MAX_PATH + 1) * sizeof (WCHAR)))) api_fatal ("Internal error: Out of memory for new wide path buf."); return tls_pbuf.w_buf[tls_pbuf.w_cnt++]; } diff --git a/winsup/cygwin/winf.cc b/winsup/cygwin/winf.cc index 924e60403..033de7b1e 100644 --- a/winsup/cygwin/winf.cc +++ b/winsup/cygwin/winf.cc @@ -15,6 +15,7 @@ details. */ #include "fhandler.h" #include "dtable.h" #include "cygheap.h" +#include "tls_pbuf.h" #include "winf.h" #include "sys/cygwin.h" @@ -136,7 +137,8 @@ av::unshift (const char *what, int conv) argv = av; memmove (argv + 1, argv, (argc + 1) * sizeof (char *)); - char buf[CYG_MAX_PATH]; + tmp_pathbuf tp; + char *buf = tp.c_get (); if (conv) { cygwin_conv_to_posix_path (what, buf);