[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BUG in ltdl.c - here's a PATCH

From: Lutz Müller
Subject: Re: BUG in ltdl.c - here's a PATCH
Date: 14 Jun 2002 19:49:47 +0200

On Fri, 2002-06-14 at 18:23, Albert Chin wrote:
> Shouldn't we find out why filename is non-zero terminated?

No, you didn't get it. If you do

strncpy (filename, dir_name, strlen (dir_name));

filename will afterwards not be terminated by '\0' (unless filename has
previously been initialized to 0, for example by memset (filename, 0,
...)). If you copy a string, you need to copy the terminating '\0', too,

strncpy (filename, dir_name, strlen (dir_name) + 1);

> How about
> we initialize filename[0] = '\0' after alloc? Anyway, I don't think
> LT_EMALLOC should null-terminate the string (who knows if you're
> always allocating a string) but I think we *definitely* need to
> null-terminate filename after LT_EMALLOC.

Not quite right. We need to terminate the filename after dir_name got
copied over it without a terminating '\0'. That is, you could do a 

strncpy (filename, dir_name, strlen (dir_name));
filename[strlen (dir_name)] = '\0';

or initialize filename in its full length to '\0' before like

memset (filename, 0, filenamesize);
strncpy (filename, dir_name, strlen (dir_name));

but I like my one-liner better.

> Does the patch below work?

No, to no surprise.

| Lutz Müller                 +49 (7156) 34837 |
|                                              |
| Hans-Sachs-Strasse 5                         |
| 71254 Ditzingen |
| Germany           address@hidden |

reply via email to

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