This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 2/2][BZ #14594] Mangle and demangle NULL pointers.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Thu, 31 Oct 2013 20:47:19 +0100
- Subject: [PATCH 2/2][BZ #14594] Mangle and demangle NULL pointers.
- Authentication-results: sourceware.org; auth=none
- References: <20131031194113 dot GA30302 at domone dot podge>
A problem here is that if a function pointer is mapped by PTR_MANGLE to
null it is indistingushible from NULL pointer so init will not be
called. This could be fixed by also mangling/demangling NULL pointer.
[BZ #14594]
* iconv/gconv_cache.c: Mangle and demangle NULL pointers.
* iconv/gconv_db.c: Likewise.
* iconv/gconv_dl.c: Likewise.
---
iconv/gconv_cache.c | 5 ++---
iconv/gconv_db.c | 11 ++++-------
iconv/gconv_dl.c | 6 ++----
3 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c
index a6a000a..dd6cca8 100644
--- a/iconv/gconv_cache.c
+++ b/iconv/gconv_cache.c
@@ -216,14 +216,13 @@ find_module (const char *directory, const char *filename,
result->__data = NULL;
/* Call the init function. */
+ PTR_DEMANGLE (init_fct);
if (result->__init_fct != NULL)
{
__gconv_init_fct init_fct = result->__init_fct;
- PTR_DEMANGLE (init_fct);
status = DL_CALL_FCT (init_fct, (result));
- if (result->__btowc_fct != NULL)
- PTR_MANGLE (result->__btowc_fct);
+ PTR_MANGLE (result->__btowc_fct);
}
}
diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c
index 45eb36a..8f32253 100644
--- a/iconv/gconv_db.c
+++ b/iconv/gconv_db.c
@@ -297,11 +297,11 @@ gen_steps (struct derivation_step *best, const char *toset,
/* Call the init function. */
__gconv_init_fct init_fct = result[step_cnt].__init_fct;
+ PTR_DEMANGLE (init_fct);
if (init_fct != NULL)
{
assert (result[step_cnt].__shlib_handle != NULL);
- PTR_DEMANGLE (init_fct);
status = DL_CALL_FCT (init_fct, (&result[step_cnt]));
if (__builtin_expect (status, __GCONV_OK) != __GCONV_OK)
@@ -313,8 +313,7 @@ gen_steps (struct derivation_step *best, const char *toset,
break;
}
- if (result[step_cnt].__btowc_fct != NULL)
- PTR_MANGLE (result[step_cnt].__btowc_fct);
+ PTR_MANGLE (result[step_cnt].__btowc_fct);
}
}
else
@@ -393,13 +392,11 @@ increment_counter (struct __gconv_step *steps, size_t nsteps)
/* Call the init function. */
__gconv_init_fct init_fct = step->__init_fct;
+ PTR_DEMANGLE (init_fct);
if (init_fct != NULL)
{
- PTR_DEMANGLE (init_fct);
DL_CALL_FCT (init_fct, (step));
-
- if (step->__btowc_fct != NULL)
- PTR_MANGLE (step->__btowc_fct);
+ PTR_MANGLE (step->__btowc_fct);
}
}
}
diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c
index e92876a..6c12341 100644
--- a/iconv/gconv_dl.c
+++ b/iconv/gconv_dl.c
@@ -139,10 +139,8 @@ __gconv_find_shlib (const char *name)
found->end_fct = __libc_dlsym (found->handle, "gconv_end");
PTR_MANGLE (found->fct);
- if (found->init_fct != NULL)
- PTR_MANGLE (found->init_fct);
- if (found->end_fct != NULL)
- PTR_MANGLE (found->end_fct);
+ PTR_MANGLE (found->init_fct);
+ PTR_MANGLE (found->end_fct);
/* We have succeeded in loading the shared object. */
found->counter = 1;
--
1.8.4.rc3