summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Conway2019-12-23 18:33:25 +0000
committerJoe Conway2019-12-23 18:33:25 +0000
commitd5b9c2baff662aac22cd2a497d5bcd3b5a916fd0 (patch)
treee9c9b4208bc62f2f729f2c54724f19a7bf335d8a
parent39ebb943de9dd64e305d17329b8989e3061d03a5 (diff)
Disallow null category in crosstab_hash
While building a hash map of categories in load_categories_hash, resulting category names have not thus far been checked to ensure they are not null. Prior to pg12 null category names worked to the extent that they did not crash on some platforms. This is because those system libraries have an snprintf which can deal with being passed a null pointer argument for a string. But even in those cases null categories did nothing useful. And on some platforms it crashed. As of pg12, our own version of snprintf gets called, and it does not deal with null pointer arguments at all, and crashes consistently. Fix that by disallowing null categories. They never worked usefully, and no one has ever asked for them to work previously. Back-patch to all supported branches. Reported-By: Ireneusz Pluta Discussion: https://postgr.es/m/[email protected]
-rw-r--r--contrib/tablefunc/tablefunc.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index 256d52fc629..1072827784f 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -762,6 +762,11 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
/* get the category from the current sql result tuple */
catname = SPI_getvalue(spi_tuple, spi_tupdesc, 1);
+ if (catname == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("provided \"categories\" SQL must " \
+ "not return NULL values")));
SPIcontext = MemoryContextSwitchTo(per_query_ctx);