Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2002:
[Freeciv-Dev] Re: (PR#2546) Everything compiles now BUT
Home

[Freeciv-Dev] Re: (PR#2546) Everything compiles now BUT

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: bernd.korz@xxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2546) Everything compiles now BUT
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Wed, 11 Dec 2002 07:45:56 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Wed, Dec 11, 2002 at 05:50:43AM -0800, Bernd Korz via RT wrote:
> I can conmpile now everything (server AND client)
> 
> but when i start the client i get a short time a BWindow (a Window) and 
> then it crashs and i get that sc:
> 
> loading symbols
> segment violation occurred
> real_mystrdup:
> real_mystrdup:
> +0040  80074e28:   *          108b    movl    (%eax), %edx
> civclient:sc
>    frame         retaddr
> fcffc554   8004672a  load_intro_gfx + 00000046
> fcffc57c   80047797  ui_init + 00000073
> fcffc5b0   8001b3d8  main + 000004c8
> fcffc5ec   80018cc4  _start + 00000060

This is an indication of two problems. A local one and a global
one. The local one is that in client/gui-sdl/graphics.c:

  pIntro_gfx_path = mystrdup(datafilename("theme/default/intro3.png"));
  pLogo_gfx_path = mystrdup(datafilename("theme/default/logo.png"));
  pCity_gfx_path = mystrdup(datafilename("theme/default/city.png"));

datafilename may return NULL. This leads us to the second global one:

  There is no semantic defined for strlen(NULL), strdup(NULL) and
  strcpy(..., NULL).

Neither the C standard, man-pages nor OpenGroup said something about
the NULL case. So while for it may work (strlen(NULL) == 0 for
example) on most systems doesn't mean that it is safe everywhere. In
the BeOS case it crashes. Also note that I also didn't found any
mention of the NULL case for strlcpy. So it looks like we have to do
some auditing (strlen) and add guards to other functions (mystrdup) to
catch the NULL case. The latter can be "if(!str){die("NULL string);}"
or "if(!str){return strdup("");}".

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Life is too short for reboots."




[Prev in Thread] Current Thread [Next in Thread]