summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-07-10 17:29:22 +0200
committerVolker Lendecke <vl@samba.org>2009-07-10 18:16:46 +0200
commit0a0bff353e3cd8287166c7ed907a50a8599b0e03 (patch)
tree6a6fcbbf81d28e4796cf63f4a268633be8afc40c
parent67c7b7f90bd1bad265e892bb00abf649b22345b6 (diff)
downloadsamba-0a0bff353e3cd8287166c7ed907a50a8599b0e03.tar.gz
samba-0a0bff353e3cd8287166c7ed907a50a8599b0e03.tar.bz2
samba-0a0bff353e3cd8287166c7ed907a50a8599b0e03.zip
Fix our base64 implementation for blobs of length 4....
The additional length check bit us exactly at 4, removing it. The torture test survives valgrind up to 2000 bytes :-)
-rw-r--r--source3/lib/util_str.c2
-rwxr-xr-xsource3/script/tests/test_smbtorture_s3.sh1
-rw-r--r--source3/torture/torture.c34
3 files changed, 36 insertions, 1 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index cdd7d0a300..0aff9439e9 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -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++;
diff --git a/source3/script/tests/test_smbtorture_s3.sh b/source3/script/tests/test_smbtorture_s3.sh
index c577ed18d4..4301081cec 100755
--- a/source3/script/tests/test_smbtorture_s3.sh
+++ b/source3/script/tests/test_smbtorture_s3.sh
@@ -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"
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index aa7e83bcc8..15083ef90d 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -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},