]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
sbuff->shifted should be reinitialised to 0 with each new sbuff in the chain
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 22 Jun 2022 20:15:08 +0000 (15:15 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 22 Jun 2022 20:15:08 +0000 (15:15 -0500)
This breaks the file streaming sbuff, so record the shifted count separately in the fr_sbuff_uctx_file_t structure

src/lib/util/sbuff.c
src/lib/util/sbuff.h
src/lib/util/sbuff_tests.c

index 2c0cdbc78840d109003848d5bfd328ca609e7681..d8288c75566a3bd4fda8cb24b886fe6953137ca2 100644 (file)
@@ -266,7 +266,7 @@ size_t fr_sbuff_extend_file(fr_sbuff_t *sbuff, size_t extension)
 
        if (extension == SIZE_MAX) extension = 0;
 
-       total_read = sbuff->shifted + (sbuff->end - sbuff->buff);
+       total_read = fctx->shifted + (sbuff->end - sbuff->buff);
        if (total_read >= fctx->max) {
                fr_strerror_const("Can't satisfy extension request, max bytes read");
                return 0;       /* There's no way we could satisfy the extension request */
@@ -279,7 +279,7 @@ size_t fr_sbuff_extend_file(fr_sbuff_t *sbuff, size_t extension)
                 *
                 *      Note: p and markers are constraints here.
                 */
-               fr_sbuff_shift(sbuff, fr_sbuff_used(sbuff));
+               fctx->shifted += fr_sbuff_shift(sbuff, fr_sbuff_used(sbuff));
        }
 
        available = fctx->buff_end - sbuff->end;
index ef7c5d401f5a0f549e16f1277034caa7b42a02f7..77c5bbc3faebe853de3155c04ea9e47a0e5d548a 100644 (file)
@@ -124,6 +124,7 @@ typedef struct {
        FILE                    *file;                  //!< FILE * we're reading from.
        char                    *buff_end;              //!< The true end of the buffer.
        size_t                  max;                    //!< Maximum number of bytes to read.
+       size_t                  shifted;                //!< How much we've read from this file.
        bool                    eof;                    //!< are we at EOF?
 } fr_sbuff_uctx_file_t;
 
@@ -406,7 +407,7 @@ do { \
        .p              = (_current), \
        .is_const       = fr_sbuff_ptr(_sbuff_or_marker)->is_const, \
        .adv_parent     = (_adv_parent), \
-       .shifted        = fr_sbuff_ptr(_sbuff_or_marker)->shifted, \
+       .shifted        = 0, \
        .extend         = (_extend), \
        .uctx           = fr_sbuff_ptr(_sbuff_or_marker)->uctx, \
        .parent         = fr_sbuff_ptr(_sbuff_or_marker) \
index abc75d8c194b85beace7e4635e4058b010a6b6ca..754bda62a1dc9b67783e5b0bf3d2573d2cde9916 100644 (file)
@@ -1042,8 +1042,8 @@ static void test_file_extend_max(void)
        TEST_CHECK(fr_sbuff_init_file(&sbuff, &fctx, buff, sizeof(buff), fp, sizeof(fbuff) - 8) == &sbuff);
 
        TEST_CASE("Confirm that max stops us from seeing xyzzy");
-       TEST_CHECK_LEN(sizeof(fbuff) - 8, fr_sbuff_adv_past_whitespace(&sbuff, SIZE_MAX, NULL));
-       (void) fr_sbuff_out_abstrncpy(NULL, &post_ws, &sbuff, 24);
+       TEST_CHECK_SLEN(fr_sbuff_adv_past_whitespace(&sbuff, SIZE_MAX, NULL), sizeof(fbuff) - 8);
+       TEST_CHECK_SLEN(fr_sbuff_out_abstrncpy(NULL, &post_ws, &sbuff, 24), 0);
        TEST_CHECK_STRCMP(post_ws, "");
        talloc_free(post_ws);
        fclose(fp);