diff options
Diffstat (limited to 'src/bin/psql/variables.c')
-rw-r--r-- | src/bin/psql/variables.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c index 38252893377..a43c786bf02 100644 --- a/src/bin/psql/variables.c +++ b/src/bin/psql/variables.c @@ -6,11 +6,41 @@ * src/bin/psql/variables.c */ #include "postgres_fe.h" + #include "common.h" #include "variables.h" /* + * Check whether a variable's name is allowed. + * + * We allow any non-ASCII character, as well as ASCII letters, digits, and + * underscore. Keep this in sync with the definition of variable_char in + * psqlscan.l. + */ +static bool +valid_variable_name(const char *name) +{ + const unsigned char *ptr = (const unsigned char *) name; + + /* Mustn't be zero-length */ + if (*ptr == '\0') + return false; + + while (*ptr) + { + if (IS_HIGHBIT_SET(*ptr) || + strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" + "_0123456789", *ptr) != NULL) + ptr++; + else + return false; + } + + return true; +} + +/* * A "variable space" is represented by an otherwise-unused struct _variable * that serves as list header. */ @@ -158,7 +188,7 @@ SetVariable(VariableSpace space, const char *name, const char *value) if (!space) return false; - if (strspn(name, VALID_VARIABLE_CHARS) != strlen(name)) + if (!valid_variable_name(name)) return false; if (!value) @@ -202,7 +232,7 @@ SetVariableAssignHook(VariableSpace space, const char *name, VariableAssignHook if (!space) return false; - if (strspn(name, VALID_VARIABLE_CHARS) != strlen(name)) + if (!valid_variable_name(name)) return false; for (previous = space, current = space->next; |