Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix for drivers/hidparser.c losing the link with incorrect HID data #1146

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion drivers/hidparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void GetValue(const unsigned char *Buf, HIDData_t *pData, long *pValue)

int Weight, Bit;
unsigned long mask, signbit, magMax, magMin;
long value = 0;
long value = 0, range;

Bit = pData->Offset + 8; /* First byte of report is report ID */

Expand All @@ -446,6 +446,17 @@ void GetValue(const unsigned char *Buf, HIDData_t *pData, long *pValue)
}
}

range = pData->LogMax - pData->LogMin + 1;
if (range <= 0) {
/* makes no sense, give up */
*pValue = value;
/* Discussion: https://github.com/networkupstools/nut/pull/1138 */
upslogx(LOG_ERR, "ERROR in %s: LogMin is greater than LogMax, "
"possibly vendor HID is incorrect on device side; "
"skipping evaluation of these constraints", __func__);
return;
}

/* translate Value into a signed/unsigned value in the range
LogMin..LogMax, as appropriate. See HID spec, p.38: "If both the
Logical Minimum and Logical Maximum extents are defined as
Expand Down