]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add error strings for IPP read issues so that we can more easily dianose IPP
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 9 Sep 2011 18:29:36 +0000 (18:29 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 9 Sep 2011 18:29:36 +0000 (18:29 +0000)
encoding errors.

Add a check to ipptool for a missing end-of-attributes-tag.

Fix _cupsSetHTTPError(HTTP_ERROR).

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@9986 7a7537e8-13f0-0310-91df-b6672ffda945

cups/ipp.c
cups/request.c
test/ipptool.c

index 1a04caf95a21d31b1552ced1f4179927a0e43825..a597df30c013fbc15fe2784bc5be6be31e1e7d79 100644 (file)
@@ -1116,7 +1116,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
   if ((buffer = ipp_buffer_get()) == NULL)
   {
-    DEBUG_puts("1ippReadIO: Unable to get read buffer!");
+    DEBUG_puts("1ippReadIO: Unable to get read buffer.");
     return (IPP_ERROR);
   }
 
@@ -1134,7 +1134,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
           if ((*cb)(src, buffer, 8) < 8)
          {
-           DEBUG_puts("1ippReadIO: Unable to read header!");
+           DEBUG_puts("1ippReadIO: Unable to read header.");
            ipp_buffer_release(buffer);
            return (IPP_ERROR);
          }
@@ -1193,7 +1193,7 @@ ippReadIO(void       *src,                /* I - Data source */
            * No more attributes left...
            */
 
-            DEBUG_puts("2ippReadIO: IPP_TAG_END!");
+            DEBUG_puts("2ippReadIO: IPP_TAG_END.");
 
            ipp->state = IPP_DATA;
            break;
@@ -1225,7 +1225,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
           if ((*cb)(src, buffer, 2) < 2)
          {
-           DEBUG_puts("1ippReadIO: unable to read name length!");
+           DEBUG_puts("1ippReadIO: unable to read name length.");
            ipp_buffer_release(buffer);
            return (IPP_ERROR);
          }
@@ -1234,7 +1234,8 @@ ippReadIO(void       *src,                /* I - Data source */
 
           if (n >= IPP_BUF_SIZE)
          {
-           DEBUG_printf(("1ippReadIO: bad name length %d!", n));
+           _cupsSetError(IPP_ERROR, _("IPP name larger than 32767 bytes."), 1);
+           DEBUG_printf(("1ippReadIO: bad name length %d.", n));
            ipp_buffer_release(buffer);
            return (IPP_ERROR);
          }
@@ -1250,7 +1251,8 @@ ippReadIO(void       *src,                /* I - Data source */
 
             if (ipp->current == NULL)
            {
-             DEBUG_puts("1ippReadIO: Attribute without name and no current");
+             _cupsSetError(IPP_ERROR, _("IPP attribute has no name."), 1);
+             DEBUG_puts("1ippReadIO: Attribute without name and no current.");
              ipp_buffer_release(buffer);
              return (IPP_ERROR);
            }
@@ -1285,6 +1287,9 @@ ippReadIO(void       *src,                /* I - Data source */
                  (tag < IPP_TAG_TEXT || tag > IPP_TAG_MIMETYPE) &&
                  tag != IPP_TAG_NOVALUE)
              {
+               _cupsSetError(IPP_ERROR,
+                             _("IPP 1setOf attribute with incompatible value "
+                               "tags."), 1);
                DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
                              value_tag, ippTagString(value_tag), tag,
                              ippTagString(tag)));
@@ -1294,6 +1299,9 @@ ippReadIO(void       *src,                /* I - Data source */
             }
            else if (value_tag != tag)
            {
+             _cupsSetError(IPP_ERROR,
+                           _("IPP 1setOf attribute with incompatible value "
+                             "tags."), 1);
              DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
                            value_tag, ippTagString(value_tag), tag,
                            ippTagString(tag)));
@@ -1311,7 +1319,6 @@ ippReadIO(void       *src,                /* I - Data source */
            {
              ipp_attribute_t   *temp;  /* Pointer to new buffer */
 
-
               DEBUG_printf(("2ippReadIO: reallocating for up to %d values...",
                            attr->num_values + IPP_MAX_VALUES));
 
@@ -1323,6 +1330,7 @@ ippReadIO(void       *src,                /* I - Data source */
                                        (attr->num_values + IPP_MAX_VALUES - 1) *
                                        sizeof(ipp_value_t))) == NULL)
              {
+               _cupsSetHTTPError(HTTP_ERROR);
                DEBUG_puts("1ippReadIO: Unable to resize attribute");
                ipp_buffer_release(buffer);
                return (IPP_ERROR);
@@ -1351,7 +1359,8 @@ ippReadIO(void       *src,                /* I - Data source */
 
            if (n)
            {
-             DEBUG_puts("1ippReadIO: member name not empty!");
+             _cupsSetError(IPP_ERROR, _("IPP member name is not empty."), 1);
+             DEBUG_puts("1ippReadIO: member name not empty.");
              ipp_buffer_release(buffer);
              return (IPP_ERROR);
            }
@@ -1376,7 +1385,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
            if ((*cb)(src, buffer, n) < n)
            {
-             DEBUG_puts("1ippReadIO: unable to read name!");
+             DEBUG_puts("1ippReadIO: unable to read name.");
              ipp_buffer_release(buffer);
              return (IPP_ERROR);
            }
@@ -1388,7 +1397,8 @@ ippReadIO(void       *src,                /* I - Data source */
 
            if ((attr = ipp->current = _ippAddAttr(ipp, 1)) == NULL)
            {
-             DEBUG_puts("1ippReadIO: unable to allocate attribute!");
+             _cupsSetHTTPError(HTTP_ERROR);
+             DEBUG_puts("1ippReadIO: unable to allocate attribute.");
              ipp_buffer_release(buffer);
              return (IPP_ERROR);
            }
@@ -1411,7 +1421,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
          if ((*cb)(src, buffer, 2) < 2)
          {
-           DEBUG_puts("1ippReadIO: unable to read value length!");
+           DEBUG_puts("1ippReadIO: unable to read value length.");
            ipp_buffer_release(buffer);
            return (IPP_ERROR);
          }
@@ -1419,20 +1429,35 @@ ippReadIO(void       *src,              /* I - Data source */
          n = (buffer[0] << 8) | buffer[1];
           DEBUG_printf(("2ippReadIO: value length=%d", n));
 
+         if (n >= IPP_BUF_SIZE)
+         {
+           _cupsSetError(IPP_ERROR,
+                         _("IPP value larger than 32767 bytes."), 1);
+           DEBUG_printf(("1ippReadIO: bad value length %d.", n));
+           ipp_buffer_release(buffer);
+           return (IPP_ERROR);
+         }
+
          switch (tag)
          {
            case IPP_TAG_INTEGER :
            case IPP_TAG_ENUM :
                if (n != 4)
                {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
+                 if (tag == IPP_TAG_INTEGER)
+                   _cupsSetError(IPP_ERROR,
+                                 _("IPP integer value not 4 bytes."), 1);
+                 else
+                   _cupsSetError(IPP_ERROR,
+                                 _("IPP enum value not 4 bytes."), 1);
+                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
 
                if ((*cb)(src, buffer, 4) < 4)
                {
-                 DEBUG_puts("1ippReadIO: Unable to read integer value!");
+                 DEBUG_puts("1ippReadIO: Unable to read integer value.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1446,14 +1471,16 @@ ippReadIO(void       *src,              /* I - Data source */
            case IPP_TAG_BOOLEAN :
                if (n != 1)
                {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
+                 _cupsSetError(IPP_ERROR, _("IPP boolean value not 1 byte."),
+                               1);
+                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
 
                if ((*cb)(src, buffer, 1) < 1)
                {
-                 DEBUG_puts("1ippReadIO: Unable to read boolean value!");
+                 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1487,16 +1514,9 @@ ippReadIO(void       *src,               /* I - Data source */
            case IPP_TAG_CHARSET :
            case IPP_TAG_LANGUAGE :
            case IPP_TAG_MIMETYPE :
-               if (n >= IPP_BUF_SIZE)
-               {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
-                 ipp_buffer_release(buffer);
-                 return (IPP_ERROR);
-               }
-
                if ((*cb)(src, buffer, n) < n)
                {
-                 DEBUG_puts("1ippReadIO: unable to read name!");
+                 DEBUG_puts("1ippReadIO: unable to read string value.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1509,14 +1529,16 @@ ippReadIO(void       *src,              /* I - Data source */
            case IPP_TAG_DATE :
                if (n != 11)
                {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
+                 _cupsSetError(IPP_ERROR, _("IPP date value not 11 bytes."),
+                               1);
+                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
 
                if ((*cb)(src, value->date, 11) < 11)
                {
-                 DEBUG_puts("1ippReadIO: Unable to read date value!");
+                 DEBUG_puts("1ippReadIO: Unable to read date value.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1525,14 +1547,16 @@ ippReadIO(void       *src,              /* I - Data source */
            case IPP_TAG_RESOLUTION :
                if (n != 9)
                {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
+                 _cupsSetError(IPP_ERROR,
+                               _("IPP resolution value not 9 bytes."), 1);
+                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
 
                if ((*cb)(src, buffer, 9) < 9)
                {
-                 DEBUG_puts("1ippReadIO: Unable to read resolution value!");
+                 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1550,14 +1574,16 @@ ippReadIO(void       *src,              /* I - Data source */
            case IPP_TAG_RANGE :
                if (n != 8)
                {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
+                 _cupsSetError(IPP_ERROR,
+                               _("IPP rangeOfInteger value not 8 bytes."), 1);
+                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
 
                if ((*cb)(src, buffer, 8) < 8)
                {
-                 DEBUG_puts("1ippReadIO: Unable to read range value!");
+                 DEBUG_puts("1ippReadIO: Unable to read range value.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1572,9 +1598,17 @@ ippReadIO(void       *src,               /* I - Data source */
 
            case IPP_TAG_TEXTLANG :
            case IPP_TAG_NAMELANG :
-               if (n >= IPP_BUF_SIZE || n < 4)
+               if (n < 4)
                {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
+                 if (tag == IPP_TAG_TEXTLANG)
+                   _cupsSetError(IPP_ERROR,
+                                 _("IPP textWithLanguage value less than "
+                                   "minimum 4 bytes."), 1);
+                 else
+                   _cupsSetError(IPP_ERROR,
+                                 _("IPP nameWithLanguage value less than "
+                                   "minimum 4 bytes."), 1);
+                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1582,7 +1616,7 @@ ippReadIO(void       *src,                /* I - Data source */
                if ((*cb)(src, buffer, n) < n)
                {
                  DEBUG_puts("1ippReadIO: Unable to read string w/language "
-                            "value!");
+                            "value.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1593,10 +1627,13 @@ ippReadIO(void       *src,              /* I - Data source */
                * text-with-language and name-with-language are composite
                * values:
                *
-               *    charset-length
-               *    charset
+               *    language-length
+               *    language
                *    text-length
                *    text
+               *
+               * The "charset" field name is an unfortunate typo from
+               * CUPS 1.0...
                */
 
                n = (bufptr[0] << 8) | bufptr[1];
@@ -1604,7 +1641,9 @@ ippReadIO(void       *src,                /* I - Data source */
                if ((bufptr + 2 + n) >= (buffer + IPP_BUF_SIZE) ||
                    n >= sizeof(string))
                {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
+                 _cupsSetError(IPP_ERROR,
+                               _("IPP language length overflows value."), 1);
+                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1619,7 +1658,9 @@ ippReadIO(void       *src,                /* I - Data source */
 
                if ((bufptr + 2 + n) >= (buffer + IPP_BUF_SIZE))
                {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
+                 _cupsSetError(IPP_ERROR,
+                               _("IPP string length overflows value."), 1);
+                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1637,15 +1678,17 @@ ippReadIO(void       *src,              /* I - Data source */
 
                 if (n > 0)
                {
+                 _cupsSetError(IPP_ERROR,
+                               _("IPP begCollection value not 0 bytes."), 1);
                  DEBUG_puts("1ippReadIO: begCollection tag with value length "
-                            "> 0!");
+                            "> 0.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
 
                if (ippReadIO(src, cb, 1, ipp, value->collection) == IPP_ERROR)
                {
-                 DEBUG_puts("1ippReadIO: Unable to read collection value!");
+                 DEBUG_puts("1ippReadIO: Unable to read collection value.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1656,8 +1699,10 @@ ippReadIO(void       *src,               /* I - Data source */
 
                 if (n > 0)
                {
+                 _cupsSetError(IPP_ERROR,
+                               _("IPP endCollection value not 0 bytes."), 1);
                  DEBUG_puts("1ippReadIO: endCollection tag with value length "
-                            "> 0!");
+                            "> 0.");
                  return (IPP_ERROR);
                }
 
@@ -1670,16 +1715,9 @@ ippReadIO(void       *src,               /* I - Data source */
                * we need to carry over...
                */
 
-               if (n >= IPP_BUF_SIZE)
-               {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
-                 ipp_buffer_release(buffer);
-                 return (IPP_ERROR);
-               }
-
                if ((*cb)(src, buffer, n) < n)
                {
-                 DEBUG_puts("1ippReadIO: Unable to read member name value!");
+                 DEBUG_puts("1ippReadIO: Unable to read member name value.");
                  ipp_buffer_release(buffer);
                  return (IPP_ERROR);
                }
@@ -1699,25 +1737,12 @@ ippReadIO(void       *src,              /* I - Data source */
                break;
 
             default : /* Other unsupported values */
-               if (n > IPP_MAX_LENGTH)
-               {
-                 DEBUG_printf(("1ippReadIO: bad value length %d!", n));
-                 ipp_buffer_release(buffer);
-                 return (IPP_ERROR);
-               }
-
-               if (!value)
-               {
-                 DEBUG_puts("1ippReadIO: NULL value!");
-                 ipp_buffer_release(buffer);
-                 return (IPP_ERROR);
-               }
-
                 value->unknown.length = n;
                if (n > 0)
                {
                  if ((value->unknown.data = malloc(n)) == NULL)
                  {
+                   _cupsSetHTTPError(HTTP_ERROR);
                    DEBUG_puts("1ippReadIO: Unable to allocate value");
                    ipp_buffer_release(buffer);
                    return (IPP_ERROR);
@@ -1725,7 +1750,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
                  if ((*cb)(src, value->unknown.data, n) < n)
                  {
-                   DEBUG_puts("1ippReadIO: Unable to read unsupported value!");
+                   DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
                    ipp_buffer_release(buffer);
                    return (IPP_ERROR);
                  }
@@ -1753,7 +1778,7 @@ ippReadIO(void       *src,                /* I - Data source */
         break; /* anti-compiler-warning-code */
   }
 
-  DEBUG_printf(("1ippReadIO: returning ipp->state=%d!", ipp->state));
+  DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp->state));
   ipp_buffer_release(buffer);
 
   return (ipp->state);
index 0f50afcb65082369600b64f9d140e4f31a35dff0..881c0d2f2e01c68902049f2248f0063fb90b6d08 100644 (file)
@@ -1105,7 +1105,7 @@ _cupsSetHTTPError(http_status_t status)   /* I - HTTP status code */
         break;
 
     case HTTP_ERROR :
-       _cupsSetError(IPP_INTERNAL_ERROR, httpStatus(status), 0);
+       _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno), 0);
         break;
 
     default :
index 70b91e2cc1b3d0d570bf6bf9ed4bec9879a9b0e9..e0e953aad1d0ecadc502bfa1ca9561080bea7132 100644 (file)
@@ -2115,6 +2115,9 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       if (http->version != HTTP_1_1)
         prev_pass = pass = 0;
 
+      if (response->state != IPP_DATA)
+        prev_pass = pass = 0;
+
       if (response->request.status.request_id != request_id)
         prev_pass = pass = 0;
 
@@ -2411,6 +2414,10 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
                         cupsLastErrorString());
       else
       {
+       if (response->state != IPP_DATA)
+         print_test_error("Missing end-of-attributes-tag in response "
+                          "(RFC 2910 section 3.5.1)");
+
        if (version &&
            (response->request.status.version[0] != (version / 10) ||
             response->request.status.version[1] != (version % 10)))