Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C driver causing segmentation fault in onion-i2c.c #20

Closed
shaheenm82 opened this issue Oct 20, 2017 · 4 comments
Closed

I2C driver causing segmentation fault in onion-i2c.c #20

shaheenm82 opened this issue Oct 20, 2017 · 4 comments

Comments

@shaheenm82
Copy link

When performing reads and writes the buffer is often cleared by performing a memset. the driver assumes a buffer of 32 bytes and always performs
memset( buffer, 0, I2C_BUFFER_SIZE );

If the user supplies a smaller or bigger buffer, this could not have the intended effect. For a smaller buffer this can overwrite memory past the end of the supplied buffer, thus causing a segmentation fault.

Rather use the nbytes parameter and only perform a memset on the length of the buffer provided.

@greenbreakfast
Copy link
Contributor

Yes, we had seen this as well and fixed it in the read-fix branch. It just never got brought to the master branch.

Did it now, will release an updated package soon!

@maxgerhardt
Copy link

maxgerhardt commented May 10, 2018

Is this true? Seems like it was never merged. There are still offending lines:

https://github.com/OnionIoT/i2c-exp-driver/blob/master/src/lib/onion-i2c.c#L313

Re-discovered these while trying to write a I2C device driver and wondering why my programm keeps crashing with a corrupted stack.

greenbreakfast added a commit that referenced this issue Jun 7, 2018
@greenbreakfast
Copy link
Contributor

The read-fix branch was indeed merged but it only had fixes for the i2c_write() and i2c_readByte() functions. This function, i2c_readRaw(), had the same issue but was overlooked.

In any case, it's fixed now and part of the v0.7 libonioni2c release. Please try it out and let me know if you have any issues.

@maxgerhardt
Copy link

The code looks good now. I was able to remove my workarounds for library bugs and it does work with the newest version! Issue can be closed IMO.

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

No branches or pull requests

3 participants