agora inbox for pgsql-interfaces@postgresql.org  
help / color / mirror / Atom feed
segfault in libpq
3+ messages / 2 participants
[nested] [flat]

* segfault in libpq
@ 2014-09-15 16:09  frank ernest <doark@mail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: frank ernest @ 2014-09-15 16:09 UTC (permalink / raw)
  To: pgsql-interfaces

Hi, before I report this as a bug I'd like to know if it's my code or not. I'm not going to send the whole function that starts the process since it's several KiB in size (but yell if yu want it anyways.) The problem in libpq is with the vaiable:
paramValues
Here's the code involving libpq
----------------------------------------
    static const char *insert_str = \
           "INSERT INTO mime_types " \
        "(mime, ext) VALUES ($1, $2);";
-----------------------------------------
    //Create the new table.
    result = PQexec(pgconn,     "CREATE TABLE mime_types ( "  \
    "mime varchar(255) NOT NULL, ext varchar(255) NOT NULL );" );
    
    com_status = PQresultStatus(result);
    
    if(com_status != PGRES_COMMAND_OK)
    {
        GGGerrno_str_ptr = PQerrorMessage(pgconn);
        fprintf(stderr, _(&FPCCT), my_name, &"CREATE TABLE mime_types ( "  \
                 "mime varchar(255) NOT NULL, ext varchar(255) NOT NULL );" );
        fprintf(stderr, _(&PQEMR), GGGerrno_str_ptr);
        
        pg_cleanup(pgconn, "DROP TABLE mime_types;");
        
        (void)raise(SIGABRT);
    }
    
    result = PQprepare(pgconn, INSERTSTMT, insert_str, 2, &paramtypes);
    
    com_status = PQresultStatus(result);
    
    if(com_status != PGRES_COMMAND_OK)
    {
        GGGerrno_str_ptr = PQerrorMessage(pgconn);
        fprintf(stderr, _(&FPCPS), my_name, insert_str );
        fprintf(stderr, _(&PQEMR), GGGerrno_str_ptr);
        
        pg_cleanup(pgconn, "DROP TABLE mime_types;");
        
        (void)raise(SIGABRT);
    }

----------------------------------------------------------------
                        //Split the string into two. Malloc.
                        errno = argz_create_sep(string_to_be_database, \
                                              '=', &argz_str, &argz_len );
                        
                        if(errno)
                        {
                            //This should never happen.
                            GGGerrno_str_ptr = strerror(errno);
                            fprintf(stderr, _(&ERRRE), my_name, \
                                                GGGerrno_str_ptr );
                            (void)raise(SIGABRT);
                        }
                        
                        //There should be no more or less then two strings.
                        count = strcnul(argz_str, argz_len);
                        
                        if(2 != count)
                        {
                            fprintf(stderr, _(&ESS), my_name, \
                                string_to_be_database, argz_len);
                            
                            exit(EXIT_FAILURE);
                        }
                        
                        result = PQexecPrepared(pgconn, INSERTSTMT, 2, \
                                        argz_str, NULL, paramformats, 0 );
                        
                        com_status = PQresultStatus(result);
                        
                        if(com_status != PGRES_COMMAND_OK)
                        {
                            GGGerrno_str_ptr = PQerrorMessage(pgconn);
                            fprintf(stderr, _(&FPCID), my_name);
                            fprintf(stderr, _(&PQEMR), GGGerrno_str_ptr);
                            
                            pg_cleanup(pgconn, "DROP TABLE mime_types;");
                            
                            (void)raise(SIGABRT);
                        }
                        
                        free(argz_str);
                        
                        continue;
-------------------------------------------------------------------


I took the following steps.
create a database called test01
start postgresql on localhost port 1234

In the file mime-types.txt only this line was ever processed.
application/1d-interleaved-parityfec=1d-interleaved-parityfec

