[TUHS] buffer overflow (Re: Happy birthday Morris worm

Robert Clausecker fuz at fuz.su
Wed Nov 13 08:41:51 AEST 2019

Oh please no.  One of the things we've hopefully all learned from Pascal
is that length-prefixed strings suck because you can't perform anything
useful without copying the entire string.  Rob Pike and friends showed
how to get strings and vectors right in the Go language where you have a
builtin slice type which is essentially a structure

    struct slice(type) {
            type *data;
            size_t len, cap;

where data points to a buffer, len is the length of meaningful data in
that buffer and cap is the total buffer size.  This allows the language
to take subslices and to append to existing slices without requiring
copies in most cases.  If a copy is necessary, the runtime can allocate
a slightly larger buffer in advance to allow for appending in amortised
linear time.

Overall, much more versatile than Pascal strings.

But let's get back to the topic, after all I promised not to flame as
much as Jörg did.

Robert Clausecker

On Tue, Nov 12, 2019 at 02:14:18PM -0800, Larry McVoy wrote:
> On Tue, Nov 12, 2019 at 02:10:46PM -0800, Bakul Shah wrote:
> > On Tue, 12 Nov 2019 15:56:15 -0500 Norman Wilson <norman at oclsc.org> wrote:
> > >
> > > My longer-term reaction was to completely drop my sloppy
> > > old habit (common in those days not just in my code but in
> > > that of many others) of ignoring possible buffer overflows.
> > > I find it mind-boggling that people still make that mistake;
> > > it has been literal decades since the lesson was rubbed in
> > > our community's collective noses.  I am very disappointed
> > > that programming education seems not to care enough about
> > > this sort of thing, even today.
> > 
> > Unfortunately strcpy & other buffer overflow friendly
> > functions are still present in the C standard (I am looking at
> > n2434.pdf, draft of Sept 25, 2019). Is C really not fixable?
> Someone needs to do Strcpy() etc that have the length in the 
> first bytes[s] of the string.
> -- 
> ---
> Larry McVoy            	     lm at mcvoy.com             http://www.mcvoy.com/lm 

()  ascii ribbon campaign - for an 8-bit clean world 
/\  - against html email  - against proprietary attachments

More information about the TUHS mailing list