Uploaded image for project: 'Qpid Proton'
  1. Qpid Proton
  2. PROTON-2249

[c] AMQP char type does not handle null chars correctly from pn_inspect()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • proton-c
    • None

    Description

      The pn_inspect() method returns a string representation of the inspected AMQP type.

      While testing an array of type char in which the first char had value 0x0, it was observed that this method is not correctly printing the array, but is being truncated:

      "@PN_CHAR["
      

      and prevents effective checking of the array contents in the test.

      The formatting of simple AMQP types is set in the pni_inspect_atom() method. The use of the %c formatting code to print the char is causing null chars to terminate the string which is being treated as a c-string. The following suggested change fixes this issue and prefixes each char with 'U' to indicate it is UTF-32:

      diff --git a/c/src/core/codec.c b/c/src/core/codec.c
      index b50f286b..1f9185f7 100644
      --- a/c/src/core/codec.c
      +++ b/c/src/core/codec.c
      @@ -129,7 +129,8 @@ int pni_inspect_atom(pn_atom_t *atom, pn_string_t *str)
        case PN_INT:
          return pn_string_addf(str, "%" PRIi32, atom->u.as_int);
        case PN_CHAR:
      -   return pn_string_addf(str, "%c", atom->u.as_char);
      +   if (isprint(atom->u.as_char)) return pn_string_addf(str, "U'%c'", atom->u.as_char);
      +   return pn_string_addf(str, "U'\\x%" PRIx32 "'", atom->u.as_char);
        case PN_ULONG:
          return pn_string_addf(str, "%" PRIu64, atom->u.as_ulong);
        case PN_LONG:
      

      and the array prints as:

      "@PN_CHAR[U'\x0', U'5', U'a', U'Z', U'\x7f']"
      

      The following are improved:

      Thoughts?

      Attachments

        Activity

          People

            Unassigned Unassigned
            kpvdr Kim van der Riet
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: