]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix length passed to talloc_bstr_realloc()
authorAlan T. DeKok <aland@freeradius.org>
Mon, 27 Oct 2025 20:33:39 +0000 (16:33 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 28 Oct 2025 13:07:53 +0000 (09:07 -0400)
the meaning of the length parameter should not change depending
on the first parameter being NULL or not.

src/lib/server/cf_util.c
src/lib/util/talloc.c
src/modules/rlm_rest/rest.c

index 98903a16a6b4f5d5f8f8fd4952accb4e1e86c25b..3728f71db9a8a1e50acbe2a3d02f8d13cd3459b3 100644 (file)
@@ -1972,7 +1972,7 @@ int cf_pair_in_table(int32_t *out, fr_table_num_sorted_t const *table, size_t ta
        /*
         *      Trim the final ", "
         */
-       MEM(list = talloc_bstr_realloc(NULL, list, talloc_array_length(list) - 3));
+       MEM(list = talloc_bstr_realloc(NULL, list, talloc_array_length(list) - 2));
 
        cf_log_err(cp, "Invalid value \"%s\". Expected one of %s", cf_pair_value(cp), list);
 
index 7b7662e8009d6e6eea77ad90fe7eb8e8eb72a515..009b56165bd8ca509e56890b211805ecafd93db9 100644 (file)
@@ -652,7 +652,7 @@ char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen)
        char *n;
 
        if (!in) {
-               n = talloc_array(ctx, char, inlen);
+               n = talloc_array(ctx, char, inlen + 1);
                n[0] = '\0';
                return n;
        }
index f6249ff8e9e0850a533b8e74c873c794f2cdd136..688df386b4193c29f96c245e53e319441a4c72bf 100644 (file)
@@ -596,23 +596,23 @@ static ssize_t rest_request_encode_wrapper(char **out, UNUSED rlm_rest_t const *
                                           rest_read_t func, size_t limit, void *userdata)
 {
        char    *buff = NULL;
-       size_t  alloc = REST_BODY_ALLOC_CHUNK;  /* Size of buffer to alloc */
+       size_t  needed = REST_BODY_ALLOC_CHUNK; /* Size of buffer to alloc */
        size_t  used = 0;                       /* Size of data written */
        size_t  len = 0;
 
-       buff = talloc_array(NULL, char, alloc);
+       buff = talloc_array(NULL, char, needed);
        for (;;) {
-               len = func(buff + used, alloc - used, 1, userdata);
+               len = func(buff + used, needed - used, 1, userdata);
                used += len;
                if (!len) {
                        *out = buff;
                        return used;
                }
 
-               alloc = alloc * 2;
-               if (alloc > limit) break;
+               needed *= 2;
+               if (needed > limit) break;
 
-               MEM(buff = talloc_realloc(NULL, buff, char, alloc));
+               MEM(buff = talloc_realloc(NULL, buff, char, needed));
        }
 
        talloc_free(buff);