]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
correctly split query string; cleanups
authorMark Andrews <marka@isc.org>
Thu, 27 Dec 2018 00:44:52 +0000 (11:44 +1100)
committerMark Andrews <marka@isc.org>
Wed, 9 Jan 2019 08:57:46 +0000 (19:57 +1100)
CHANGES
contrib/dlz/drivers/include/dlz/sdlz_helper.h
contrib/dlz/drivers/sdlz_helper.c

diff --git a/CHANGES b/CHANGES
index e8968f411d67ae3e47e7cb1d5e41f688b1b56a76..ca7da17efbf39b48ce78005f5c11ea2a8019bebf 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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
                        keys zones. [GL #784]
 
index 4d74e70d904b2472fe2e18c5bcc8be1a2eef1aa2..b6add3f1a0f211d17902cea2943b3faf9c47d839 100644 (file)
@@ -59,7 +59,7 @@ typedef struct driverinstance driverinstance_t;
 struct query_segment {
        void                            *sql;
        unsigned int                    strlen;
-       bool                    direct;
+       bool                            direct;
        ISC_LINK(query_segment_t)       link;
 };
 
index c44f72438293fdc00f9276d27048c0e8067c805d..e08cf89d779324596245bb6425ca081fe817185b 100644 (file)
@@ -106,11 +106,11 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
        bool foundzone = false;
        bool foundrecord = false;
        bool foundclient = false;
+       char *free_me = NULL;
        char *temp_str = NULL;
-       char *right_str = NULL;
        query_list_t *tql;
        query_segment_t *tseg = NULL;
-       char *last;
+       char *last = NULL;
 
        REQUIRE(querylist != NULL && *querylist == NULL);
        REQUIRE(mctx != NULL);
@@ -135,15 +135,24 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
        ISC_LIST_INIT(*tql);
 
        /* 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!! */
-       if (right_str == NULL) {
+       if (temp_str == NULL) {
                result = ISC_R_NOMEMORY;
                goto cleanup;
        }
 
        /* 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 */
                tseg = isc_mem_get(mctx, sizeof(query_segment_t));
                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 */
                ISC_LIST_APPEND(*tql, tseg, link);
 
-               /*
-                * split string at the first "$". set query segment to
-                * left portion
-                */
-               last = NULL;
-               tseg->sql = isc_mem_strdup(mctx,
-                                          strtok_r(right_str, "$", &last));
+               tseg->sql = isc_mem_strdup(mctx, sql);
                if (tseg->sql == NULL) {
                        /* no memory, clean everything up. */
                        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);
                        /* set tseg->sql to in-direct zone string */
-                       tseg->sql = (char**) zone;
+                       tseg->sql = zone;
                        tseg->strlen = 0;
                        /* tseg->sql points in-directly to a string */
                        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);
                        /* set tseg->sql to in-direct record string */
-                       tseg->sql = (char**) record;
+                       tseg->sql = record;
                        tseg->strlen = 0;
-                       /* tseg->sql points in-directly poinsts to a string */
+                       /* tseg->sql points in-directly points to a string */
                        tseg->direct = false;
                        foundrecord = true;
                        /* 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);
                        /* set tseg->sql to in-direct record string */
-                       tseg->sql = (char**) client;
+                       tseg->sql = client;
                        tseg->strlen = 0;
-                       /* tseg->sql points in-directly poinsts to a string */
+                       /* tseg->sql points in-directly points to a string */
                        tseg->direct = false;
                        foundclient = true;
                }
        }
 
        /* 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
         * necessary.
@@ -259,9 +262,9 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
        return (ISC_R_SUCCESS);
 
  cleanup:
-       /* get rid of temp_str */
-       if (temp_str != NULL)
-               isc_mem_free(mctx, temp_str);
+       /* get rid of free_me */
+       if (free_me != NULL)
+               isc_mem_free(mctx, free_me);
 
  flag_fail:
        /* get rid of what was build of the query list */