Skip to content

Commit

Permalink
drivers/libshut.c: adjust data_size usage to usb_ctrl_charbufsize typ…
Browse files Browse the repository at this point in the history
…edef
  • Loading branch information
jimklimov committed Dec 25, 2021
1 parent 0d07991 commit 357dee6
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions drivers/libshut.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,14 +1184,31 @@ static int shut_control_msg(

/* Forge the SHUT Frame */
shut_pkt[0] = SHUT_TYPE_REQUEST + ( ((requesttype == REQUEST_TYPE_SET_REPORT) && (remaining_size>8))? 0 : SHUT_PKT_LAST);
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) )
# pragma GCC diagnostic push
#endif
#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS
# pragma GCC diagnostic ignored "-Wtype-limits"
#endif
#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE
# pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare"
#endif
#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE
# pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare"
#endif
if (data_size < 0 || data_size > UCHAR_MAX) {
upsdebugx(1, "%s: ERROR: data_size %i is out of range for SHUT packet",
__func__, data_size);
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) )
# pragma GCC diagnostic pop
#endif
upsdebugx(1, "%s: ERROR: data_size %" PRI_NUT_USB_CTRL_CHARBUFSIZE
" is out of range for SHUT packet",
__func__, data_size);
return -1;
}
if (data_size > 0x0F) {
upsdebugx(1, "%s: WARNING: data_size %i may be too large for SHUT packet?",
__func__, data_size);
upsdebugx(1, "%s: WARNING: data_size %" PRI_NUT_USB_CTRL_CHARBUFSIZE
" may be too large for SHUT packet?",
__func__, data_size);
// Do not abort here - maybe there is intentional maths
// in the protocol with overlapping/shifted-away numbers?
}
Expand Down

0 comments on commit 357dee6

Please sign in to comment.