You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2017/12/21 15:52:28 UTC

qpid-dispatch git commit: DISPATCH-885 - PR from gmurthy - Compose zero-length string/symbol/binary when a null pointer is provided. This closes #223

Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 44ee33fc8 -> 918c8f7c7


DISPATCH-885 - PR from gmurthy - Compose zero-length string/symbol/binary when a null pointer is provided.
This closes #223


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/918c8f7c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/918c8f7c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/918c8f7c

Branch: refs/heads/master
Commit: 918c8f7c7ba337e44aba96ebde60fd6e3d03c1c3
Parents: 44ee33f
Author: Ted Ross <tr...@redhat.com>
Authored: Thu Dec 21 10:49:58 2017 -0500
Committer: Ted Ross <tr...@redhat.com>
Committed: Thu Dec 21 10:49:58 2017 -0500

----------------------------------------------------------------------
 src/compose.c        |  9 ++++++--
 tests/compose_test.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/918c8f7c/src/compose.c
----------------------------------------------------------------------
diff --git a/src/compose.c b/src/compose.c
index 590927c..2162961 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -441,7 +441,10 @@ void qd_compose_insert_string_n(qd_composed_field_t *field, const char *value, s
 
 void qd_compose_insert_string(qd_composed_field_t *field, const char *value)
 {
-    qd_compose_insert_string_n(field, value, strlen(value));
+    if (value)
+        qd_compose_insert_string_n(field, value, strlen(value));
+    else
+        qd_compose_insert_string_n(field, value, 0);
 }
 
 
@@ -494,7 +497,9 @@ void qd_compose_insert_string_iterator(qd_composed_field_t *field, qd_iterator_t
 
 void qd_compose_insert_symbol(qd_composed_field_t *field, const char *value)
 {
-    uint32_t len = strlen(value);
+    uint32_t len = 0;
+    if (value)
+        len = strlen(value);
 
     if (len < 256) {
         qd_insert_8(field, QD_AMQP_SYM8);

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/918c8f7c/tests/compose_test.c
----------------------------------------------------------------------
diff --git a/tests/compose_test.c b/tests/compose_test.c
index 3986769..8e3fdd6 100644
--- a/tests/compose_test.c
+++ b/tests/compose_test.c
@@ -141,6 +141,60 @@ static char *vector1 =
 
 static int vector1_length = 69;
 
+static char *test_compose_insert_empty_string(void *context)
+{
+    char *empty_string = "\x00\x53\x75\xa1\x00";
+    qd_composed_field_t *field = qd_compose(QD_PERFORMATIVE_BODY_DATA, 0);
+    qd_compose_insert_string(field, 0);
+
+    qd_buffer_t *buf = DEQ_HEAD(field->buffers);
+
+    char *right = (char*) qd_buffer_base(buf);
+
+    for (int idx = 0; idx < qd_buffer_size(buf); idx++) {
+        if (empty_string[idx] != right[idx])
+            return "Pattern Mismatch";
+    }
+
+    return 0;
+}
+
+static char *test_compose_insert_empty_symbol(void *context)
+{
+    char *empty_string = "\x00\x53\x75\xa3\x00";
+    qd_composed_field_t *field = qd_compose(QD_PERFORMATIVE_BODY_DATA, 0);
+    qd_compose_insert_symbol(field, 0);
+
+    qd_buffer_t *buf = DEQ_HEAD(field->buffers);
+
+    char *right = (char*) qd_buffer_base(buf);
+
+    for (int idx = 0; idx < qd_buffer_size(buf); idx++) {
+        if (empty_string[idx] != right[idx])
+            return "Pattern Mismatch";
+    }
+
+    return 0;
+}
+
+static char *test_compose_insert_empty_binary(void *context)
+{
+    char *empty_string = "\x00\x53\x75\xa0\x00";
+    qd_composed_field_t *field = qd_compose(QD_PERFORMATIVE_BODY_DATA, 0);
+    qd_compose_insert_binary(field, 0, 0);
+
+    qd_buffer_t *buf = DEQ_HEAD(field->buffers);
+
+    char *right = (char*) qd_buffer_base(buf);
+
+    for (int idx = 0; idx < qd_buffer_size(buf); idx++) {
+        if (empty_string[idx] != right[idx])
+            return "Pattern Mismatch";
+    }
+
+    return 0;
+}
+
 static char *test_compose_nested_composites(void *context)
 {
     qd_composed_field_t *field = qd_compose(QD_PERFORMATIVE_DELIVERY_ANNOTATIONS, 0);
@@ -346,6 +400,9 @@ int compose_tests()
 
     TEST_CASE(test_compose_list_of_maps, 0);
     TEST_CASE(test_compose_nested_composites, 0);
+    TEST_CASE(test_compose_insert_empty_symbol, 0);
+    TEST_CASE(test_compose_insert_empty_string, 0);
+    TEST_CASE(test_compose_insert_empty_binary, 0);
     TEST_CASE(test_compose_scalars, 0);
     TEST_CASE(test_compose_subfields, 0);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org