pgbench_verify_varname_20091228.patch
application/octet-stream
Filename: pgbench_verify_varname_20091228.patch
Type: application/octet-stream
Part: 0
Message:
Verifying variable names in pgbench
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: context
| File | + | − |
|---|---|---|
| contrib/pgbench/pgbench.c | 31 | 10 |
diff -cprN head/contrib/pgbench/pgbench.c work/contrib/pgbench/pgbench.c
*** head/contrib/pgbench/pgbench.c 2009-12-15 16:28:45.231538000 +0900
--- work/contrib/pgbench/pgbench.c 2009-12-28 12:25:08.389037115 +0900
*************** putVariable(CState *st, char *name, char
*** 451,456 ****
--- 451,482 ----
if (var == NULL)
{
Variable *newvars;
+ int i;
+
+ /*
+ * Check for the name only when declaring a new variable to avoid
+ * overhead.
+ */
+ for (i = 0; name[i]; i++)
+ {
+ if (!isalnum((unsigned char) name[i]) && name[i] != '_')
+ {
+ Command **file;
+ Command *command;
+ const char *argv0;
+
+ /* Command might not be available during startup. */
+ if ((file = sql_files[st->use_file]) != NULL &&
+ (command = file[st->state]) != NULL &&
+ command->argc > 0 && command->argv[0] != NULL)
+ argv0 = command->argv[0];
+ else
+ argv0 = "(global)";
+
+ fprintf(stderr, "%s: invalid variable name '%s'\n", argv0, name);
+ return false;
+ }
+ }
if (st->variables)
newvars = (Variable *) realloc(st->variables,
*************** putVariable(CState *st, char *name, char
*** 459,465 ****
newvars = (Variable *) malloc(sizeof(Variable));
if (newvars == NULL)
! return false;
st->variables = newvars;
--- 485,491 ----
newvars = (Variable *) malloc(sizeof(Variable));
if (newvars == NULL)
! goto out_of_memory;
st->variables = newvars;
*************** putVariable(CState *st, char *name, char
*** 493,498 ****
--- 519,528 ----
}
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':
--- 1905,1911 ----
*************** 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);
- }
}
}
}
--- 1986,1992 ----
*************** 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);
- }
}
}
--- 2064,2070 ----