mirror of https://github.com/citusdata/citus.git
Fix an undefined behavior for bit shift in citus_stat_tenants.c (#7954)
DESCRIPTION: Fixes an undefined behavior that could happen when computing tenant score for citus_stat_tenants Add check for shift size, reset to zero in case of overflow Fixes #7953. --------- Co-authored-by: Onur Tirtir <onurcantirtir@gmail.com>pull/8158/head^2
parent
8ece8acac7
commit
2834fa26c9
|
|
@ -49,6 +49,9 @@ ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
|
|||
#define STAT_TENANTS_COLUMNS 9
|
||||
#define ONE_QUERY_SCORE 1000000000
|
||||
|
||||
/* this doesn't attempt dereferencing given input and is computed in compile-time, so it's safe */
|
||||
#define TENANT_STATS_SCORE_FIELD_BIT_LENGTH (sizeof(((TenantStats *) NULL)->score) * 8)
|
||||
|
||||
static char AttributeToTenant[MAX_TENANT_ATTRIBUTE_LENGTH] = "";
|
||||
static CmdType AttributeToCommandType = CMD_UNKNOWN;
|
||||
static int AttributeToColocationGroupId = INVALID_COLOCATION_ID;
|
||||
|
|
@ -605,8 +608,13 @@ ReduceScoreIfNecessary(TenantStats *tenantStats, TimestampTz queryTime)
|
|||
*/
|
||||
if (periodCountAfterLastScoreReduction > 0)
|
||||
{
|
||||
tenantStats->score >>= periodCountAfterLastScoreReduction;
|
||||
tenantStats->lastScoreReduction = queryTime;
|
||||
|
||||
/* addtional check to avoid undefined behavior */
|
||||
tenantStats->score = (periodCountAfterLastScoreReduction <
|
||||
TENANT_STATS_SCORE_FIELD_BIT_LENGTH)
|
||||
? tenantStats->score >> periodCountAfterLastScoreReduction
|
||||
: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue