Protect against out of bounds memory type, replaces !3598

This commit is contained in:
Adam Honse
2026-09-11 17:21:29 -05:00
parent 6bb57b8822
commit 0440478acb
4 changed files with 40 additions and 6 deletions
+22 -3
View File
@@ -66,7 +66,8 @@ const char *spd_memory_type_name[] =
"LPDDR4",
"LPDDR4X",
"DDR5",
"LPDDR5"
"LPDDR5",
"Unknown"
};
SPDAccessor::SPDAccessor(i2c_smbus_interface *bus, uint8_t spd_addr)
@@ -161,7 +162,16 @@ DDR4Accessor::~DDR4Accessor()
SPDMemoryType DDR4Accessor::memory_type()
{
return((SPDMemoryType)(this->at(BASIC_MEMORY_TYPE_ADDR)));
SPDMemoryType type = (SPDMemoryType)(this->at(BASIC_MEMORY_TYPE_ADDR));
if(type <= SPD_UNKNOWN)
{
return(type);
}
else
{
return(SPD_UNKNOWN);
}
}
uint16_t DDR4Accessor::jedec_id()
@@ -195,7 +205,16 @@ DDR5Accessor::~DDR5Accessor()
SPDMemoryType DDR5Accessor::memory_type()
{
return((SPDMemoryType)(this->at(BASIC_MEMORY_TYPE_ADDR)));
SPDMemoryType type = (SPDMemoryType)(this->at(BASIC_MEMORY_TYPE_ADDR));
if(type <= SPD_UNKNOWN)
{
return(type);
}
else
{
return(SPD_UNKNOWN);
}
}
uint16_t DDR5Accessor::jedec_id()
+2 -1
View File
@@ -48,7 +48,8 @@ typedef enum
SPD_LPDDR4_SDRAM = 16,
SPD_LPDDR4X_SDRAM = 17,
SPD_DDR5_SDRAM = 18,
SPD_LPDDR5_SDRAM = 19
SPD_LPDDR5_SDRAM = 19,
SPD_UNKNOWN = 20,
} SPDMemoryType;
#define SPD_IO_DELAY 1ms
+8 -1
View File
@@ -30,7 +30,14 @@ bool SPDDetector::is_valid() const
SPDMemoryType SPDDetector::memory_type() const
{
return(mem_type);
if(mem_type <= SPD_UNKNOWN)
{
return(mem_type);
}
else
{
return(SPD_UNKNOWN);
}
}
void SPDDetector::detect_memory_type()
+8 -1
View File
@@ -65,7 +65,14 @@ SPDWrapper::~SPDWrapper()
SPDMemoryType SPDWrapper::memory_type()
{
return mem_type;
if(mem_type <= SPD_UNKNOWN)
{
return(mem_type);
}
else
{
return(SPD_UNKNOWN);
}
}
uint8_t SPDWrapper::address()