Changeset 831aa466 in mainline


Ignore:
Timestamp:
2018-06-26T23:16:12Z (6 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2fc9bfd
Parents:
70fae4e
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-06-26 23:06:11)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-06-26 23:16:12)
Message:

Fix cases of undefined behavior found by ubsan.

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/endpoint.c

    r70fae4e r831aa466  
    102102        if (dev->speed >= USB_SPEED_HIGH ||
    103103            ep->transfer_type != USB_TRANSFER_INTERRUPT) {
    104                 xhci_ep->interval = 1 << (xhci_ep->interval - 1);
     104
     105                if (xhci_ep->interval > 0)
     106                        xhci_ep->interval = 1 << (xhci_ep->interval - 1);
    105107        }
    106108
  • uspace/lib/c/generic/ubsan.c

    r70fae4e r831aa466  
    9898#endif
    9999void __ubsan_handle_nonnull_return(struct nonnull_return_data *data);
     100void __ubsan_handle_builtin_unreachable(struct unreachable_data *data);
    100101
    101102static void print_loc(const char *func, struct source_location *loc)
     
    107108                f += sizeof(func_prefix);
    108109
    109         PRINTF("Undefined behavior %s at %s:%" PRIu32 " col %" PRIu32 "\n",
     110        PRINTF("####### Undefined behavior %s at %s:%" PRIu32 " col %" PRIu32 "\n",
    110111            f, loc->file_name, loc->line, loc->column);
    111112}
     
    115116{
    116117        print_loc(__func__, &data->loc);
     118        PRINTF("Type: %s, alignment: %lu, type_check_kind: %hhu\n",
     119            data->type->type_name, data->alignment, data->type_check_kind);
    117120        ubsan_panic();
    118121}
     
    219222        ubsan_panic();
    220223}
     224
     225void __ubsan_handle_builtin_unreachable(struct unreachable_data *data)
     226{
     227        print_loc(__func__, &data->loc);
     228        ubsan_panic();
     229}
     230
  • uspace/lib/drv/generic/remote_usb.c

    r70fae4e r831aa466  
    7777                return EBADMEM;
    7878
    79         usb_device_desc_t tmp_desc;
     79        sysarg_t address, depth, speed, handle, iface;
    8080
    8181        const errno_t ret = async_req_1_5(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    82             IPC_M_USB_GET_MY_DESCRIPTION,
    83             (sysarg_t *) &tmp_desc.address,
    84             (sysarg_t *) &tmp_desc.depth,
    85             (sysarg_t *) &tmp_desc.speed,
    86             &tmp_desc.handle,
    87             (sysarg_t *) &tmp_desc.iface);
    88         if (ret == EOK && desc)
    89                 *desc = tmp_desc;
     82            IPC_M_USB_GET_MY_DESCRIPTION, &address, &depth, &speed, &handle,
     83            &iface);
     84        if (ret == EOK && desc) {
     85                *desc = (usb_device_desc_t) {
     86                        .address = address,
     87                        .depth = depth,
     88                        .speed = speed,
     89                        .handle = handle,
     90                        .iface = iface,
     91                };
     92        }
     93
    9094        return ret;
    9195}
  • uspace/lib/usb/include/usb/request.h

    r70fae4e r831aa466  
    7575#define USB_SETUP_PACKET_SIZE 8
    7676
    77 /** Device request setup packet.
    78  * The setup packet describes the request.
    79  */
    80 typedef struct {
    81         /** Request type.
    82          * The type combines transfer direction, request type and
    83          * intended recipient.
    84          */
    85         uint8_t request_type;
    8677#define SETUP_REQUEST_TYPE_DEVICE_TO_HOST (1 << 7)
    8778#define SETUP_REQUEST_TYPE_HOST_TO_DEVICE (0 << 7)
     
    9485    (uint8_t)(((type & 0x3) << 5) | (recipient & 0x1f))
    9586
    96         /** Request identification. */
    97         uint8_t request;
    98         /** Main parameter to the request. */
    99         union __attribute__((packed)) {
    100                 uint16_t value;
    101                 /* FIXME: add #ifdefs according to host endianness */
    102                 struct __attribute__((packed)) {
    103                         uint8_t value_low;
    104                         uint8_t value_high;
     87/** Device request setup packet.
     88 * The setup packet describes the request.
     89 */
     90typedef union {
     91        struct __attribute__((packed)) {
     92                /** Request type.
     93                 * The type combines transfer direction, request type and
     94                 * intended recipient.
     95                 */
     96                uint8_t request_type;
     97
     98                /** Request identification. */
     99                uint8_t request;
     100                /** Main parameter to the request. */
     101                union __attribute__((packed)) {
     102                        uint16_t value;
     103                        /* FIXME: add #ifdefs according to host endianness */
     104                        struct __attribute__((packed)) {
     105                                uint8_t value_low;
     106                                uint8_t value_high;
     107                        };
    105108                };
     109                /** Auxiliary parameter to the request.
     110                 * Typically, it is offset to something.
     111                 */
     112                uint16_t index;
     113                /** Length of extra data. */
     114                uint16_t length;
    106115        };
    107         /** Auxiliary parameter to the request.
    108          * Typically, it is offset to something.
    109          */
    110         uint16_t index;
    111         /** Length of extra data. */
    112         uint16_t length;
     116        uint64_t raw;
    113117} __attribute__((packed)) usb_device_request_setup_packet_t;
    114118
  • uspace/lib/usbhost/src/usb2_bus.c

    r70fae4e r831aa466  
    142142        usb_log_debug("Device(%d): Setting USB address.", address);
    143143        err = bus_device_send_batch_sync(dev, usb2_default_target, USB_DIRECTION_OUT,
    144             NULL, 0, *(uint64_t *)&set_address, "set address", NULL);
     144            NULL, 0, set_address.raw, "set address", NULL);
    145145        if (err) {
    146146                usb_log_error("Device(%d): Failed to set new address: %s.",
Note: See TracChangeset for help on using the changeset viewer.