From: | "frank ernest" <doark(at)mail(dot)com> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | segfault in libpq |
Date: | 2014-09-15 16:09:45 |
Message-ID: | trinity-31011ab9-a78d-449a-b500-6b1d8ccfbc5b-1410797385159@3capp-mailcom-lxa04 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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, ¶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 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(at)entry=0x604010,
command=command(at)entry=0x0, stmtName=stmtName(at)entry=0x401f95 "insert",
nParams=nParams(at)entry=2, paramTypes=paramTypes(at)entry=0x0,
paramValues=paramValues(at)entry=0x60c840,
paramLengths=paramLengths(at)entry=0x0,
paramFormats=paramFormats(at)entry=0x603110 <paramformats.7077>,
resultFormat=resultFormat(at)entry=0) at fe-exec.c:1464
#2 0x00007ffff7bc0d1e in PQsendQueryPrepared (conn=conn(at)entry=0x604010,
stmtName=stmtName(at)entry=0x401f95 "insert", nParams=nParams(at)entry=2,
paramValues=paramValues(at)entry=0x60c840,
paramLengths=paramLengths(at)entry=0x0,
paramFormats=paramFormats(at)entry=0x603110 <paramformats.7077>,
resultFormat=resultFormat(at)entry=0) at fe-exec.c:1308
#3 0x00007ffff7bc1d3b in PQexecPrepared (conn=conn(at)entry=0x604010,
stmtName=stmtName(at)entry=0x401f95 "insert", nParams=nParams(at)entry=2,
paramValues=0x60c840, paramLengths=paramLengths(at)entry=0x0,
paramFormats=paramFormats(at)entry=0x603110 <paramformats.7077>,
resultFormat=resultFormat(at)entry=0) at fe-exec.c:1852
#4 0x000000000040134a in build_exts (
mime_types_file_name=mime_types_file_name(at)entry=0x7fffffffdbfb "/home/me/bin/data/mime-types.txt", pgconn=pgconn(at)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2014-09-15 16:50:30 | Re: segfault in libpq |
Previous Message | Greg Sabino Mullane | 2014-08-18 14:53:30 | DBD::Pg 3.4.0 released |