Skip to content

Commit

Permalink
Merge pull request #1146 from jimklimov/issue_1023_fallout_hotfix
Browse files Browse the repository at this point in the history
Hotfix for drivers/hidparser.c losing the link with incorrect HID data
  • Loading branch information
jimklimov authored Oct 26, 2021
2 parents 38fc6a0 + b259129 commit 3d7d959
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit 3d7d959

Please sign in to comment.