You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A uint32_t variable is used as an array of uint8_t to try and store an IP address.
int8_tsocket(uint8_tsn, uint8_tprotocol, uint16_tport, uint8_tflag)
{
CHECK_SOCKNUM();
switch(protocol)
{
caseSn_MR_TCP :
{
//M20150601 : Fixed the warning - taddr will never be NULL/* uint8_t taddr[4]; getSIPR(taddr); */uint32_ttaddr; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< THIS VARIABLEgetSIPR((uint8_t*)&taddr);
if(taddr==0) returnSOCKERR_SOCKINIT;
break;
}
// ...
The problem is that the bytes are not always juxtaposed in that way in an array and, if they aren't, an out-of-bound write occurs, which overwrites other variables on the stack. For example the C2000 architecture is widely used for power electronics, and its smallest addressable cell is 16 bits. I was getting a bug where my port number would be the last byte of my IP, e.g. IP 192.168.0.150 would give port 150 no matter what.
I can see it was done because the word is tested against zero, but you could read the address as a byte array and make shifts, like it's done elsewhere in the file, like in connect():
A uint32_t variable is used as an array of uint8_t to try and store an IP address.
The problem is that the bytes are not always juxtaposed in that way in an array and, if they aren't, an out-of-bound write occurs, which overwrites other variables on the stack. For example the C2000 architecture is widely used for power electronics, and its smallest addressable cell is 16 bits. I was getting a bug where my port number would be the last byte of my IP, e.g. IP 192.168.0.150 would give port 150 no matter what.
I can see it was done because the word is tested against zero, but you could read the address as a byte array and make shifts, like it's done elsewhere in the file, like in connect():
The text was updated successfully, but these errors were encountered: