Patch for dl-cache.c
Jakub Jelinek
jakub@redhat.com
Wed Nov 24 07:21:00 GMT 1999
On Wed, Nov 24, 1999 at 03:40:28PM +0100, Andreas Jaeger wrote:
>
> Jakub found a bug in my version of ldconfig, which is also in glibc's
> dl-cache. I'm appending a patch for dl-cache.c.
>
> The bug is that the final NUL in CACHEMAGIC is part of the magic - but
> the data structure doesn't reserve space for it (this worked due to
> alignment).
That was a misunderstanding. Cache magic seems to be without the final NUL
in H.J.'s version I looked at, it was just my ldconfig hack to make it emit
0 in the pad and not random value, now when I look at it it would be better
to just make sure the whole structure with all its padding is zero:
--- ldconfig/cache.c.jj Wed Nov 24 10:13:33 1999
+++ ldconfig/cache.c Wed Nov 24 16:13:53 1999
@@ -54,7 +54,7 @@ struct file_entry
struct cache_file
{
- char magic[sizeof CACHEMAGIC];
+ char magic[sizeof CACHEMAGIC - 1];
unsigned int nlibs;
struct file_entry libs[0];
};
@@ -129,7 +129,7 @@ print_cache (const char *cache_name)
cache_size = st.st_size;
if (cache_size < sizeof (struct cache_file)
- || memcmp (cache->magic, CACHEMAGIC, sizeof CACHEMAGIC))
+ || memcmp (cache->magic, CACHEMAGIC, sizeof CACHEMAGIC - 1))
return;
/* This is where the strings start. */
cache_data = (const char *) &cache->libs[cache->nlibs];
@@ -248,7 +248,8 @@ save_cache (const char *cache_name)
file_entries = (struct cache_file *) xmalloc (file_entries_size);
/* Fill in the header. */
- memcpy (file_entries->magic, CACHEMAGIC, sizeof CACHEMAGIC);
+ memset (file_entries, 0, sizeof (struct cache_file));
+ memcpy (file_entries->magic, CACHEMAGIC, sizeof CACHEMAGIC - 1);
file_entries->nlibs = cache_entry_count;
Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.18 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________
More information about the Libc-hacker
mailing list