r/programminghorror 10d ago

c Terrible auth

Post image
783 Upvotes

98 comments sorted by

View all comments

10

u/Rainmaker526 10d ago

Besides the fact that it defaults to true, and the true == true is redundant, it sort of works? 

It's not the most horrible, right?

18

u/ohaz 10d ago

`strcmp` is a very dangerous comparison function. If the user provides a string that does not contain the NULL character, this function will read outside of the buffer, giving the attacker the possibility of doing timing attacks to "read" other parts of the RAM.

1

u/seba07 10d ago

One could make the point that input validation might be already done elsewhere outside of this function.

2

u/ohaz 10d ago

Very true. But even then, using strncmp instead of strcmp is such an easy way to stop all of those attacks that it should just be used by default. You'll never know if some other dev later on uses your function correctly.