Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Garbage trailing bytes on device ID #3266

Closed

Description

@michaelrsweet

Version: 1.4rc1
CUPS.org User: twaugh.redhat

I was getting two garbage bytes on the end of Device IDs obtained from the usb backend. Here is the fix.

Activity

  1. michaelrsweet commented on Aug 7, 2009

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Fixed in Subversion repository.

  2. michaelrsweet commented on Aug 7, 2009

    @michaelrsweet
    ContributorAuthor

    "0001-Truncate-Device-ID-string-at-the-correct-point.patch":

    From 6bba4e202372910ed4868107a935737176d663d6 Mon Sep 17 00:00:00 2001
    From: Tim Waugh twaugh@redhat.com
    Date: Sat, 18 Jul 2009 16:11:57 +0100
    Subject: [PATCH] Truncate Device ID string at the correct point.

    The IEEE 1284 Device ID specification says that the initial MSB length

    field includes the 2 bytes of that field itself.

    backend/ieee1284.c | 13 ++++++++++---
    backend/usb-libusb.c | 8 +++++---
    2 files changed, 15 insertions(+), 6 deletions(-)

    diff --git a/backend/ieee1284.c b/backend/ieee1284.c
    index d3fd303..19555ba 100644
    --- a/backend/ieee1284.c
    +++ b/backend/ieee1284.c
    @@ -196,12 +196,19 @@ backendGetDeviceID(
    * and then limit the length to the size of our buffer...
    */

    •  if (length > (device_id_size - 2))
      
    •  if (length > device_id_size)
      

      length = (((unsigned)device_id[1] & 255) << 8) +
      ((unsigned)device_id[0] & 255);

    •  if (length > (device_id_size - 2))
      
    • length = device_id_size - 2;

    •  if (length > device_id_size)
      
    • length = device_id_size;

    • /*
      
    •  \* The length field counts the number of bytes in the string
      
    •  \* including the length field itself (2 bytes).
      
    •  */
      
    •  length -= 2;
      

      /*

      • Copy the device ID text to the beginning of the buffer and
        diff --git a/backend/usb-libusb.c b/backend/usb-libusb.c
        index 3cb61e3..d5c6ae5 100644
        --- a/backend/usb-libusb.c
        +++ b/backend/usb-libusb.c
        @@ -418,12 +418,14 @@ get_device_id(usb_printer_t printer, / I - Printer */
        • and then limit the length to the size of our buffer...
          */
    • if (length > (bufsize - 2))

    • if (length > bufsize)
      length = (((unsigned)buffer[1] & 255) << 8) +
      ((unsigned)buffer[0] & 255);

    • if (length > (bufsize - 2))

    • length = bufsize - 2;

    • if (length > bufsize)

    • length = bufsize;

    • length -= 2;

    /*

    * Copy the device ID text to the beginning of the buffer and

    1.6.2.5

  3. added this to the Stable milestone on Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions