Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Probably stack corruption in AttitudeManager.c adjustVNOrientationMatrix.c #77

Open
sergei1152 opened this issue Jan 14, 2017 · 4 comments

Comments

@sergei1152
Copy link

It looks like there could be possible stack corruption in the adjustVNOrientationMatrix function within AttitudeManager.c. You can see we declare an array of 9 floats, and pass it onto the vectornav function
VN100_SPI_GetRefFrameRot .

void adjustVNOrientationMatrix(float* adjustment){

    adjustment[0] = deg2rad(adjustment[0]);
    adjustment[1] = deg2rad(adjustment[1]);
    adjustment[2] = deg2rad(adjustment[2]);

    float matrix[9];
    VN100_SPI_GetRefFrameRot(0, (float*)&matrix);
    ...otherstuff...
}

Inside this function however we see that its going to try to write 12 bytes onto the variable (look at for loop). This will cause a corruption of the stack. According to chris everytime the adjustVNOrientation matrix function is called, the picpilot crashes, so this would explain why.

VN100_SPI_Packet* VN100_SPI_GetRefFrameRot(unsigned char sensorID, float* refFrameRot){

  unsigned long i;

  /* Read register */
  VN100_SPI_ReadRegister(sensorID, VN100_REG_RFR, 12);

  /* Get reference frame rotation parameters */
  for(i=0;i<12;i++){
    refFrameRot[i] = VN_SPI_LastReceivedPacket.Data[i].Float;
  }

  /* Return pointer to SPI packet */
  return &VN_SPI_LastReceivedPacket;
}
@sergei1152
Copy link
Author

This is actually due to the incorrect documentation found at the vectornav library, as it states you need to pass a 9x1 matrix

@CoatedMoose
Copy link
Contributor

CoatedMoose commented Jan 15, 2017 via email

@sergei1152
Copy link
Author

Its writing 12 32-bit words and i believe floats are 4 bytes

@CoatedMoose
Copy link
Contributor

CoatedMoose commented Jan 15, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants