Re: [HACKERS] pg_dump 9.1.1 hanging (collectSecLabels gets 0 labels)

2011-11-10 Thread Steve Singer

On 11-11-09 06:35 PM, Tom Lane wrote:

Steve Singerssin...@ca.afilias.info  writes:

I've tracked the issue down to collectSecLabels in pg_dump.c



SELECT label, provider, classoid, objoid, objsbid FROM
pg_catalog.pg_seclabel;



returns 0 rows.



The code in collectSecLabels() is not prepared to deal with a zero row
result and tries to malloc 0 bytes.


pg_seclabel is almost always empty, so I'm not convinced that you've
identified your problem correctly.

regards, tom lane



The attached patch seems to fix the issue.

The man page for malloc on AIX is pretty clear on what happens when you 
try to malloc 0 bytes.  It returns NULL.
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index fce9d3b..9e31767 100644
*** a/src/bin/pg_dump/pg_dump.c
--- b/src/bin/pg_dump/pg_dump.c
*** findSecLabels(Archive *fout, Oid classoi
*** 11760,11766 
  	/* Get security labels if we didn't already */
  	if (nlabels  0)
  		nlabels = collectSecLabels(fout, labels);
! 
  	/*
  	 * Do binary search to find some item matching the object.
  	 */
--- 11760,11770 
  	/* Get security labels if we didn't already */
  	if (nlabels  0)
  		nlabels = collectSecLabels(fout, labels);
! 	if (nlabels == 0)
! 	{
! 		*items=NULL;
! 		return 0;
! 	}
  	/*
  	 * Do binary search to find some item matching the object.
  	 */
*** collectSecLabels(Archive *fout, SecLabel
*** 11858,11875 
  	i_objsubid = PQfnumber(res, objsubid);
  
  	ntups = PQntuples(res);
! 
! 	labels = (SecLabelItem *) malloc(ntups * sizeof(SecLabelItem));
! 
! 	for (i = 0; i  ntups; i++)
  	{
! 		labels[i].label = PQgetvalue(res, i, i_label);
! 		labels[i].provider = PQgetvalue(res, i, i_provider);
! 		labels[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
! 		labels[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
! 		labels[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
  	}
  
  	/* Do NOT free the PGresult since we are keeping pointers into it */
  	destroyPQExpBuffer(query);
  
--- 11862,11889 
  	i_objsubid = PQfnumber(res, objsubid);
  
  	ntups = PQntuples(res);
! 	if ( ntups == 0)
  	{
! 		labels = NULL;
  	}
+ 	else
+ 	{
+ 		labels = (SecLabelItem *) malloc(ntups * sizeof(SecLabelItem));
+ 		if (labels == NULL )
+ 		{
+ 			write_msg(NULL, out of memory);
+ 			exit(1);
+ 		}
  
+ 		for (i = 0; i  ntups; i++)
+ 		{
+ 			labels[i].label = PQgetvalue(res, i, i_label);
+ 			labels[i].provider = PQgetvalue(res, i, i_provider);
+ 			labels[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
+ 			labels[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
+ 			labels[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
+ 		}
+ 	}
  	/* Do NOT free the PGresult since we are keeping pointers into it */
  	destroyPQExpBuffer(query);
  

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


Re: [HACKERS] pg_dump 9.1.1 hanging (collectSecLabels gets 0 labels)

2011-11-10 Thread Tom Lane
Steve Singer ssin...@ca.afilias.info writes:
 The man page for malloc on AIX is pretty clear on what happens when you 
 try to malloc 0 bytes.  It returns NULL.

Yes, that's a pretty common behavior for malloc(0).  It should not cause
a problem here AFAICS.

... Oh, I see, the problem is that labels[-1] might not compare to
labels[0] the way we want.  I think only the first hunk of your
patch is actually necessary.

regards, tom lane

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


Re: [HACKERS] pg_dump 9.1.1 hanging (collectSecLabels gets 0 labels)

2011-11-10 Thread Steve Singer

On 11-11-10 02:00 PM, Tom Lane wrote:

Steve Singerssin...@ca.afilias.info  writes:

The man page for malloc on AIX is pretty clear on what happens when you
try to malloc 0 bytes.  It returns NULL.


Yes, that's a pretty common behavior for malloc(0).  It should not cause
a problem here AFAICS.

... Oh, I see, the problem is thatlabels[-1] might not compare to
labels[0] the way we want.  I think only the first hunk of your
patch is actually necessary.

regards, tom lane



Yes the problem is still fixed if I only apply the first hunk.



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


Re: [HACKERS] pg_dump 9.1.1 hanging (collectSecLabels gets 0 labels)

2011-11-10 Thread Tom Lane
Steve Singer ssin...@ca.afilias.info writes:
 On 11-11-10 02:00 PM, Tom Lane wrote:
 ... Oh, I see, the problem is thatlabels[-1] might not compare to
 labels[0] the way we want.  I think only the first hunk of your
 patch is actually necessary.

 Yes the problem is still fixed if I only apply the first hunk.

OK, everything seems satisfactorily explained then.  Will commit the
fix, thanks for the report!

regards, tom lane

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


[HACKERS] pg_dump 9.1.1 hanging (collectSecLabels gets 0 labels)

2011-11-09 Thread Steve Singer
We have a cluster running 9.1.1 where pg_dump hangs when we try to dump 
some a database inside of the cluster.  The server is running AIX.


I can see this on clean cluster where we do an initdb, followed by a 
createdb and try running pg_dump.


I've tracked the issue down to collectSecLabels in pg_dump.c

SELECT label, provider, classoid, objoid, objsbid FROM 
pg_catalog.pg_seclabel;


returns 0 rows.

The code in collectSecLabels() is not prepared to deal with a zero row 
result and tries to malloc 0 bytes.


I am not yet sure if the problem is that my pg_seclabel is empty or if 
the issue is in collectSecLabels() or if collectSecLabels shouldn't even 
be called.


Has anyone seen something similar?

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


Re: [HACKERS] pg_dump 9.1.1 hanging (collectSecLabels gets 0 labels)

2011-11-09 Thread Tom Lane
Steve Singer ssin...@ca.afilias.info writes:
 I've tracked the issue down to collectSecLabels in pg_dump.c

 SELECT label, provider, classoid, objoid, objsbid FROM 
 pg_catalog.pg_seclabel;

 returns 0 rows.

 The code in collectSecLabels() is not prepared to deal with a zero row 
 result and tries to malloc 0 bytes.

pg_seclabel is almost always empty, so I'm not convinced that you've
identified your problem correctly.

regards, tom lane

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