Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can strncpy return 0?

The man page of strncpy states:

char *strncpy(char *dest, const char *src, size_t n);

The strcpy() and strncpy() functions return a pointer to the destination string dest.

Is it possible that strncpy(buff, "something", 9) == 0 be true if char buff[100]?

UPDATE

I also consider it as not very probable but it's part of a program that I should make to bufferoverflow and this condition stays on my way to achieve this.

like image 593
Brozorec Avatar asked Dec 14 '22 10:12

Brozorec


1 Answers

No.

Judging from the facts that

  1. The null pointer constant NULL's value equals 0
  2. A NULL pointer shall not point to a valid object. From the C11 standard, §6.3.2.3:

    [...] a null pointer [,] is guaranteed to compare unequal to a pointer to any object or function.

and that the corresponding man page does not mention the possibility of dest == NULL,
it is not allowed to.

like image 110
cadaniluk Avatar answered Dec 28 '22 07:12

cadaniluk