On Wed, 2004-12-01 at 21:41 -0700, Michael Fuhr wrote:
> % 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

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:p:U:P:d:t:o: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
---------------------------(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

Reply via email to