=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sudo/Attic/parse.lex,v retrieving revision 1.8 retrieving revision 1.9 diff -c -r1.8 -r1.9 *** src/usr.bin/sudo/Attic/parse.lex 2003/01/07 00:04:48 1.8 --- src/usr.bin/sudo/Attic/parse.lex 2003/03/15 21:23:54 1.9 *************** *** 1,6 **** %{ /* ! * Copyright (c) 1996, 1998-2001 Todd C. Miller * All rights reserved. * * This code is derived from software contributed by Chris Jepeway. --- 1,6 ---- %{ /* ! * Copyright (c) 1996, 1998-2003 Todd C. Miller * All rights reserved. * * This code is derived from software contributed by Chris Jepeway. *************** *** 68,74 **** #include #ifndef lint ! static const char rcsid[] = "$Sudo: parse.lex,v 1.119 2002/03/16 00:44:47 millert Exp $"; #endif /* lint */ #undef yywrap /* guard against a yywrap macro */ --- 68,74 ---- #include #ifndef lint ! static const char rcsid[] = "$Sudo: parse.lex,v 1.126 2003/03/15 20:31:02 millert Exp $"; #endif /* lint */ #undef yywrap /* guard against a yywrap macro */ *************** *** 99,105 **** OCTET (1?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]) DOTTEDQUAD {OCTET}(\.{OCTET}){3} HOSTNAME [[:alnum:]_-]+ ! WORD ([^#@!=:,\(\) \t\n\\]|\\[^\n])+ ENVAR ([^#!=, \t\n\\]|\\[^\n])([^#=, \t\n\\]|\\[^\n])* DEFVAR [a-z_]+ --- 99,105 ---- OCTET (1?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]) DOTTEDQUAD {OCTET}(\.{OCTET}){3} HOSTNAME [[:alnum:]_-]+ ! WORD ([^#>@!=:,\(\) \t\n\\]|\\[^\n])+ ENVAR ([^#!=, \t\n\\]|\\[^\n])([^#=, \t\n\\]|\\[^\n])* DEFVAR [a-z_]+ *************** *** 175,186 **** } /* a command line arg */ } ! ^Defaults[:@]? { BEGIN GOTDEFS; switch (yytext[8]) { case ':': LEXTRACE("DEFAULTS_USER "); return(DEFAULTS_USER); case '@': LEXTRACE("DEFAULTS_HOST "); return(DEFAULTS_HOST); --- 175,189 ---- } /* a command line arg */ } ! ^Defaults[:@>]? { BEGIN GOTDEFS; switch (yytext[8]) { case ':': LEXTRACE("DEFAULTS_USER "); return(DEFAULTS_USER); + case '>': + LEXTRACE("DEFAULTS_RUNAS "); + return(DEFAULTS_RUNAS); case '@': LEXTRACE("DEFAULTS_HOST "); return(DEFAULTS_HOST); *************** *** 362,369 **** int i, j; yylval.string = (char *) malloc(len + 1); ! if (yylval.string == NULL) yyerror("unable to allocate memory"); /* Copy the string and collapse any escaped characters. */ for (i = 0, j = 0; i < len; i++, j++) { --- 365,374 ---- int i, j; yylval.string = (char *) malloc(len + 1); ! if (yylval.string == NULL) { yyerror("unable to allocate memory"); + return; + } /* Copy the string and collapse any escaped characters. */ for (i = 0, j = 0; i < len; i++, j++) { *************** *** 382,394 **** { arg_len = arg_size = 0; ! yylval.command.cmnd = (char *) malloc(len + 1); ! if (yylval.command.cmnd == NULL) yyerror("unable to allocate memory"); /* copy the string and NULL-terminate it (escapes handled by fnmatch) */ ! (void) strncpy(yylval.command.cmnd, s, len); ! yylval.command.cmnd[len] = '\0'; yylval.command.args = NULL; } --- 387,400 ---- { arg_len = arg_size = 0; ! yylval.command.cmnd = (char *) malloc(++len); ! if (yylval.command.cmnd == NULL) { yyerror("unable to allocate memory"); + return; + } /* copy the string and NULL-terminate it (escapes handled by fnmatch) */ ! (void) strlcpy(yylval.command.cmnd, s, len); yylval.command.args = NULL; } *************** *** 402,442 **** int new_len; char *p; - /* - * If first arg, malloc() some room, else if we don't - * have enough space realloc() some more. - */ if (yylval.command.args == NULL) { addspace = 0; new_len = len; while (new_len >= (arg_size += COMMANDARGINC)) ; ! yylval.command.args = (char *) malloc(arg_size); ! if (yylval.command.args == NULL) ! yyerror("unable to allocate memory"); ! } else { ! new_len = arg_len + len + addspace; ! ! if (new_len >= arg_size) { ! /* Allocate more space than we need for subsequent args */ ! while (new_len >= (arg_size += COMMANDARGINC)) ! ; ! ! if ((p = (char *) realloc(yylval.command.args, arg_size)) == NULL) { free(yylval.command.args); ! yyerror("unable to allocate memory"); ! } else ! yylval.command.args = p; ! } } /* Efficiently append the arg (with a leading space if needed). */ p = yylval.command.args + arg_len; if (addspace) *p++ = ' '; ! (void) strcpy(p, s); arg_len = new_len; } --- 408,442 ---- int new_len; char *p; if (yylval.command.args == NULL) { addspace = 0; new_len = len; + } else + new_len = arg_len + len + addspace; + if (new_len >= arg_size) { + /* Allocate more space than we need for subsequent args */ while (new_len >= (arg_size += COMMANDARGINC)) ; ! p = yylval.command.args ? ! (char *) realloc(yylval.command.args, arg_size) : ! (char *) malloc(arg_size); ! if (p == NULL) { ! if (yylval.command.args != NULL) free(yylval.command.args); ! yyerror("unable to allocate memory"); ! return; ! } else ! yylval.command.args = p; } /* Efficiently append the arg (with a leading space if needed). */ p = yylval.command.args + arg_len; if (addspace) *p++ = ' '; ! if (strlcpy(p, s, arg_size - (p - yylval.command.args)) != len) ! yyerror("fill_args: buffer overflow"); /* paranoia */ arg_len = new_len; }