Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoid column names that are not valid PHP identifiers in pl/PHP funct…

…ions.
  • Loading branch information...
commit 9df4fbfb2fe27ebf7ebefcfbbb81ad2fe8e85c2a 1 parent d5076cd
@alexeyklyukin alexeyklyukin authored
Showing with 27 additions and 0 deletions.
  1. +27 −0 plphp.c
View
27 plphp.c
@@ -255,6 +255,7 @@ static zval *plphp_call_php_trig(plphp_proc_desc *desc,
static void plphp_error_cb(int type, const char *filename, const uint lineno,
const char *fmt, va_list args);
+static bool is_valid_php_identifier(char *name);
/*
* FIXME -- this comment is quite misleading actually, which is not surprising
@@ -1451,6 +1452,9 @@ plphp_compile_function(Oid fnoid, bool is_trigger TSRMLS_DC)
}
if (aliases && argnames[i][0] != '\0')
{
+ if (!is_valid_php_identifier(argnames[i]))
+ elog(ERROR, "\"%s\" can not be used as a PHP variable name",
+ argnames[i]);
/* Deal with argument name */
alias_str_end += snprintf(aliases + alias_str_end,
NAMEDATALEN + 32,
@@ -1918,6 +1922,29 @@ plphp_error_cb(int type, const char *filename, const uint lineno,
(errmsg("plphp: %s", str)));
}
+/* Check if the name can be a valid PHP variable name */
+static bool
+is_valid_php_identifier(char *name)
+{
+ int len,
+ i;
+
+ Assert(name);
+
+ len = strlen(name);
+
+ /* Should start from the letter */
+ if (!isalpha(name[0]))
+ return false;
+ for (i = 1; i < len; i++)
+ {
+ /* Only letters, digits and underscores are allowed */
+ if (!isalpha(name[i]) && !isdigit(name[i]) && name[i] != '_')
+ return false;
+ }
+ return true;
+}
+
/*
* vim:ts=4:sw=4:cino=(0
*/

0 comments on commit 9df4fbf

Please sign in to comment.
Something went wrong with that request. Please try again.