diff -cprN head/contrib/pgbench/pgbench.c work/contrib/pgbench/pgbench.c *** head/contrib/pgbench/pgbench.c 2010-01-04 09:10:26.638773000 +0900 --- work/contrib/pgbench/pgbench.c 2010-01-04 10:26:43.729385726 +0900 *************** getVariable(CState *st, char *name) *** 431,436 **** --- 431,451 ---- return NULL; } + /* check whether the name consists of alphabets, numerals and underscores. */ + static bool + isLegalVariableName(const char *name) + { + int i; + + for (i = 0; name[i] != '\0'; i++) + { + if (!isalnum((unsigned char) name[i]) && name[i] != '_') + return false; + } + + return true; + } + static int putVariable(CState *st, char *name, char *value) { *************** putVariable(CState *st, char *name, char *** 452,457 **** --- 467,482 ---- { Variable *newvars; + /* + * Check for the name only when declaring a new variable to avoid + * overhead. + */ + if (!isLegalVariableName(name)) + { + fprintf(stderr, "invalid variable name '%s'\n", name); + return false; + } + if (st->variables) newvars = (Variable *) realloc(st->variables, (st->nvariables + 1) * sizeof(Variable)); *************** putVariable(CState *st, char *name, char *** 459,465 **** newvars = (Variable *) malloc(sizeof(Variable)); if (newvars == NULL) ! return false; st->variables = newvars; --- 484,490 ---- newvars = (Variable *) malloc(sizeof(Variable)); if (newvars == NULL) ! goto out_of_memory; st->variables = newvars; *************** putVariable(CState *st, char *name, char *** 493,498 **** --- 518,527 ---- } return true; + + out_of_memory: + fprintf(stderr, "Couldn't allocate memory for variable\n"); + return false; } static char * *************** main(int argc, char **argv) *** 1875,1884 **** *p++ = '\0'; if (putVariable(&state[0], optarg, p) == false) - { - fprintf(stderr, "Couldn't allocate memory for variable\n"); exit(1); - } } break; case 'F': --- 1904,1910 ---- *************** main(int argc, char **argv) *** 1959,1968 **** for (j = 0; j < state[0].nvariables; j++) { if (putVariable(&state[i], state[0].variables[j].name, state[0].variables[j].value) == false) - { - fprintf(stderr, "Couldn't allocate memory for variable\n"); exit(1); - } } } } --- 1985,1991 ---- *************** main(int argc, char **argv) *** 2040,2049 **** for (i = 0; i < nclients; i++) { if (putVariable(&state[i], "scale", val) == false) - { - fprintf(stderr, "Couldn't allocate memory for variable\n"); exit(1); - } } } --- 2063,2069 ----