Thread: segfault in libpq

segfault in libpq

From
"frank ernest"
Date:
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
thatstarts the process since it's several KiB in size (but yell if yu want it anyways.) The problem in libpq is with
thevaiable:
 
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
TABLEmime_types;");              (void)raise(SIGABRT);   }      result = PQprepare(pgconn, INSERTSTMT, insert_str, 2,
¶mtypes);     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
shouldbe 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,
"DROPTABLE 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



Re: segfault in libpq

From
Tom Lane
Date:
"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
thatstarts the process since it's several KiB in size (but yell if yu want it anyways.) The problem in libpq is with
thevaiable:
 
> 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



Re: segfault in libpq

From
"frank ernest"
Date:
> 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.

Attachment