Skip to content

Commit

Permalink
rtld-audit.7: Use correct printf() specifier for pointer types
Browse files Browse the repository at this point in the history
In the example code you used %x rather than %p in the example
code for an audit library. The problem is that it truncates the
pointers on 64b platforms. So you get something like:

la_symbind64(): symname = strrchr sym->st_value = 0x7f4b8a3f8960
ndx = 222 flags = 0x0 refcook = 8b53e5c8 defcook = 8b537e30

rather than:

la_symbind64(): symname = fclose sym->st_value = 0x7fa452dd49b0
ndx = 1135 flags = 0x0 refcook = 0x7fa453f395c8 defcook = 0x7fa453f32e30

This has bitten me a handful of times when playing around with
audit test libraries to investigate its behavior.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
  • Loading branch information
woodard authored and mkerrisk committed May 19, 2015
1 parent d850c7e commit 8e83cef
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions man7/rtld-audit.7
Expand Up @@ -515,7 +515,7 @@ la_version(unsigned int version)
char *
la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag)
{
printf("la_objsearch(): name = %s; cookie = %x", name, cookie);
printf("la_objsearch(): name = %s; cookie = %p", name, cookie);
printf("; flag = %s\\n",
(flag == LA_SER_ORIG) ? "LA_SER_ORIG" :
(flag == LA_SER_LIBPATH) ? "LA_SER_LIBPATH" :
Expand All @@ -531,7 +531,7 @@ la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag)
void
la_activity (uintptr_t *cookie, unsigned int flag)
{
printf("la_activity(): cookie = %x; flag = %s\\n", cookie,
printf("la_activity(): cookie = %p; flag = %s\\n", cookie,
(flag == LA_ACT_CONSISTENT) ? "LA_ACT_CONSISTENT" :
(flag == LA_ACT_ADD) ? "LA_ACT_ADD" :
(flag == LA_ACT_DELETE) ? "LA_ACT_DELETE" :
Expand All @@ -541,7 +541,7 @@ la_activity (uintptr_t *cookie, unsigned int flag)
unsigned int
la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
{
printf("la_objopen(): loading \\"%s\\"; lmid = %s; cookie=%x\\n",
printf("la_objopen(): loading \\"%s\\"; lmid = %s; cookie=%p\\n",
map\->l_name,
(lmid == LM_ID_BASE) ? "LM_ID_BASE" :
(lmid == LM_ID_NEWLM) ? "LM_ID_NEWLM" :
Expand All @@ -554,15 +554,15 @@ la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
unsigned int
la_objclose (uintptr_t *cookie)
{
printf("la_objclose(): %x\\n", cookie);
printf("la_objclose(): %p\\n", cookie);

return 0;
}

void
la_preinit(uintptr_t *cookie)
{
printf("la_preinit(): %x\\n", cookie);
printf("la_preinit(): %p\\n", cookie);
}

uintptr_t
Expand All @@ -572,7 +572,7 @@ la_symbind32(Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
printf("la_symbind32(): symname = %s; sym\->st_value = %p\\n",
symname, sym\->st_value);
printf(" ndx = %d; flags = 0x%x", ndx, *flags);
printf("; refcook = %x; defcook = %x\\n", refcook, defcook);
printf("; refcook = %p; defcook = %p\\n", refcook, defcook);

return sym\->st_value;
}
Expand All @@ -584,7 +584,7 @@ la_symbind64(Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
printf("la_symbind64(): symname = %s; sym\->st_value = %p\\n",
symname, sym\->st_value);
printf(" ndx = %d; flags = 0x%x", ndx, *flags);
printf("; refcook = %x; defcook = %x\\n", refcook, defcook);
printf("; refcook = %p; defcook = %p\\n", refcook, defcook);

return sym\->st_value;
}
Expand Down

0 comments on commit 8e83cef

Please sign in to comment.