Hello,
i was trying the new 1.2.2 release against our openbravo codebase and it segfaults trying to check one of our pl-functions.
Problem is that that the 'refname' if some variable declaration is null and so the is_internal function defaults comparing it to "internal".
Attached patch works around the segfault by adding an explicit null check. Note i just did return true for is_internal to work around the crash. I did not investigate how that variable definition should be classified.
Backtrace from gdb:
#0 __strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31
#1 0x00007f6f55489c46 in is_internal (refname=0x0, lineno=2) at plpgsql_check.c:2897
#2 0x00007f6f55489d14 in datum_is_explicit (cstate=0x7ffd0e884a60, dno=3) at plpgsql_check.c:2923
#3 0x00007f6f5548a022 in report_unused_variables (cstate=0x7ffd0e884a60) at plpgsql_check.c:3033
#4 0x00007f6f55485fd5 in function_check (func=0x561c23b8c460, fcinfo=0x7ffd0e884c40, estate=0x7ffd0e884ad0,
cstate=0x7ffd0e884a60) at plpgsql_check.c:1247
#5 0x00007f6f55485c01 in check_plpgsql_function (procTuple=0x7f6f558d0248, relid=0, trigtype=PLPGSQL_NOT_TRIGGER,
tupdesc=0x561c23b82840, tupstore=0x561c23b82950, format=1, fatal_errors=1 '\001', other_warnings=1 '\001',
performance_warnings=0 '\000', extra_warnings=1 '\001') at plpgsql_check.c:1134
#6 0x00007f6f55484d7b in plpgsql_check_function (fcinfo=0x7ffd0e8851a0) at plpgsql_check.c:651
(gdb) up
#1 0x00007f6f55489c46 in is_internal (refname=0x0, lineno=2) at plpgsql_check.c:2897
warning: Source file is more recent than executable.
2897 if (strcmp(refname, "internal") == 0)
Also attached is the pl-function which is triggered the problem (cut down to the minimum to trigger the crash).
The trigger seems to be having that "declare cursor" line. Removing that make the problem not happen.
Test was done against postgresql-9.3.
Stefan
issue-30.diff.txt
issue-30-reproducer.txt