Add missing NUL terminator in lb_steal().

This commit is contained in:
Gunnar Beutner 2013-03-27 16:01:16 +01:00
parent f1c57ce3a0
commit 4c04c2665c
2 changed files with 85 additions and 81 deletions

View File

@ -664,23 +664,15 @@ static void lb_cleanup(lex_buf *lb)
free(lb->buf);
}
static char *lb_steal(lex_buf *lb)
{
char *buf = lb->buf;
lb->buf = NULL;
lb->size = 0;
return buf;
}
static void lb_append_char(lex_buf *lb, char new_char)
{
const size_t block_size = 64;
size_t old_alloc = (lb->size + (block_size - 1)) / block_size;
size_t new_alloc = ((lb->size + 1) + (block_size - 1)) / block_size;
size_t old_blocks = (lb->size + (block_size - 1)) / block_size;
size_t new_blocks = ((lb->size + 1) + (block_size - 1)) / block_size;
if (old_alloc != new_alloc) {
char *new_buf = (char *)realloc(lb->buf, new_alloc);
if (old_blocks != new_blocks) {
char *new_buf = (char *)realloc(lb->buf, new_blocks * block_size);
if (new_buf == NULL && new_alloc > 0)
throw std::bad_alloc();
@ -691,11 +683,21 @@ static void lb_append_char(lex_buf *lb, char new_char)
lb->size++;
lb->buf[lb->size - 1] = new_char;
}
static char *lb_steal(lex_buf *lb)
{
lb_append_char(lb, '\0');
char *buf = lb->buf;
lb->buf = NULL;
lb->size = 0;
return buf;
}
#define YY_NO_UNISTD_H 1
#line 699 "config_lexer.cc"
#line 701 "config_lexer.cc"
#define INITIAL 0
#define C_COMMENT 1
@ -948,11 +950,11 @@ YY_DECL
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
#line 99 "config_lexer.ll"
#line 101 "config_lexer.ll"
lex_buf string_buf;
#line 956 "config_lexer.cc"
#line 958 "config_lexer.cc"
yylval = yylval_param;
@ -1049,12 +1051,12 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 102 "config_lexer.ll"
#line 104 "config_lexer.ll"
{ lb_init(&string_buf); BEGIN(STRING); }
YY_BREAK
case 2:
YY_RULE_SETUP
#line 104 "config_lexer.ll"
#line 106 "config_lexer.ll"
{
BEGIN(INITIAL);
@ -1068,7 +1070,7 @@ YY_RULE_SETUP
case 3:
/* rule 3 can match eol */
YY_RULE_SETUP
#line 114 "config_lexer.ll"
#line 116 "config_lexer.ll"
{
std::ostringstream msgbuf;
msgbuf << "Unterminated string found: " << *yylloc;
@ -1078,7 +1080,7 @@ YY_RULE_SETUP
YY_BREAK
case 4:
YY_RULE_SETUP
#line 121 "config_lexer.ll"
#line 123 "config_lexer.ll"
{
/* octal escape sequence */
int result;
@ -1097,7 +1099,7 @@ YY_RULE_SETUP
YY_BREAK
case 5:
YY_RULE_SETUP
#line 137 "config_lexer.ll"
#line 139 "config_lexer.ll"
{
/* generate error - bad escape sequence; something
* like '\48' or '\0777777'
@ -1109,38 +1111,38 @@ YY_RULE_SETUP
YY_BREAK
case 6:
YY_RULE_SETUP
#line 146 "config_lexer.ll"
#line 148 "config_lexer.ll"
{ lb_append_char(&string_buf, '\n'); }
YY_BREAK
case 7:
YY_RULE_SETUP
#line 147 "config_lexer.ll"
#line 149 "config_lexer.ll"
{ lb_append_char(&string_buf, '\t'); }
YY_BREAK
case 8:
YY_RULE_SETUP
#line 148 "config_lexer.ll"
#line 150 "config_lexer.ll"
{ lb_append_char(&string_buf, '\r'); }
YY_BREAK
case 9:
YY_RULE_SETUP
#line 149 "config_lexer.ll"
#line 151 "config_lexer.ll"
{ lb_append_char(&string_buf, '\b'); }
YY_BREAK
case 10:
YY_RULE_SETUP
#line 150 "config_lexer.ll"
#line 152 "config_lexer.ll"
{ lb_append_char(&string_buf, '\f'); }
YY_BREAK
case 11:
/* rule 11 can match eol */
YY_RULE_SETUP
#line 151 "config_lexer.ll"
#line 153 "config_lexer.ll"
{ lb_append_char(&string_buf, yytext[1]); }
YY_BREAK
case 12:
YY_RULE_SETUP
#line 153 "config_lexer.ll"
#line 155 "config_lexer.ll"
{
char *yptr = yytext;
@ -1150,12 +1152,12 @@ YY_RULE_SETUP
YY_BREAK
case 13:
YY_RULE_SETUP
#line 160 "config_lexer.ll"
#line 162 "config_lexer.ll"
{ lb_init(&string_buf); BEGIN(HEREDOC); }
YY_BREAK
case 14:
YY_RULE_SETUP
#line 162 "config_lexer.ll"
#line 164 "config_lexer.ll"
{
BEGIN(INITIAL);
@ -1169,224 +1171,224 @@ YY_RULE_SETUP
case 15:
/* rule 15 can match eol */
YY_RULE_SETUP
#line 172 "config_lexer.ll"
#line 174 "config_lexer.ll"
{ lb_append_char(&string_buf, yytext[0]); }
YY_BREAK
case 16:
YY_RULE_SETUP
#line 175 "config_lexer.ll"
#line 177 "config_lexer.ll"
BEGIN(C_COMMENT);
YY_BREAK
case 17:
YY_RULE_SETUP
#line 179 "config_lexer.ll"
#line 181 "config_lexer.ll"
BEGIN(INITIAL);
YY_BREAK
case 18:
/* rule 18 can match eol */
YY_RULE_SETUP
#line 180 "config_lexer.ll"
#line 182 "config_lexer.ll"
/* ignore comment */
YY_BREAK
case 19:
YY_RULE_SETUP
#line 181 "config_lexer.ll"
#line 183 "config_lexer.ll"
/* ignore star */
YY_BREAK
case 20:
YY_RULE_SETUP
#line 184 "config_lexer.ll"
#line 186 "config_lexer.ll"
/* ignore C++-style comments */
YY_BREAK
case 21:
/* rule 21 can match eol */
YY_RULE_SETUP
#line 185 "config_lexer.ll"
#line 187 "config_lexer.ll"
/* ignore whitespace */
YY_BREAK
case 22:
YY_RULE_SETUP
#line 188 "config_lexer.ll"
#line 190 "config_lexer.ll"
return T_TYPE;
YY_BREAK
case 23:
YY_RULE_SETUP
#line 189 "config_lexer.ll"
#line 191 "config_lexer.ll"
{ yylval->type = TypeDictionary; return T_TYPE_DICTIONARY; }
YY_BREAK
case 24:
YY_RULE_SETUP
#line 190 "config_lexer.ll"
#line 192 "config_lexer.ll"
{ yylval->type = TypeArray; return T_TYPE_ARRAY; }
YY_BREAK
case 25:
YY_RULE_SETUP
#line 191 "config_lexer.ll"
#line 193 "config_lexer.ll"
{ yylval->type = TypeNumber; return T_TYPE_NUMBER; }
YY_BREAK
case 26:
YY_RULE_SETUP
#line 192 "config_lexer.ll"
#line 194 "config_lexer.ll"
{ yylval->type = TypeString; return T_TYPE_STRING; }
YY_BREAK
case 27:
YY_RULE_SETUP
#line 193 "config_lexer.ll"
#line 195 "config_lexer.ll"
{ yylval->type = TypeScalar; return T_TYPE_SCALAR; }
YY_BREAK
case 28:
YY_RULE_SETUP
#line 194 "config_lexer.ll"
#line 196 "config_lexer.ll"
{ yylval->type = TypeAny; return T_TYPE_ANY; }
YY_BREAK
case 29:
YY_RULE_SETUP
#line 195 "config_lexer.ll"
#line 197 "config_lexer.ll"
{ return T_VALIDATOR; }
YY_BREAK
case 30:
YY_RULE_SETUP
#line 196 "config_lexer.ll"
#line 198 "config_lexer.ll"
{ return T_REQUIRE; }
YY_BREAK
case 31:
YY_RULE_SETUP
#line 197 "config_lexer.ll"
#line 199 "config_lexer.ll"
{ return T_ATTRIBUTE; }
YY_BREAK
case 32:
YY_RULE_SETUP
#line 198 "config_lexer.ll"
#line 200 "config_lexer.ll"
return T_ABSTRACT;
YY_BREAK
case 33:
YY_RULE_SETUP
#line 199 "config_lexer.ll"
#line 201 "config_lexer.ll"
return T_LOCAL;
YY_BREAK
case 34:
YY_RULE_SETUP
#line 200 "config_lexer.ll"
#line 202 "config_lexer.ll"
return T_OBJECT;
YY_BREAK
case 35:
YY_RULE_SETUP
#line 201 "config_lexer.ll"
#line 203 "config_lexer.ll"
return T_TEMPLATE;
YY_BREAK
case 36:
YY_RULE_SETUP
#line 202 "config_lexer.ll"
#line 204 "config_lexer.ll"
return T_INCLUDE;
YY_BREAK
case 37:
YY_RULE_SETUP
#line 203 "config_lexer.ll"
#line 205 "config_lexer.ll"
return T_LIBRARY;
YY_BREAK
case 38:
YY_RULE_SETUP
#line 204 "config_lexer.ll"
#line 206 "config_lexer.ll"
return T_INHERITS;
YY_BREAK
case 39:
YY_RULE_SETUP
#line 205 "config_lexer.ll"
#line 207 "config_lexer.ll"
return T_NULL;
YY_BREAK
case 40:
YY_RULE_SETUP
#line 206 "config_lexer.ll"
#line 208 "config_lexer.ll"
return T_PARTIAL;
YY_BREAK
case 41:
YY_RULE_SETUP
#line 207 "config_lexer.ll"
#line 209 "config_lexer.ll"
{ yylval->num = 1; return T_NUMBER; }
YY_BREAK
case 42:
YY_RULE_SETUP
#line 208 "config_lexer.ll"
#line 210 "config_lexer.ll"
{ yylval->num = 0; return T_NUMBER; }
YY_BREAK
case 43:
YY_RULE_SETUP
#line 209 "config_lexer.ll"
#line 211 "config_lexer.ll"
{ yylval->text = strdup(yytext); return T_IDENTIFIER; }
YY_BREAK
case 44:
/* rule 44 can match eol */
YY_RULE_SETUP
#line 210 "config_lexer.ll"
#line 212 "config_lexer.ll"
{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
YY_BREAK
case 45:
YY_RULE_SETUP
#line 211 "config_lexer.ll"
#line 213 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
YY_BREAK
case 46:
YY_RULE_SETUP
#line 212 "config_lexer.ll"
#line 214 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }
YY_BREAK
case 47:
YY_RULE_SETUP
#line 213 "config_lexer.ll"
#line 215 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
YY_BREAK
case 48:
YY_RULE_SETUP
#line 214 "config_lexer.ll"
#line 216 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
YY_BREAK
case 49:
YY_RULE_SETUP
#line 215 "config_lexer.ll"
#line 217 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
YY_BREAK
case 50:
YY_RULE_SETUP
#line 216 "config_lexer.ll"
#line 218 "config_lexer.ll"
{ yylval->op = OperatorSet; return T_EQUAL; }
YY_BREAK
case 51:
YY_RULE_SETUP
#line 217 "config_lexer.ll"
#line 219 "config_lexer.ll"
{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
YY_BREAK
case 52:
YY_RULE_SETUP
#line 218 "config_lexer.ll"
#line 220 "config_lexer.ll"
{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
YY_BREAK
case 53:
YY_RULE_SETUP
#line 219 "config_lexer.ll"
#line 221 "config_lexer.ll"
{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
YY_BREAK
case 54:
YY_RULE_SETUP
#line 220 "config_lexer.ll"
#line 222 "config_lexer.ll"
{ yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; }
YY_BREAK
case 55:
YY_RULE_SETUP
#line 223 "config_lexer.ll"
#line 225 "config_lexer.ll"
return yytext[0];
YY_BREAK
case 56:
YY_RULE_SETUP
#line 225 "config_lexer.ll"
#line 227 "config_lexer.ll"
ECHO;
YY_BREAK
#line 1390 "config_lexer.cc"
#line 1392 "config_lexer.cc"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(C_COMMENT):
case YY_STATE_EOF(STRING):
@ -2576,7 +2578,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables"
#line 225 "config_lexer.ll"
#line 227 "config_lexer.ll"

View File

@ -59,14 +59,6 @@ static void lb_cleanup(lex_buf *lb)
free(lb->buf);
}
static char *lb_steal(lex_buf *lb)
{
char *buf = lb->buf;
lb->buf = NULL;
lb->size = 0;
return buf;
}
static void lb_append_char(lex_buf *lb, char new_char)
{
const size_t block_size = 64;
@ -86,6 +78,16 @@ static void lb_append_char(lex_buf *lb, char new_char)
lb->size++;
lb->buf[lb->size - 1] = new_char;
}
static char *lb_steal(lex_buf *lb)
{
lb_append_char(lb, '\0');
char *buf = lb->buf;
lb->buf = NULL;
lb->size = 0;
return buf;
}
%}
%option reentrant noyywrap yylineno