DLZ PG segfaults
David Ford
david at blue-labs.org
Thu Nov 2 21:25:11 UTC 2006
David Ford wrote:
> Greetings,
> I set up DLZ yesterday w/ 9.4b2 and discovered that the DLZ code needed
> a bit of love. PQclear(x) doesn't set x to NULL and some functions were
> testing for NULL and working on an invalid pointer. So to be overly
> cautious rather than depend on obscure logic, I set x = NULL at every
> instance of PQclear() which solved the segfaults.
>
> Attached is a patch to accomplish this.
>
> David
>
>
>
>
> !DSPAM:1000,454a6144299291802529180!
>
>
Apparently the attachment got removed by the list. Here it is inline.
--- dlz_postgres_driver.c 2005-10-26 00:57:23.000000000 -0400
+++ /tmp/dlz_postgres_driver.c 2006-11-02 12:08:52.000000000 -0500
@@ -549,7 +549,10 @@
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d clearing rs", dlz_thread_num);
- PQclear(*rs); /* get rid of it */
+ if (*rs) {
+ PQclear(*rs); /* get rid of it */
+ *rs = NULL;
+ }
/* in case this was the last attempt */
result = ISC_R_FAILURE;
}
@@ -681,7 +684,10 @@
"Postgres driver unable to "
"allocate memory for "
"temporary string");
- PQclear(rs);
+ if (rs) {
+ PQclear(rs);
+ rs=NULL;
+ }
return (ISC_R_FAILURE); /* Yeah, I'd say! */
}
/* copy field to tmpString */
@@ -712,7 +718,10 @@
/* I sure hope we were successful */
if (result != ISC_R_SUCCESS) {
/* nope, get rid of the Result set, and log a msg */
- PQclear(rs);
+ if (rs) {
+ PQclear(rs);
+ rs=NULL;
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"dns_sdlz_putrr returned error. "
@@ -723,7 +732,10 @@
}
/* free result set memory */
- PQclear(rs);
+ if (rs) {
+ PQclear(rs);
+ rs=NULL;
+ }
/* if we did return results, we are successful */
if (rows > 0)
@@ -752,8 +764,10 @@
FINDZONE, dbdata, &rs);
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs) {
PQclear(rs);
+ rs=NULL;
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to return "
@@ -762,8 +776,12 @@
}
/* count how many rows in result set */
rows = PQntuples(rs);
+
/* get rid of result set, we are done with it. */
- PQclear(rs);
+ if (rs) {
+ PQclear(rs);
+ rs=NULL;
+ }
/* if we returned any rows, zone is supported. */
if (rows > 0)
@@ -803,8 +821,10 @@
return result;
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs) {
PQclear(rs);
+ rs=NULL;
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to return "
@@ -813,8 +833,12 @@
}
/* count how many rows in result set */
rows = PQntuples(rs);
+
/* get rid of result set, we are done with it. */
- PQclear(rs);
+ if (rs) {
+ PQclear(rs);
+ rs=NULL;
+ }
/* if we returned any rows, zone xfr is allowed. */
if (rows > 0)
@@ -854,8 +878,10 @@
return result;
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs) {
PQclear(rs);
+ rs=NULL;
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to return "
@@ -905,7 +931,8 @@
"Postgres driver unable to "
"allocate memory for "
"temporary string");
- PQclear(rs);
+ if (rs)
+ PQclear(rs);
return (ISC_R_FAILURE);
}
/* copy this field to tmpString */
@@ -924,7 +951,10 @@
}
/* if we weren't successful, log err msg */
if (result != ISC_R_SUCCESS) {
- PQclear(rs);
+ if (rs) {
+ PQclear(rs);
+ rs=NULL;
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"dns_sdlz_putnamedrr returned error. "
@@ -935,7 +965,10 @@
}
/* free result set memory */
- PQclear(rs);
+ if (rs) {
+ PQclear(rs);
+ rs=NULL;
+ }
/* if we did return results, we are successful */
if (rows > 0)
@@ -967,8 +1000,10 @@
return result;
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs) {
PQclear(rs);
+ rs=NULL;
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to return "
@@ -997,8 +1032,10 @@
result = postgres_get_resultset(zone, name, NULL, LOOKUP, dbdata, &rs);
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs) {
PQclear(rs);
+ rs=NULL;
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to "
More information about the bind-users
mailing list