Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c,comp.programming,comp.sys.raspberry-pi Subject: Re: C is not a low level language Followup-To: comp.lang.c Date: Sun, 24 Feb 2019 17:59:38 -0800 Organization: None to speak of Lines: 20 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="d7a76040ef7e877133de8f8312ada9dc"; logging-data="30378"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PRFQM5/ZIZGhsR3tlxOki" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:bVkk89fknvoUIfnNxqvYbztzs5A= sha1:nOx/BCDsBswXJlj9Ve7/ni78Zlg= >From: Keith Thompson Xref: csiph.com comp.lang.c:141268 comp.programming:9676 comp.sys.raspberry-pi:19704 "R.Wieser" writes: [...] > True. But that only goes as far as the programmer can imagine such attacks. > "strncpy" is ment as a "last ditch" effort to safeguard against the > /unforseen/ circumstances which could lead to memory/stack being clobbered. > My suggestion to provide it an argument that is one less than what the > buffer can actually hold is just an extension on that. No, strncpy is designed to work with a specific (and, in recent history, rare) data structure, namely a fixed-length character array containing some bytes of meaningful data padded to the end by zero or more null bytes. (I believe it was used to store file names in Unix directory entries.) (followups to comp.lang.c only) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */