Giter VIP home page Giter VIP logo

Comments (4)

zdethcore avatar zdethcore commented on July 19, 2024

(thanks for pointing me to this from the Omega forums)

good catch on this increasing buffer size, but, i think it doesn't affect the intended functionality once in _i2c_writeBuffer. So, inside of i2c_writeBuffer, in your example, size was: 3 | is: 4 and bufferNew is 5. Once passed to _i2c_writeBuffer, the actual write command still uses size (which is 4), so you'll be writing the address + 3 bytes. Only consequence I see, is that you're wasting the time and space to store garbage in bufferNew[5] (or am I wrong?)

// generic function to write a buffer to the i2c bus
int _i2c_writeBuffer(int devNum, int devAddr, uint8_t *buffer, int size)
{
	int 	status;
	int 	fd, index;
        ......
	// write to the i2c device
	status = write(fd, buffer, size);
	..........
	return (status);
}`

from i2c-exp-driver.

maxgerhardt avatar maxgerhardt commented on July 19, 2024

It will correctly write the write number of bytes to the I2C device (address + initially given buffer), right. (However bufferNew has 4 byte allocated, not 5, and the overwritten index is bufferNew[4], the 5th byte from the start, but the rest is correct)

However the damage is already done after the memcpy beyond the boundaries of bufferNew because the allocated / malloc()ed space just isn't big enough (by 1 byte). This will cause an overwrite into some other memory structure on the heap or a heap information block, which can cause subsequent program failure.

Memory / heap corruption might even be exploitable in special settings, i.e. be used for a system takeover by attacking the programs using this I2C library (https://googleprojectzero.blogspot.de/2015/06/what-is-good-memory-corruption.html).

from i2c-exp-driver.

greenbreakfast avatar greenbreakfast commented on July 19, 2024

@maxgerhardt yep, you were absolutely correct, we were copying by the incremented size instead of the actual size.
We've released v0.7 of libonioni2c, please try it out and let us know if there's any issues.

from i2c-exp-driver.

maxgerhardt avatar maxgerhardt commented on July 19, 2024

Yep, this off-by-one was fixed.

from i2c-exp-driver.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.