Security Impact of using strncmp()?

863 Views Asked by At

I've been doing a little research on the security of strncmp and I understand it's not null terminated. But I've also seen how some people are saying it is "not a secure replacement for strcmp()." Could anyone explain this to me please? I've been looking for a while but really the only place i can find that says that is here on SO on a few questions. Maybe someone could link me a few resources for looking into this? Thanks.

1

There are 1 best solutions below

1
tikna On

I think this thread might help you - Is there any safe strcmp?

In short, even though you can send in the size of the strings to be compared, strncmp will still read garbage values if the string is shorter than size 'n' and it is not null terminated.

Similar to your question - Why should you use strncpy instead of strcpy?