]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Have foreach allocate its own buffers
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 24 Jan 2018 00:36:55 +0000 (17:36 -0700)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 25 Jan 2018 19:12:21 +0000 (12:12 -0700)
src/main/xlat_func.c

index c3af94216655019204121dfa552bbe05f80bfbdc..becc7155807cba9d821552ae7c9a3be24ab50447 100644 (file)
@@ -427,12 +427,11 @@ static ssize_t xlat_regex(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
  *
  * @see modcall()
  */
-static ssize_t xlat_foreach(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
+static ssize_t xlat_foreach(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen,
                            void const *mod_inst, UNUSED void const *xlat_inst,
                            REQUEST *request, UNUSED char const *fmt)
 {
        VALUE_PAIR      **pvp;
-       size_t          len;
 
        /*
         *      See modcall, "FOREACH" for how this works.
@@ -440,13 +439,8 @@ static ssize_t xlat_foreach(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen,
        pvp = (VALUE_PAIR **) request_data_reference(request, (void *)radius_get_vp, *(int const *) mod_inst);
        if (!pvp || !*pvp) return 0;
 
-       len = fr_pair_value_snprint(*out, outlen, *pvp, 0);
-       if (is_truncated(len, outlen)) {
-               RDEBUG("Insufficient buffer space to write foreach value");
-               return -1;
-       }
-
-       return len;
+       *out = fr_pair_value_asprint(ctx, *pvp, '\0');
+       return  talloc_array_length(*out) - 1;
 }
 #endif
 
@@ -1113,7 +1107,7 @@ int xlat_init(void)
 
 #ifdef WITH_UNLANG
        for (i = 0; xlat_foreach_names[i] != NULL; i++) {
-               xlat_register(&xlat_foreach_inst[i], xlat_foreach_names[i], xlat_foreach, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN, true);
+               xlat_register(&xlat_foreach_inst[i], xlat_foreach_names[i], xlat_foreach, NULL, NULL, 0, 0, true);
                c = xlat_func_find(xlat_foreach_names[i]);
                rad_assert(c != NULL);
                c->internal = true;