nahanni / rw_redis_fdw

Other
97 stars 23 forks source link

segfault postgresql on null key in redisIterateForeignScan #11

Closed dumbuzz closed 7 years ago

dumbuzz commented 7 years ago

Caught segfault of postgresql master process on null key. SQL-query: select array_agg(rdva.value order by rdva.index) into m_visitor_actions from redis_db0_visitor_actions as rdva where key = var_visitorActionKeyPrefix || var_visitorID || var_date_suffix; Due to expression in where clause, the key in redis_fdw.c parse_where_clause sometimes (due to postgresql planner behavior of precalulating and caching where clauses) obtain null-value (logging with message: unable to process subexpr type 311).

redis_db0_visitor_actions is of redistype "list".

Then in redisIterateForeignScan function it send null key to hiredis redisCommand (LLEN in my case), which segfaults master postgresql process, because hiredis can't work with null values for keys.

To prevent this, it needs to add NULL-check for key in all redisCommand calls inside redisIterateForeignScan where key is mandatory argument.

l-d-x commented 7 years ago

can you do a test to verify fix.

dumbuzz commented 7 years ago

yes, I test your fix....correct.....no segfault now, just error "key is NULL" - it's what should be excpected