[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Tue May 24 14:58:01 MDT 2011


The branch, master has been updated
       via  e719dfd Fix our asn.1 parser to handle negative numbers.
       via  ede98c0 lib/util Add Volker's asn1_Integer test into code that runs in 'make test'
      from  13d20fa Actually make use of the SMBTA_SUBRELEASE define in smb_traffic_analyzer.h. This will allow to introduce new features or fixes into the protocol after the 3.6.0 release. The client software is designed to take care for the subrelease number.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit e719dfd4dc178f001a5f804fb1ac4e587574415f
Author: Jeremy Allison <jra at samba.org>
Date:   Tue May 24 12:47:31 2011 -0700

    Fix our asn.1 parser to handle negative numbers.
    
    Autobuild-User: Jeremy Allison <jra at samba.org>
    Autobuild-Date: Tue May 24 22:57:16 CEST 2011 on sn-devel-104

commit ede98c0e5190bf59461703629d5a4742ad8e044f
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Sat May 14 19:49:36 2011 +0200

    lib/util Add Volker's asn1_Integer test into code that runs in 'make test'
    
    The comfychair test harness isn't hooked up, and with the current
    infrustructure C code is better tested directly here.
    
    Andrew Bartlett

-----------------------------------------------------------------------

Summary of changes:
 lib/util/asn1.c             |    9 ++++
 lib/util/tests/asn1_tests.c |   94 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+), 0 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/asn1.c b/lib/util/asn1.c
index b716da6..c23bf65 100644
--- a/lib/util/asn1.c
+++ b/lib/util/asn1.c
@@ -885,10 +885,19 @@ bool asn1_read_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *blo
 bool asn1_read_implicit_Integer(struct asn1_data *data, int *i)
 {
 	uint8_t b;
+	bool first_byte = true;
 	*i = 0;
 
 	while (!data->has_error && asn1_tag_remaining(data)>0) {
 		if (!asn1_read_uint8(data, &b)) return false;
+		if (first_byte) {
+			if (b & 0x80) {
+				/* Number is negative.
+				   Set i to -1 for sign extend. */
+				*i = -1;
+			}
+			first_byte = false;
+		}
 		*i = (*i << 8) + b;
 	}
 	return !data->has_error;	
diff --git a/lib/util/tests/asn1_tests.c b/lib/util/tests/asn1_tests.c
index ac8ca53..3ee64c3 100644
--- a/lib/util/tests/asn1_tests.c
+++ b/lib/util/tests/asn1_tests.c
@@ -4,6 +4,8 @@
    util_asn1 testing
 
    Copyright (C) Kamen Mazdrashki <kamen.mazdrashki at postpath.com> 2009
+   Copyright (C) Volker Lendecke 2004
+   Copyright (C) Andrew Bartlett 2011
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -103,6 +105,55 @@ static const struct oid_data partial_oid_data_ok[] = {
 	},
 };
 
+static const struct {
+	DATA_BLOB blob;
+	int value;
+} integer_tests[] = {
+        {
+		.blob = {"\x02\x01\x00", 3},
+		.value = 0
+	},
+	{
+		.blob = {"\x02\x01\x7f", 3},
+		.value = 127
+	},
+	{
+		.blob = {"\x02\x02\x00\x80", 4},
+		.value = 128
+	},
+	{
+		.blob = {"\x02\x02\x01\x00", 4},
+		.value = 256
+	},
+	{
+		.blob = {"\x02\x01\x80", 3},
+		.value = -128
+	},
+	{
+		.blob = {"\x02\x02\xff\x7f", 4},
+		.value = -129
+	},
+	{
+		.blob = {"\x02\x01\xff", 3},
+		.value = -1
+	},
+	{
+		.blob = {"\x02\x02\xff\x01", 4},
+		.value = -255
+	},
+	{
+		.blob = {"\x02\x02\x00\xff", 4},
+		.value = 255
+	},
+	{
+		.blob = {"\x02\x04\x80\x00\x00\x00", 6},
+		.value = 0x80000000
+	},
+	{
+		.blob = {"\x02\x04\x7f\xff\xff\xff", 6},
+		.value = 0x7fffffff
+	}
+};
 
 /* Testing ber_write_OID_String() function */
 static bool test_ber_write_OID_String(struct torture_context *tctx)
@@ -260,6 +311,46 @@ static bool test_ber_read_partial_OID_String(struct torture_context *tctx)
 	return true;
 }
 
+/*
+ * Testing asn1_read_Integer and asn1_write_Integer functions,
+ * inspired by Love Hornquist Astrand
+ */
+
+static bool test_asn1_Integer(struct torture_context *tctx)
+{
+	int i;
+	TALLOC_CTX *mem_ctx;
+
+	mem_ctx = talloc_new(tctx);
+
+	for (i = 0; i < ARRAY_SIZE(integer_tests); i++) {
+		ASN1_DATA *data;
+		DATA_BLOB blob;
+		int val;
+
+		data = asn1_init(mem_ctx);
+		if (!data) {
+			return -1;
+		}
+
+		asn1_write_Integer(data, integer_tests[i].value);
+
+		blob.data = data->data;
+		blob.length = data->length;
+		torture_assert_data_blob_equal(tctx, blob, integer_tests[i].blob, "asn1_write_Integer gave incorrect result");
+
+		asn1_load(data, blob);
+		torture_assert(tctx, asn1_read_Integer(data, &val), "asn1_write_Integer output could not be read by asn1_read_Integer()");
+
+		torture_assert_int_equal(tctx, val, integer_tests[i].value,
+			"readback of asn1_write_Integer output by asn1_read_Integer() failed");
+	}
+
+	talloc_free(mem_ctx);
+
+	return true;
+}
+
 
 /* LOCAL-ASN1 test suite creation */
 struct torture_suite *torture_local_util_asn1(TALLOC_CTX *mem_ctx)
@@ -278,5 +369,8 @@ struct torture_suite *torture_local_util_asn1(TALLOC_CTX *mem_ctx)
 	torture_suite_add_simple_test(suite, "ber_read_partial_OID_String",
 				      test_ber_read_partial_OID_String);
 
+	torture_suite_add_simple_test(suite, "asn1_Integer",
+				      test_asn1_Integer);
+
 	return suite;
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list