From: mathog@seqaxp.bio.caltech.edu
Subject: Re: Compaq prefers Alpha over Merced! BUT OF COURSE, ALPHA *
Date: 1998/08/29 [thread overview]
Message-ID: <6s7hcd$sgs@gap.cco.caltech.edu> (raw)
In-Reply-To: 35fbd212.2154018254@news.axion.bt.co.uk
In article <35fbd212.2154018254@news.axion.bt.co.uk>, thomasgd@omc.bt.co.uk (Greg Thomas) writes:
>
>Think of OpenVMS descriptors, and have a pascal_strings.h which
>contains ...
>
> typedef struct
> {
> unsigned int length;
> void *string_ptr;
> } pascal_string_t;
That stores the length, but does not store the maximum length, so
you're still into buffer overrun land for safe_strcpy. Better would be:
typedef struct
{
unsigned int storage_length;
unsigned int length;
void *string_ptr;
} pascal_string_t;
Where storage_length is either set at malloc() time, or if strings are
packed into one big memory space, shortly thereafter. So it wastes a bit
of space in the data, but might end up being more efficient in other ways.
For instance
status=safe_strcat(safe_string1,safe_string2);
can check the sizes *before* it does anything, and then use
a nice efficient loop to transfer one onto the end of the other. You
call it, you know you're not going to get a buffer overrun.
Unfortunately, null terminated strings permeate the libraries, so that you
would probably have to resort to making all such strings one character
longer than they would overwise be (storage_length - 1) so that you can pop
a '\0' onto the end before calling printf (or whatever). That's still
nasty though - what if somebody passes you a read only safe_string?
To save the extra byte your safe_string.c module would have to implement
dozens, and dozens of functions.
That said, it would not be at all a bad idea to do so, since null
terminated strings seem to be at the root of at least half the problems in
C and C based operating systems.
Regards,
David Mathog
mathog@seqaxp.bio.caltech.edu
Manager, sequence analysis facility, biology division, Caltech
**************************************************************************
* RIP VMS *
**************************************************************************
next prev parent reply other threads:[~1998-08-29 4:00 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <0095000017115526000002L062*@MHS>
[not found] ` <35E04DF1.1911@world.std.com>
[not found] ` <35E09E76.6773@earthlink.net>
1998-08-23 4:00 ` Compaq prefers Alpha over Merced! BUT OF COURSE, ALPHA * Terry C. Shannon
1998-08-23 4:00 ` Glenn C. Everhart
1998-08-24 4:00 ` Paul Sture
1998-08-25 4:00 ` Gregg E Economou
1998-08-25 4:00 ` Jordan Henderson
1998-08-26 4:00 ` Bob Koehler
[not found] ` <6s910k$2bo$1@Starbase.NeoSoft.COM>
1998-08-29 4:00 ` Gregg E Economou
1998-08-30 4:00 ` Jay Maynard
[not found] ` <35e833be.0@news.wizvax.net>
1998-08-29 4:00 ` Jordan Henderson
1998-08-30 4:00 ` John Wilson
1998-08-30 4:00 ` JF Mezei
1998-08-30 4:00 ` Chris Torek
1998-08-31 4:00 ` Gregg E Economou
1998-08-31 4:00 ` Chris Torek
1998-08-30 4:00 ` Lawrence Kirby
1998-08-30 4:00 ` JF Mezei
1998-08-30 4:00 ` Martin Ambuhl
1998-08-31 4:00 ` Michael Rubenstein
[not found] ` <6scur7$qtk@bgtnsc02.wo <35EA0E22.C59E9476@videotron.ca>
1998-08-31 4:00 ` Will Rose
1998-08-31 4:00 ` Craig Franck
1998-08-30 4:00 ` JF Mezei
1998-08-31 4:00 ` firewind
1998-09-04 4:00 ` Thor Lancelot Simon
1998-08-30 4:00 ` Gregg E Economou
1998-08-30 4:00 ` K&R fight over ketchup (was: Compaq prefers Alpha over Merced! BUT OF COURSE, ALPHA ) Clint Comes
1998-08-31 4:00 ` Bob Koehler
1998-09-05 4:00 ` Gregg E Economou
1998-09-05 4:00 ` Compaq prefers Alpha over Merced! BUT OF COURSE, ALPHA * Peter da Silva
1998-09-05 4:00 ` Jordan Henderson
1998-09-07 4:00 ` Peter da Silva
1998-09-07 4:00 ` Jordan Henderson
1998-09-07 4:00 ` Peter da Silva
1998-09-07 4:00 ` Jordan Henderson
1998-09-08 4:00 ` Tim Shoppa
[not found] ` <6t4cui$hfu@espresso.cafe.net>
1998-09-09 4:00 ` Tim Shoppa
1998-09-08 4:00 ` JF Mezei
1998-09-09 4:00 ` Dan Pop
1998-09-09 4:00 ` Peter da Silva
1998-09-08 4:00 ` Peter da Silva
[not found] ` <6t2im5$mke@espresso.cafe.net>
1998-09-08 4:00 ` Peter da Silva
1998-09-08 4:00 ` Peter da Silva
1998-09-08 4:00 ` JF Mezei
1998-09-08 4:00 ` Dan Pop
1998-09-08 4:00 ` Peter da Silva
1998-09-08 4:00 ` Dan Pop
1998-09-07 4:00 ` Richard Stamp
1998-09-07 4:00 ` Dan Pop
1998-08-25 4:00 ` John Wilson
1998-08-26 4:00 ` Gregg E Economou
1998-08-27 4:00 ` John Wilson
1998-08-26 4:00 ` Bob Koehler
1998-08-27 4:00 ` Peter da Silva
1998-08-31 4:00 ` Boris
1998-08-27 4:00 ` Thor Lancelot Simon
1998-08-28 4:00 ` Bob Koehler
1998-09-05 4:00 ` Peter da Silva
1998-09-08 4:00 ` Carl Perkins
1998-08-28 4:00 ` TERENCE MURPHY
1998-08-28 4:00 ` George Cornelius
1998-08-28 4:00 ` Monty Brandenberg
1998-08-28 4:00 ` Greg Thomas
1998-08-29 4:00 ` mathog [this message]
1998-09-01 4:00 ` Greg Thomas
1998-08-29 4:00 ` Gregg E Economou
1998-09-05 4:00 ` Peter da Silva
1998-08-31 4:00 ` Boris
1998-08-26 4:00 ` Paul Sture
1998-08-27 4:00 ` Gregg E Economou
1998-08-28 4:00 ` Paul Sture
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox