]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use nesting when creating SQL pairs
authorAlan T. DeKok <aland@freeradius.org>
Mon, 18 Sep 2023 12:32:24 +0000 (08:32 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 18 Sep 2023 12:32:24 +0000 (08:32 -0400)
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sql/sql.c

index 65a162e0a1bc32f6760ab3200480b14a91849edc..00035012f6bae9cc2487822f35829c51be2dfbad 100644 (file)
@@ -348,7 +348,7 @@ static int _sql_map_proc_get_value(TALLOC_CTX *ctx, fr_pair_list_t *out,
        fr_pair_t       *vp;
        char const      *value = uctx;
 
-       vp = fr_pair_afrom_da(ctx, tmpl_attr_tail_da(map->lhs));
+       vp = fr_pair_afrom_da_nested(ctx, out, tmpl_attr_tail_da(map->lhs));
        if (!vp) return -1;
 
        /*
@@ -357,14 +357,10 @@ static int _sql_map_proc_get_value(TALLOC_CTX *ctx, fr_pair_list_t *out,
         */
        if (fr_pair_value_from_str(vp, value, strlen(value), NULL, true) < 0) {
                RPEDEBUG("Failed parsing value \"%pV\" for attribute %s",
-                        fr_box_strvalue_buffer(value), tmpl_attr_tail_da(map->lhs)->name);
-               talloc_free(vp);
-
+                        fr_box_strvalue_buffer(value), vp->da->name);
                return -1;
        }
 
-       fr_pair_append(out, vp);
-
        return 0;
 }
 
index 9c1dafbdcef95c7ffd6aae97c30466382a028481..6fb30f9d87888c3f531d51a4bb1b4e169c075d12 100644 (file)
@@ -214,6 +214,9 @@ static int sql_pair_afrom_row(TALLOC_CTX *ctx, request_t *request, fr_pair_list_
 
                my_list = &(*relative_vp)->vp_group;
                my_ctx = *relative_vp;
+
+               MEM(vp = fr_pair_afrom_da(my_ctx, da));
+               fr_pair_append(my_list, vp);
        } else {
                /*
                 *      Search in our local dictionary
@@ -231,9 +234,10 @@ static int sql_pair_afrom_row(TALLOC_CTX *ctx, request_t *request, fr_pair_list_
 
                my_list = out;
                my_ctx = ctx;
+
+               MEM(vp = fr_pair_afrom_da_nested(my_ctx, my_list, da));
        }
 
-       MEM(vp = fr_pair_afrom_da(my_ctx, da));
        vp->op = op;
 
        if ((vp->vp_type == FR_TYPE_TLV) && !*value) {
@@ -248,17 +252,10 @@ static int sql_pair_afrom_row(TALLOC_CTX *ctx, request_t *request, fr_pair_list_
        } else {
                if (fr_pair_value_from_str(vp, value, strlen(value), NULL, true) < 0) {
                        RPEDEBUG("Error parsing value");
-
-                       talloc_free(vp);
                        return -1;
                }
        }
 
-       /*
-        *      Add the pair into the packet
-        */
-       fr_pair_append(my_list, vp);
-
        /*
         *      Update the relative vp.
         */