Fix our base64 implementation for blobs of length 4....
authorVolker Lendecke <vl@samba.org>
Fri, 10 Jul 2009 15:29:22 +0000 (17:29 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 10 Jul 2009 16:16:46 +0000 (18:16 +0200)
The additional length check bit us exactly at 4, removing it. The
torture test survives valgrind up to 2000 bytes :-)

source3/lib/util_str.c
source3/script/tests/test_smbtorture_s3.sh
source3/torture/torture.c

index cdd7d0a300e118768653191e62ba3dff7cb3f1a9..0aff9439e901fbf1fff66252be04f10837da8354 100644 (file)
@@ -1932,7 +1932,7 @@ char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data)
        result = TALLOC_ARRAY(mem_ctx, char, output_len); /* get us plenty of space */
        SMB_ASSERT(result != NULL);
 
-       while (len-- && out_cnt < (data.length * 2) - 5) {
+       while (len--) {
                int c = (unsigned char) *(data.data++);
                bits += c;
                char_count++;
index c577ed18d4244756cd57ec029e33e44c99385de4..4301081cecc28c3561149dd9f46bc92c8970659e 100755 (executable)
@@ -29,6 +29,7 @@ tests="$tests DIR DIR1 TCON TCONDEV RW1 RW2 RW3"
 tests="$tests OPEN XCOPY RENAME DELETE PROPERTIES W2K"
 tests="$tests TCON2 IOCTL CHKPATH FDSESS LOCAL-SUBSTITUTE CHAIN1"
 tests="$tests GETADDRINFO POSIX UID-REGRESSION-TEST SHORTNAME-TEST"
+tests="$tests LOCAL-BASE64"
 
 skipped1="RANDOMIPC NEGNOWAIT NBENCH ERRMAPEXTRACT TRANS2SCAN NTTRANSSCAN"
 skipped2="DENY1 DENY2 OPENATTR CASETABLE EATEST"
index aa7e83bcc83c3387b18d8b2d797e287863bfe3ba..15083ef90d05f0da7ddd1b838a9f702ec904ff4b 100644 (file)
@@ -5749,6 +5749,39 @@ static bool run_local_substitute(int dummy)
        return ok;
 }
 
+static bool run_local_base64(int dummy)
+{
+       int i;
+       bool ret = true;
+
+       for (i=1; i<2000; i++) {
+               DATA_BLOB blob1, blob2;
+               char *b64;
+
+               blob1.data = talloc_array(talloc_tos(), uint8_t, i);
+               blob1.length = i;
+               generate_random_buffer(blob1.data, blob1.length);
+
+               b64 = base64_encode_data_blob(talloc_tos(), blob1);
+               if (b64 == NULL) {
+                       d_fprintf(stderr, "base64_encode_data_blob failed "
+                                 "for %d bytes\n", i);
+                       ret = false;
+               }
+               blob2 = base64_decode_data_blob(b64);
+               TALLOC_FREE(b64);
+
+               if (data_blob_cmp(&blob1, &blob2)) {
+                       d_fprintf(stderr, "data_blob_cmp failed for %d "
+                                 "bytes\n", i);
+                       ret = false;
+               }
+               TALLOC_FREE(blob1.data);
+               data_blob_free(&blob2);
+       }
+       return ret;
+}
+
 static bool run_local_gencache(int dummy)
 {
        char *val;
@@ -6487,6 +6520,7 @@ static struct {
        { "STREAMERROR", run_streamerror },
        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        { "LOCAL-GENCACHE", run_local_gencache, 0},
+       { "LOCAL-BASE64", run_local_base64, 0},
        { "LOCAL-RBTREE", run_local_rbtree, 0},
        { "LOCAL-MEMCACHE", run_local_memcache, 0},
        { "LOCAL-STREAM-NAME", run_local_stream_name, 0},