Mail Archives: djgpp-workers/1997/08/10/15:40:30
Subject: c1args.c patches
My patches below cover the following things:
- Use stackavail() + malloc to avoid crashes if the response file
is bigger than the available stack.
- Fix a bug that incorretly quotes filenames like i'vebeen.org
- Allows '@-' as a synonym for reading the response file from stdin.
This is disabled for now.
Markus
*** h:c1args.c Sat Aug 31 18:09:32 1996
--- c:c1args.c Sat Aug 9 22:39:18 1997
***************
*** 1,2 ****
--- 1,3 ----
+ /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
***************
*** 15,18 ****
--- 16,27 ----
#define ds _my_ds()
+ static __inline__ int c1_stackavail(void)
+ {
+ extern unsigned __djgpp_stack_limit;
+ unsigned sp;
+ __asm__ __volatile__ ("movl %%esp,%k0\n" : "=r" (sp) : );
+ return (int)(sp - __djgpp_stack_limit);
+ }
+
static void *
c1xmalloc(size_t s)
***************
*** 28,31 ****
--- 37,54 ----
}
+ #if 0
+ static void *
+ c1xrealloc(void *q, size_t s)
+ {
+ q = realloc(q,s);
+ if (q == 0)
+ {
+ err("No memory to gather arguments\r\n");
+ _exit(1);
+ }
+ return q;
+ }
+ #endif
+
static int
far_strlen(int selector, int linear_addr)
***************
*** 118,122 ****
int quote=0;
! while ((quote || !isspace(*ep)) && ep < last)
{
if (quote && *ep == quote)
--- 141,145 ----
int quote=0;
! while (ep < last && (quote || !isspace(*ep)))
{
if (quote && *ep == quote)
***************
*** 125,134 ****
ep++;
}
! else if (!quote && (*ep == '\'' || *ep == '"'))
{
quote = *ep;
ep++;
}
! else if (*ep == '\\' && strchr("'\"", ep[1]) && ep < last-1)
{
ep++;
--- 148,158 ----
ep++;
}
! /* quoting is only recognized at the beginning of an argument */
! else if (ep == bp && !quote && (*ep == '\'' || *ep == '"'))
{
quote = *ep;
ep++;
}
! else if (ep < last-1 && *ep == '\\' && strchr("'\"", ep[1]))
{
ep++;
***************
*** 161,165 ****
{
size_t arg_len;
! while (isspace(*bp) && bp < last)
bp++;
if (bp == last)
--- 185,189 ----
{
size_t arg_len;
! while (bp < last && isspace(*bp))
bp++;
if (bp == last)
***************
*** 239,252 ****
{
if (! al->argv[i]->was_quoted && al->argv[i]->arg[0] == '@')
if ((f = _open(al->argv[i]->arg+1, O_RDONLY)) >= 0)
{
char *bytes;
! int len, st_size;
st_size = lseek(f, 0L, SEEK_END);
! lseek(f, 0L, SEEK_SET);
! bytes = (char *)alloca(st_size);
! len = _read(f, bytes, st_size);
_close(f);
- al->argv[i]->arg_file = parse_bytes(bytes, len);
expand_response_files(al->argv[i]->arg_file);
}
--- 263,310 ----
{
if (! al->argv[i]->was_quoted && al->argv[i]->arg[0] == '@')
+ #if 0
+ /* Allow '@-' as a synonym for reading the response file from stdin. */
+ /* Disabled for now. */
+ if (al->argv[i]->arg[1] == '-' && al->argv[i]->arg[2] == 0)
+ {
+ int l, len = 0;
+ int size = 8192;
+ char *bytes;
+ bytes = (char *)c1xmalloc(size);
+ while ((l = _read(STDIN_FILENO, bytes + len, size - len)) > 0)
+ {
+ len += l;
+ if (len == size)
+ {
+ size = 2 * size;
+ bytes = (char *)c1xrealloc(bytes, size);
+ }
+ }
+ al->argv[i]->arg_file = parse_bytes(bytes, len);
+ free(bytes);
+ expand_response_files(al->argv[i]->arg_file);
+ }
+ else
+ #endif
if ((f = _open(al->argv[i]->arg+1, O_RDONLY)) >= 0)
{
char *bytes;
! int len, st_size;
st_size = lseek(f, 0L, SEEK_END);
! lseek(f, 0L, SEEK_SET);
! if (st_size > 0 && st_size > c1_stackavail() - 32*1024)
! {
! bytes = (char *)c1xmalloc(st_size);
! len = _read(f, bytes, st_size);
! al->argv[i]->arg_file = parse_bytes(bytes, len);
! free(bytes);
! }
! else
! {
! bytes = (char *)alloca(st_size);
! len = _read(f, bytes, st_size);
! al->argv[i]->arg_file = parse_bytes(bytes, len);
! }
_close(f);
expand_response_files(al->argv[i]->arg_file);
}
- Raw text -