strncpy

Tags:

How can code that tries to prevent a buffer overflow end up causing one?

strncpy 는 null-padding을 하지 않을 수 있고 이것이 또다른 BOF의
원인이 될 수 있다.라는 것이군요…

null-padding을 보장하는 n개 문자 복사

char buf[N+1];
buf[N] = 0′
… strncpy(buf, src, N);

그렇군요…

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *