Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
Subject: Re: Strange errors from strtok()
Date: Mon, 1 Dec 1997 15:15:40 -0700 (MST)	[thread overview]
Message-ID: <6d99e1c0bed6ec7401410004501a79b7.axp-list@archive.invalid> (raw)
In-Reply-To: <3.0.5.32.19971201143733.009a4d00@atlas>

Rob Zook wrote:
> >strtok() is not declared,
....
> But why didn't I get some kind of link error? Why did it produce an
> executible at all if strtok was not declared or defined in my code?

strtok() is not declared, making compiler unhappy, but it still exists
in libraries which are passed to a linker.  Linker does not know
anything about declarations and headers, it cares only about resolving
symbols, so your program will link.

Now compiler produced some code, assuming that all undeclared types
defaulted to 'int' and this may, or may not, be what was expected.
On 32-bit machine, where various integer types and pointers are all four
byte wide, there is, unfortunately, a pretty good chance that all this
fits and bugs are masked.  But if your machine is 16-bit, or 64-bit -
like Alpha, and a silent assumptions of "the same width" fails, you may
be heading straight into a "crash and burn" land.

> 
> I know, gets() can produce dangerours results, and I plan to add a
> dynamic allocation for postline based on the results of CONTENT_LENGTH, 
> but not while I'm testing.

Using fgets() instead of gets() does not put much more burden on you
nor requires a dynamic allocation.  Do not forget about trailing '\0'.

> Besides, just using a pointer in c can cause dangerous results, so
> this message from the c compiler looks more like somebody at GNU's 
> personal problem to me.

A little knowledge of a C programming is a very dangerous thing.
The problem is not very personal as attested by numerous security
bugs caused by buffer overflows and stack smashing.

  Michal

-- 
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

  reply	other threads:[~1997-12-01 22:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <199712012014.NAA14201@ellpspace.math.ualberta.ca>
1997-12-01 20:37 ` Strange errors from strtok() Rob Zook
1997-12-01 22:15   ` Michal Jaegermann [this message]
1997-12-01 21:09 Przemek Klosowski
     [not found] <19971201115108.03468@dot.cygnus.com>
1997-12-01 20:16 ` Rob Zook
     [not found] <01bcfe7f$60288060$323ccbd0@zeke.bainet.com>
1997-12-01 19:03 ` Rob Zook
1997-12-01 19:51   ` Richard Henderson
1997-12-01 20:14   ` Michal Jaegermann
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