Skip to content

Segfault adding a label to a function #155

@dvarrazzo

Description

@dvarrazzo

Trying to run the checker on psycopg again 🎉 Trying with psycopg/psycopg2@23438ce and gcc-python-plugin master at 41f52bd. Tested on Ubuntu 18.04 with gcc 5.5.0 and 6.5.0 (packages gcc-5 and gcc-6).

just a CC=gcc-with-cpychecker make fails on a file too complex, so I'm trying to run a normal make and using the generated commands to test the source files one-by-one. In particular here I'm playing with the file psycopg/utils.c so in order to get a command line you can use:

$ make | grep utils.c
x86_64-linux-gnu-gcc [options] -c psycopg/utils.c [more options]

and run instead:

$ CC_FOR_CPYCHECKER=gcc-6 /path/to/gcc-with-cpychecker [options] -c psycopg/utils.c [more options]

(Note that the -DPSYCOPG_VERSION option contain spaces so it needs quoting).

Testing the file psycopg/utils.c, a warning on the function psycopg_escape_string() being too complex is generated (is it?). Trying munging, applying the seemingly harmless patch:

piro@makkuro:~/dev/psycopg2$ git diff
diff --git a/psycopg/utils.c b/psycopg/utils.c
index 261810f..c135072 100644
--- a/psycopg/utils.c
+++ b/psycopg/utils.c
@@ -89,6 +89,7 @@ psycopg_escape_string(connectionObject *conn, const char *from, Py_ssize_t len,
     if (tolen)
         *tolen = ql+eq+2;
 
+exit:
     return to;
 }
 

results in a segfault with the following output:

psycopg/utils.c: In function ‘psycopg_escape_string’:
psycopg/utils.c:92:1: warning: label ‘exit’ defined but not used [-Wunused-label]
 exit:
 ^~~~
*** WARNING *** there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins.
Event                            | Plugins
PLUGIN_FINISH_DECL               | python
PLUGIN_FINISH                    | python
PLUGIN_ATTRIBUTES                | python
psycopg/utils.c:90:16: internal compiler error: Segmentation fault
         *tolen = ql+eq+2;
         ~~~~~~~^~~~~~~~~
0x7f68dbae4f1a impl_execute
	/home/piro/dev/fs/gcc-python-plugin/gcc-python-pass.c:134
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-6/README.Bugs> for instructions.

Same problem with gcc-5. gcc-7 doesn't deal with refcount check so not playing with it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions