Changeset 171cd88 in mainline


Ignore:
Timestamp:
2011-03-18T21:04:01Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
46d12fb
Parents:
f0a1c86
Message:

Make sure new_address index is never out of array bounds (fixes #142)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/utils/device_keeper.c

    rf0a1c86 r171cd88  
    179179        } else {
    180180                if (toggle) {
    181                         instance->devices[target.address].toggle_status |= (1 << target.endpoint);
     181                        instance->devices[target.address].toggle_status |=
     182                            (1 << target.endpoint);
    182183                } else {
    183                         instance->devices[target.address].toggle_status &= ~(1 << target.endpoint);
     184                        instance->devices[target.address].toggle_status &=
     185                            ~(1 << target.endpoint);
    184186                }
    185187                ret = EOK;
     
    201203        fibril_mutex_lock(&instance->guard);
    202204
    203         usb_address_t new_address = instance->last_address + 1;
    204         while (instance->devices[new_address].occupied) {
     205        usb_address_t new_address = instance->last_address;
     206        do {
     207                ++new_address;
     208                if (new_address > USB11_ADDRESS_MAX)
     209                        new_address = 1;
    205210                if (new_address == instance->last_address) {
    206211                        fibril_mutex_unlock(&instance->guard);
    207212                        return ENOSPC;
    208213                }
    209                 if (new_address == USB11_ADDRESS_MAX)
    210                         new_address = 1;
    211                 ++new_address;
    212         }
     214        } while (instance->devices[new_address].occupied);
    213215
    214216        assert(new_address != USB_ADDRESS_DEFAULT);
Note: See TracChangeset for help on using the changeset viewer.