Skip to content

Commit

Permalink
host: str2uint sample count overflow fix
Browse files Browse the repository at this point in the history
Result of val*mult would be casted to unsigned int before min/max
boundary check allowing for overflows to occur.

Fixes #941
  • Loading branch information
rthomp10 committed Sep 18, 2023
1 parent cf181d0 commit 3150da9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions host/common/src/conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ unsigned int str2uint_suffix(const char *str,
bool *ok)
{
uint64_t mult;
unsigned int rv;
double val;
char *optr;

Expand All @@ -658,14 +657,15 @@ unsigned int str2uint_suffix(const char *str,
if (!*ok)
return false;

rv = (unsigned int)(val * mult);
if (val*mult > max) {
return max;
}

if (rv >= min && rv <= max) {
return rv;
if (val*mult < min) {
return min;
}

*ok = false;
return 0;
return (unsigned int)(val * mult);
}

uint64_t str2uint64_suffix(const char *str,
Expand Down

0 comments on commit 3150da9

Please sign in to comment.