]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fr_sbuff_out_bstrncpy_until(): call fr_sbuff_extend_lowat() with proper sbuff (#4873)
authorMax Khon <fjoe@samodelkin.net>
Fri, 31 Mar 2023 21:03:27 +0000 (04:03 +0700)
committerGitHub <noreply@github.com>
Fri, 31 Mar 2023 21:03:27 +0000 (15:03 -0600)
src/lib/util/sbuff.c
src/lib/util/sbuff_tests.c

index b2c23a20f6557b27944331e59f5312ecaa78e7c5..2770b3525f3145d00d5cf83bc8993f64d7359225 100644 (file)
@@ -846,7 +846,7 @@ size_t fr_sbuff_out_bstrncpy_until(fr_sbuff_t *out, fr_sbuff_t *in, size_t len,
                char    *p;
                char    *end;
 
-               if (fr_sbuff_extend_lowat(NULL, in, needle_len) == 0) break;
+               if (fr_sbuff_extend_lowat(NULL, &our_in, needle_len) == 0) break;
 
                p = fr_sbuff_current(&our_in);
                end = CONSTRAINED_END(&our_in, len, fr_sbuff_used_total(&our_in));
index 18878fa1545701088408bf76dcb010691dc4bc8a..b636ca1494b50637c8ef38b2e41c100be3fce015 100644 (file)
@@ -1052,7 +1052,7 @@ static void test_file_extend(void)
        fr_sbuff_uctx_file_t    fctx;
        FILE            *fp;
        char            buff[5];
-       char            out[16 + 1];
+       char            out[24];
        char            fbuff[24];
        const char      PATTERN[] = "xyzzy";
 #define PATTERN_LEN (sizeof(PATTERN) - 1)
@@ -1096,6 +1096,16 @@ static void test_file_extend(void)
        TEST_CHECK_SLEN(slen, 0);
 
        fclose(fp);
+
+       TEST_CASE("Verify fr_sbuff_out_bstrncpy_until() extends from file properly");
+       fp = fmemopen(fbuff, sizeof(fbuff), "r");
+       TEST_CHECK(fp != NULL);
+       TEST_CHECK(fr_sbuff_init_file(&sbuff, &fctx, buff, sizeof(buff), fp, 128) == &sbuff);
+       our_sbuff = FR_SBUFF_BIND_CURRENT(&sbuff);
+       slen = fr_sbuff_out_bstrncpy_until(&FR_SBUFF_OUT(out, sizeof(out)), &our_sbuff, SIZE_MAX, &FR_SBUFF_TERM("x"), NULL);
+       TEST_CHECK_SLEN(slen, sizeof(fbuff) - PATTERN_LEN);
+
+       fclose(fp);
 }
 
 static void test_file_extend_max(void)