dbTalk Databases Forums  

[BUGS] oid2name core dump

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] oid2name core dump in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Fuhr
 
Posts: n/a

Default [BUGS] oid2name core dump - 12-01-2004 , 10:44 PM






PostgreSQL 8.0.0beta5 (CVS HEAD)
Solaris 9
gcc 3.4.2

oid2name consistently dumps core:

% oid2name -d test -f 77199
From database "test":
Segmentation fault (core dumped)

(gdb) where
#0 0xfee473ec in realfree () from /usr/lib/libc.so.1
#1 0xfee47cec in cleanfree () from /usr/lib/libc.so.1
#2 0xfee46e18 in _malloc_unlocked () from /usr/lib/libc.so.1


On FreeBSD 4.10-STABLE oid2name runs but prints warnings about
freeing junk pointers:

% oid2name -d test -f 173181
From database "test":
oid2name in free(): warning: junk pointer, too low to make sense
oid2name in free(): warning: junk pointer, too low to make sense
Filenode Table Name
----------------------
173181 foo


The warnings are coming from these two lines (around lines 448 and 449):

free(comma_oids);
free(comma_tables);

Apparently the values of comma_oids and comma_tables are bogus.
I haven't looked more closely yet to see why.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply With Quote
  #2  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: [BUGS] oid2name core dump - 12-01-2004 , 10:58 PM






On Wed, Dec 01, 2004 at 09:41:49PM -0700, Michael Fuhr wrote:

Quote:
The warnings are coming from these two lines (around lines 448 and 449):

free(comma_oids);
free(comma_tables);

Apparently the values of comma_oids and comma_tables are bogus.
I haven't looked more closely yet to see why.
main() initializes my_opts->oids->num and my_opts->tables->num to 0.
sql_exec_searchtables() later sets comma_oids and comma_tables with
the following code:

comma_oids = get_comma_elts(opts->oids);
comma_tables = get_comma_elts(opts->tables);

get_comma_elts() starts with the following:

if (eary->num == 0)
return "";

sql_exec_searchtables() later tries to free the pointers to "".
Program fall down go boom.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
  #3  
Old   
Neil Conway
 
Posts: n/a

Default Re: [BUGS] oid2name core dump - 12-02-2004 , 12:13 AM



--=-2/f0aitEGhqaiT9gr8/n
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2004-12-01 at 21:41 -0700, Michael Fuhr wrote:
Quote:
% oid2name -d test -f 173181
From database "test":
oid2name in free(): warning: junk pointer, too low to make sense
oid2name in free(): warning: junk pointer, too low to make sense
Filenode Table Name
----------------------
173181 foo
I checked in a fix for this to HEAD; the patch is attached. I also
noticed various other brokenness in oid2name (access to uninitialized
variables, malloc() + sscanf() rather than strdup(), etc.), which I
fixed.

Thanks for the report.

-Neil


--=-2/f0aitEGhqaiT9gr8/n
Content-Disposition: attachment; filename=oid2name-fixes-1.patch
Content-Type: text/x-patch; name=oid2name-fixes-1.patch; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Index: contrib/oid2name/oid2name.c
================================================== =================
RCS file: /var/lib/cvs/pgsql/contrib/oid2name/oid2name.c,v
retrieving revision 1.25
diff -c -r1.25 oid2name.c
*** contrib/oid2name/oid2name.c 5 Nov 2004 19:15:45 -0000 1.25
--- contrib/oid2name/oid2name.c 2 Dec 2004 06:03:36 -0000
***************
*** 46,51 ****
--- 46,52 ----
/* function prototypes */
void get_opts(int, char **, struct options *);
void *myalloc(size_t size);
+ char *mystrdup(const char *str);
void add_one_elt(char *eltname, eary *eary);
char *get_comma_elts(eary *eary);
PGconn *sql_conn(struct options *);
***************
*** 68,73 ****
--- 69,79 ----
my_opts->nodb = false;
my_opts->extended = false;
my_opts->tablespaces = false;
+ my_opts->dbname = NULL;
+ my_opts->hostname = NULL;
+ my_opts->port = NULL;
+ my_opts->username = NULL;
+ my_opts->password = NULL;

/* get opts */
while ((c = getopt(argc, argv, "H:U:P:d:t:f:qSxish?")) != -1)
***************
*** 76,83 ****
{
/* specify the database */
case 'd':
! my_opts->dbname = (char *) myalloc(strlen(optarg));
! sscanf(optarg, "%s", my_opts->dbname);
break;

/* specify one tablename to show */
--- 82,88 ----
{
/* specify the database */
case 'd':
! my_opts->dbname = mystrdup(optarg);
break;

/* specify one tablename to show */
***************
*** 102,127 ****

/* host to connect to */
case 'H':
! my_opts->hostname = (char *) myalloc(strlen(optarg));
! sscanf(optarg, "%s", my_opts->hostname);
break;

/* port to connect to on remote host */
case 'p':
! my_opts->port = (char *) myalloc(strlen(optarg));
! sscanf(optarg, "%s", my_opts->port);
break;

/* username */
case 'U':
! my_opts->username = (char *) myalloc(strlen(optarg));
! sscanf(optarg, "%s", my_opts->username);
break;

/* password */
case 'P':
! my_opts->password = (char *) myalloc(strlen(optarg));
! sscanf(optarg, "%s", my_opts->password);
break;

/* display system tables */
--- 107,128 ----

/* host to connect to */
case 'H':
! my_opts->hostname = mystrdup(optarg);
break;

/* port to connect to on remote host */
case 'p':
! my_opts->port = mystrdup(optarg);
break;

/* username */
case 'U':
! my_opts->username = mystrdup(optarg);
break;

/* password */
case 'P':
! my_opts->password = mystrdup(optarg);
break;

/* display system tables */
***************
*** 183,188 ****
--- 184,201 ----
return ptr;
}

+ char *
+ mystrdup(const char *str)
+ {
+ char *result = strdup(str);
+ if (!result)
+ {
+ fprintf(stderr, "out of memory");
+ exit(1);
+ }
+ return result;
+ }
+
/*
* add_one_elt
*
***************
*** 208,214 ****
}
}

! eary->array[eary->num] = strdup(eltname);
eary->num++;
}

--- 221,227 ----
}
}

! eary->array[eary->num] = mystrdup(eltname);
eary->num++;
}

***************
*** 227,233 ****
int i, length = 0;

if (eary->num == 0)
! return "";

/*
* PQescapeString wants 2 * length + 1 bytes of breath space. Add two
--- 240,246 ----
int i, length = 0;

if (eary->num == 0)
! return mystrdup("");

/*
* PQescapeString wants 2 * length + 1 bytes of breath space. Add two

--=-2/f0aitEGhqaiT9gr8/n
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

--=-2/f0aitEGhqaiT9gr8/n--



Reply With Quote
  #4  
Old   
Alvaro Herrera
 
Posts: n/a

Default Re: [BUGS] oid2name core dump - 12-02-2004 , 08:21 AM



On Thu, Dec 02, 2004 at 05:11:22PM +1100, Neil Conway wrote:

Quote:
I checked in a fix for this to HEAD; the patch is attached. I also
noticed various other brokenness in oid2name (access to uninitialized
variables, malloc() + sscanf() rather than strdup(), etc.), which I
fixed.
I think they were mostly my bugs. Thanks for fixing.

--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"I suspect most samba developers are already technically insane...
Of course, since many of them are Australians, you can't tell." (L. Torvalds)

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.