alpine 3.8
obsolete weakness #34

1

Weakness Breakdown


Definition:

An obsolete weakness occurs when someone uses deprecated or obsolete functions when building a system. As a programming language evolves, some functions occasionally become obsolete.

Warning code(s):

This C routine is considered obsolete.

File Name:

gammu/src/gammu-1.39.0/libgammu/device/usb/usb.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.8 obsolete weakness.

 
ssize_t GSM_USB_Read(GSM_StateMachine *s, void *buf, size_t nbytes)
{
	GSM_Device_USBData *d = &s->Device.Data.USB;
	int rc = LIBUSB_ERROR_TIMEOUT, ret = 0, repeat = 0;

	while (repeat < 10 && (rc == LIBUSB_ERROR_TIMEOUT || rc == LIBUSB_ERROR_INTERRUPTED || rc == LIBUSB_ERROR_OTHER || rc == LIBUSB_ERROR_NO_MEM)) {
		rc = libusb_bulk_transfer(d->handle, d->ep_read, buf, nbytes, &ret, 1000);
		/* This seems to be some strange failure on partial data transfer */
		if (rc == LIBUSB_ERROR_OTHER && ret != 0) {
			smprintf(s, "Other error while reading, but got some data\n");
			rc = 0;
			break;
		}
		if (rc == LIBUSB_ERROR_TIMEOUT && ret != 0) {
			smprintf(s, "Timeout while reading, but got some data\n");
			rc = 0;
			break;
		}
		if (rc != 0) {
			smprintf(s, "Failed to read from usb (%d)!\n", rc);
			GSM_USB_Error(s, rc);
		}
		repeat++;
		usleep(1000);
	}
	if (rc != 0) {
		return -1;
	}
	return ret;
}

ssize_t GSM_USB_Write(GSM_StateMachine *s, const void *buf, size_t nbytes)
{
	GSM_Device_USBData *d = &s->Device.Data.USB;
	int rc = LIBUSB_ERROR_TIMEOUT, ret = 0, repeat = 0;

	while (repeat < 10 && (rc == LIBUSB_ERROR_TIMEOUT || rc == LIBUSB_ERROR_INTERRUPTED || rc == LIBUSB_ERROR_OTHER || rc == LIBUSB_ERROR_NO_MEM)) {
		rc = libusb_bulk_transfer(d->handle, d->ep_write, (void *)buf, nbytes, &ret, 1000);
		/* This seems to be some strange failure on partial data transfer */
		if (rc == LIBUSB_ERROR_OTHER && ret != 0) {
			smprintf(s, "Other error while writing, but got some data\n");
			rc = 0;
			break;
		}
		if (rc == LIBUSB_ERROR_TIMEOUT && ret != 0) {
			smprintf(s, "Timeout while write, but some data were written\n");
			rc = 0;
			break;
		} 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.