version 1.1.1.2, 2012/05/29 12:26:49
|
version 1.1.1.3, 2013/07/22 10:46:12
|
Line 1
|
Line 1
|
/* |
/* |
* Copyright (c) 1996, 1998-2005, 2007-2011 | * Copyright (c) 1996, 1998-2005, 2007-2013 |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
Line 25
|
Line 25
|
#include <config.h> |
#include <config.h> |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/param.h> |
|
#include <stdio.h> |
#include <stdio.h> |
#ifdef STDC_HEADERS |
#ifdef STDC_HEADERS |
# include <stdlib.h> |
# include <stdlib.h> |
Line 48
|
Line 47
|
# include <malloc.h> |
# include <malloc.h> |
#endif /* HAVE_MALLOC_H && !STDC_HEADERS */ |
#endif /* HAVE_MALLOC_H && !STDC_HEADERS */ |
#include <ctype.h> |
#include <ctype.h> |
|
#include <errno.h> |
|
|
#include "sudoers.h" |
#include "sudoers.h" |
#include "parse.h" |
#include "parse.h" |
Line 57
|
Line 57
|
static int arg_len = 0; |
static int arg_len = 0; |
static int arg_size = 0; |
static int arg_size = 0; |
|
|
static int |
|
hexchar(const char *s) |
|
{ |
|
int i, result = 0; |
|
debug_decl(hexchar, SUDO_DEBUG_PARSER) |
|
|
|
s += 2; /* skip \\x */ |
|
for (i = 0; i < 2; i++) { |
|
switch (*s) { |
|
case 'A': |
|
case 'a': |
|
result += 10; |
|
break; |
|
case 'B': |
|
case 'b': |
|
result += 11; |
|
break; |
|
case 'C': |
|
case 'c': |
|
result += 12; |
|
break; |
|
case 'D': |
|
case 'd': |
|
result += 13; |
|
break; |
|
case 'E': |
|
case 'e': |
|
result += 14; |
|
break; |
|
case 'F': |
|
case 'f': |
|
result += 15; |
|
break; |
|
default: |
|
result += *s - '0'; |
|
break; |
|
} |
|
if (i == 0) { |
|
result *= 16; |
|
s++; |
|
} |
|
} |
|
debug_return_int(result); |
|
} |
|
|
|
bool |
bool |
fill_txt(const char *src, int len, int olen) |
fill_txt(const char *src, int len, int olen) |
{ |
{ |
char *dst; |
char *dst; |
debug_decl(fill_txt, SUDO_DEBUG_PARSER) |
debug_decl(fill_txt, SUDO_DEBUG_PARSER) |
|
|
dst = olen ? realloc(yylval.string, olen + len + 1) : malloc(len + 1); | dst = olen ? realloc(sudoerslval.string, olen + len + 1) : malloc(len + 1); |
if (dst == NULL) { |
if (dst == NULL) { |
yyerror(_("unable to allocate memory")); | warning(NULL); |
| sudoerserror(NULL); |
debug_return_bool(false); |
debug_return_bool(false); |
} |
} |
yylval.string = dst; | sudoerslval.string = dst; |
|
|
/* Copy the string and collapse any escaped characters. */ |
/* Copy the string and collapse any escaped characters. */ |
dst += olen; |
dst += olen; |
Line 122 fill_txt(const char *src, int len, int olen)
|
Line 78 fill_txt(const char *src, int len, int olen)
|
if (src[1] == 'x' && len >= 3 && |
if (src[1] == 'x' && len >= 3 && |
isxdigit((unsigned char) src[2]) && |
isxdigit((unsigned char) src[2]) && |
isxdigit((unsigned char) src[3])) { |
isxdigit((unsigned char) src[3])) { |
*dst++ = hexchar(src); | *dst++ = hexchar(src + 2); |
src += 4; |
src += 4; |
len -= 3; |
len -= 3; |
} else { |
} else { |
Line 144 append(const char *src, int len)
|
Line 100 append(const char *src, int len)
|
int olen = 0; |
int olen = 0; |
debug_decl(append, SUDO_DEBUG_PARSER) |
debug_decl(append, SUDO_DEBUG_PARSER) |
|
|
if (yylval.string != NULL) | if (sudoerslval.string != NULL) |
olen = strlen(yylval.string); | olen = strlen(sudoerslval.string); |
|
|
debug_return_bool(fill_txt(src, len, olen)); |
debug_return_bool(fill_txt(src, len, olen)); |
} |
} |
Line 162 fill_cmnd(const char *src, int len)
|
Line 118 fill_cmnd(const char *src, int len)
|
|
|
arg_len = arg_size = 0; |
arg_len = arg_size = 0; |
|
|
dst = yylval.command.cmnd = (char *) malloc(len + 1); | dst = sudoerslval.command.cmnd = (char *) malloc(len + 1); |
if (yylval.command.cmnd == NULL) { | if (sudoerslval.command.cmnd == NULL) { |
yyerror(_("unable to allocate memory")); | warning(NULL); |
| sudoerserror(NULL); |
debug_return_bool(false); |
debug_return_bool(false); |
} |
} |
|
|
Line 177 fill_cmnd(const char *src, int len)
|
Line 134 fill_cmnd(const char *src, int len)
|
} |
} |
*dst = '\0'; |
*dst = '\0'; |
|
|
yylval.command.args = NULL; | sudoerslval.command.args = NULL; |
debug_return_bool(true); |
debug_return_bool(true); |
} |
} |
|
|
Line 188 fill_args(const char *s, int len, int addspace)
|
Line 145 fill_args(const char *s, int len, int addspace)
|
char *p; |
char *p; |
debug_decl(fill_args, SUDO_DEBUG_PARSER) |
debug_decl(fill_args, SUDO_DEBUG_PARSER) |
|
|
if (yylval.command.args == NULL) { | if (sudoerslval.command.args == NULL) { |
addspace = 0; |
addspace = 0; |
new_len = len; |
new_len = len; |
} else |
} else |
Line 199 fill_args(const char *s, int len, int addspace)
|
Line 156 fill_args(const char *s, int len, int addspace)
|
while (new_len >= (arg_size += COMMANDARGINC)) |
while (new_len >= (arg_size += COMMANDARGINC)) |
; |
; |
|
|
p = yylval.command.args ? | p = sudoerslval.command.args ? |
(char *) realloc(yylval.command.args, arg_size) : | (char *) realloc(sudoerslval.command.args, arg_size) : |
(char *) malloc(arg_size); |
(char *) malloc(arg_size); |
if (p == NULL) { |
if (p == NULL) { |
efree(yylval.command.args); | efree(sudoerslval.command.args); |
yyerror(_("unable to allocate memory")); | warning(NULL); |
| sudoerserror(NULL); |
debug_return_bool(false); |
debug_return_bool(false); |
} else |
} else |
yylval.command.args = p; | sudoerslval.command.args = p; |
} |
} |
|
|
/* Efficiently append the arg (with a leading space if needed). */ |
/* Efficiently append the arg (with a leading space if needed). */ |
p = yylval.command.args + arg_len; | p = sudoerslval.command.args + arg_len; |
if (addspace) |
if (addspace) |
*p++ = ' '; |
*p++ = ' '; |
if (strlcpy(p, s, arg_size - (p - yylval.command.args)) != len) { | if (strlcpy(p, s, arg_size - (p - sudoerslval.command.args)) != len) { |
yyerror(_("fill_args: buffer overflow")); /* paranoia */ | warningx(_("fill_args: buffer overflow")); /* paranoia */ |
| sudoerserror(NULL); |
debug_return_bool(false); |
debug_return_bool(false); |
} |
} |
arg_len = new_len; |
arg_len = new_len; |