News for hackers. Stuff that matters.
Re:Git's list of banned C functions by rrauenza on Thursday March 04, 2021 @04:43PM (#26348819)
I never could really understand the point of strncpy()... we always end up wrapping to deal with writing an unterminated string.

Was it intended for fixed length records?

Re:Git's list of banned C functions by tedunangst on Thursday March 04, 2021 @04:49PM (#26348900)
It is for fixed length records, which is why it also zeroes the remaining space.
Re:Git's list of banned C functions by ironmagma on Thursday March 04, 2021 @05:04PM (#26349081)
Arguably naming it with “str” is itself a security vulnerability.
Re:Git's list of banned C functions by tedunangst on Thursday March 04, 2021 @05:07PM (#26349114)
No argument. At best it is a "string to fixed record" function, hence the name, but it is not a string function.
Re:Git's list of banned C functions by Someone on Thursday March 04, 2021 @05:33PM (#26349422)
Yes. strncpy was intended for copying file names into a buffer that was only zero terminated when the name was shorter than the maximum length of a file name in Unix (14 bytes. See https://stackoverflow.com/a/1454071, https://devblogs.microsoft.com/oldnewthing/20050107-00/?p=36...)

You can also use it to overwrite part of an existing string, but I think that’s a side effect of the above.

Re:Git's list of banned C functions by spc476 on Thursday March 04, 2021 @08:03PM (#26351001)
Yes it was. On early Unix systems, each entry in a directory was bascially:

    struct dir
    {
      char name[14];
      int  inode;
    };
Adding a NUL byte might waste a full byte that could otherwise be used---remember, back when C was first developed, 10M disks were large and very expensive.