2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 23:25:38 +00:00

Merge branch '798-dlz-build_querystring-broken' into 'master'

Resolve "DLZ build_querystring broken"

Closes #798

See merge request isc-projects/bind9!1281
This commit is contained in:
Mark Andrews
2019-01-09 04:21:26 -05:00
3 changed files with 28 additions and 22 deletions

View File

@@ -1,3 +1,6 @@
5129. [contrib] sdlz_helper.c:build_querylist was not properly
splitting the query string. [GL #798]
5128. [bug] Refreshkeytime was not being updated for managed 5128. [bug] Refreshkeytime was not being updated for managed
keys zones. [GL #784] keys zones. [GL #784]

View File

@@ -59,7 +59,7 @@ typedef struct driverinstance driverinstance_t;
struct query_segment { struct query_segment {
void *sql; void *sql;
unsigned int strlen; unsigned int strlen;
bool direct; bool direct;
ISC_LINK(query_segment_t) link; ISC_LINK(query_segment_t) link;
}; };

View File

@@ -106,11 +106,11 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
bool foundzone = false; bool foundzone = false;
bool foundrecord = false; bool foundrecord = false;
bool foundclient = false; bool foundclient = false;
char *free_me = NULL;
char *temp_str = NULL; char *temp_str = NULL;
char *right_str = NULL;
query_list_t *tql; query_list_t *tql;
query_segment_t *tseg = NULL; query_segment_t *tseg = NULL;
char *last; char *last = NULL;
REQUIRE(querylist != NULL && *querylist == NULL); REQUIRE(querylist != NULL && *querylist == NULL);
REQUIRE(mctx != NULL); REQUIRE(mctx != NULL);
@@ -135,15 +135,24 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
ISC_LIST_INIT(*tql); ISC_LIST_INIT(*tql);
/* make a copy of query_str so we can chop it up */ /* make a copy of query_str so we can chop it up */
temp_str = right_str = isc_mem_strdup(mctx, query_str); free_me = temp_str = isc_mem_strdup(mctx, query_str);
/* couldn't make a copy, problem!! */ /* couldn't make a copy, problem!! */
if (right_str == NULL) { if (temp_str == NULL) {
result = ISC_R_NOMEMORY; result = ISC_R_NOMEMORY;
goto cleanup; goto cleanup;
} }
/* loop through the string and chop it up */ /* loop through the string and chop it up */
while (right_str != NULL) { for (;;) {
/*
* Split string into tokens at '$'.
*/
const char *sql = strtok_r(temp_str, "$", &last);
if (sql == NULL) {
break;
}
temp_str = NULL;
/* allocate memory for tseg */ /* allocate memory for tseg */
tseg = isc_mem_get(mctx, sizeof(query_segment_t)); tseg = isc_mem_get(mctx, sizeof(query_segment_t));
if (tseg == NULL) { /* no memory, clean everything up. */ if (tseg == NULL) { /* no memory, clean everything up. */
@@ -157,13 +166,7 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
/* append the query segment to the list */ /* append the query segment to the list */
ISC_LIST_APPEND(*tql, tseg, link); ISC_LIST_APPEND(*tql, tseg, link);
/* tseg->sql = isc_mem_strdup(mctx, sql);
* split string at the first "$". set query segment to
* left portion
*/
last = NULL;
tseg->sql = isc_mem_strdup(mctx,
strtok_r(right_str, "$", &last));
if (tseg->sql == NULL) { if (tseg->sql == NULL) {
/* no memory, clean everything up. */ /* no memory, clean everything up. */
result = ISC_R_NOMEMORY; result = ISC_R_NOMEMORY;
@@ -181,7 +184,7 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
*/ */
isc_mem_free(mctx, tseg->sql); isc_mem_free(mctx, tseg->sql);
/* set tseg->sql to in-direct zone string */ /* set tseg->sql to in-direct zone string */
tseg->sql = (char**) zone; tseg->sql = zone;
tseg->strlen = 0; tseg->strlen = 0;
/* tseg->sql points in-directly to a string */ /* tseg->sql points in-directly to a string */
tseg->direct = false; tseg->direct = false;
@@ -194,9 +197,9 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
*/ */
isc_mem_free(mctx, tseg->sql); isc_mem_free(mctx, tseg->sql);
/* set tseg->sql to in-direct record string */ /* set tseg->sql to in-direct record string */
tseg->sql = (char**) record; tseg->sql = record;
tseg->strlen = 0; tseg->strlen = 0;
/* tseg->sql points in-directly poinsts to a string */ /* tseg->sql points in-directly points to a string */
tseg->direct = false; tseg->direct = false;
foundrecord = true; foundrecord = true;
/* check if we encountered "$client$" token */ /* check if we encountered "$client$" token */
@@ -207,16 +210,16 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
*/ */
isc_mem_free(mctx, tseg->sql); isc_mem_free(mctx, tseg->sql);
/* set tseg->sql to in-direct record string */ /* set tseg->sql to in-direct record string */
tseg->sql = (char**) client; tseg->sql = client;
tseg->strlen = 0; tseg->strlen = 0;
/* tseg->sql points in-directly poinsts to a string */ /* tseg->sql points in-directly points to a string */
tseg->direct = false; tseg->direct = false;
foundclient = true; foundclient = true;
} }
} }
/* we don't need temp_str any more */ /* we don't need temp_str any more */
isc_mem_free(mctx, temp_str); isc_mem_free(mctx, free_me);
/* /*
* add checks later to verify zone and record are found if * add checks later to verify zone and record are found if
* necessary. * necessary.
@@ -259,9 +262,9 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
cleanup: cleanup:
/* get rid of temp_str */ /* get rid of free_me */
if (temp_str != NULL) if (free_me != NULL)
isc_mem_free(mctx, temp_str); isc_mem_free(mctx, free_me);
flag_fail: flag_fail:
/* get rid of what was build of the query list */ /* get rid of what was build of the query list */