I then ran
gdb ./test
(gdb)run /home/me/bin/data/mime-types.txt postgresql://localhost:1234/test01
(gdb)bt
#0  strlen () at ../sysdeps/x86_64/strlen.S:106
#1  0x00007ffff7bc09d6 in PQsendQueryGuts (conn=conn@entry=0x604010, 
    command=command@entry=0x0, stmtName=stmtName@entry=0x401f95 "insert", 
    nParams=nParams@entry=2, paramTypes=paramTypes@entry=0x0, 
    paramValues=paramValues@entry=0x60c840, 
    paramLengths=paramLengths@entry=0x0, 
    paramFormats=paramFormats@entry=0x603110 <paramformats.7077>, 
    resultFormat=resultFormat@entry=0) at fe-exec.c:1464
#2  0x00007ffff7bc0d1e in PQsendQueryPrepared (conn=conn@entry=0x604010, 
    stmtName=stmtName@entry=0x401f95 "insert", nParams=nParams@entry=2, 
    paramValues=paramValues@entry=0x60c840, 
    paramLengths=paramLengths@entry=0x0, 
    paramFormats=paramFormats@entry=0x603110 <paramformats.7077>, 
    resultFormat=resultFormat@entry=0) at fe-exec.c:1308
#3  0x00007ffff7bc1d3b in PQexecPrepared (conn=conn@entry=0x604010, 
    stmtName=stmtName@entry=0x401f95 "insert", nParams=nParams@entry=2, 
    paramValues=0x60c840, paramLengths=paramLengths@entry=0x0, 
    paramFormats=paramFormats@entry=0x603110 <paramformats.7077>, 
    resultFormat=resultFormat@entry=0) at fe-exec.c:1852
#4  0x000000000040134a in build_exts (
    mime_types_file_name=mime_types_file_name@entry=0x7fffffffdbfb "/home/me/bin/data/mime-types.txt", pgconn=pgconn@entry=0x604010)
    at ext-reg-comp.c:342
#5  0x0000000000401bde in main (argc=<optimized out>, argv=<optimized out>)
    at tests/src/ext-reg-comp-test.c:52

Thanks in advance


-- 
Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: segfault in libpq
@ 2014-09-15 16:50  Tom Lane <tgl@sss.pgh.pa.us>
  parent: frank ernest <doark@mail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2014-09-15 16:50 UTC (permalink / raw)
  To: frank ernest <doark@mail.com>; +Cc: pgsql-interfaces

"frank ernest" <doark@mail.com> writes:
> Hi, before I report this as a bug I'd like to know if it's my code or not. I'm not going to send the whole function that starts the process since it's several KiB in size (but yell if yu want it anyways.) The problem in libpq is with the vaiable:
> paramValues

It seems very likely that your code is not setting up the paramValues
array the way libpq expects.  Since you've not shown us the code that
prepares that array, nor even the variable declarations, that's just
an educated guess ... but PQexecPrepared has been around for a long
time and there are no other reports of bugs here.

			regards, tom lane


-- 
Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: segfault in libpq
@ 2014-09-15 20:08  frank ernest <doark@mail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: frank ernest @ 2014-09-15 20:08 UTC (permalink / raw)
  To: pgsql-interfaces

> It seems very likely that your code is not setting up the paramValues
> array the way libpq expects. Since you've not shown us the code that
> prepares that array, nor even the variable declarations, that's just
> an educated guess ... but PQexecPrepared has been around for a long
> time and there are no other reports of bugs here.

The setting up of the array was included. It was set up by argz_create_sep. I'm now including the full source gziped.
This is and was a test suite that I was executing for the full program, that is why some code is extranious.

Thanks again.

-- 
Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces

Attachments:

  [application/octet-stream] source.tar.gz (12.4K, ../../trinity-2d5f685d-19ff-4b91-a361-35aa141df6d5-1410811732666@3capp-mailcom-lxa12/2-source.tar.gz)
  download

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2014-09-15 20:08 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-09-15 16:09 segfault in libpq frank ernest <doark@mail.com>
2014-09-15 16:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2014-09-15 20:08 Re: segfault in libpq frank ernest <doark@mail.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox