Request: please hide or rename set_variable function
Philipp Klenze
pklenze at ph.tum.de
Tue Feb 9 14:23:28 UTC 2016
Dear all,
I would like to ask you to change the name of the function set_variable
in
https://git.samba.org/samba.git/?p=samba.git;a=blob;f=lib/param/loadparm.c#l1672
to something more unique.
I have just debugged code by someone who was using the same function
name in his own code. When he called gethostbyname(),
libsamba-hostconfig.so.0 was loaded by libc due to a nsswitch setting.
Rather sooner than later, the library tried to run set_variable.
Naturally, it ran the wrong one, which expected a very different call
stack and everything ended with a segfault.
I think everyone understands naming ones local functions fprintf,
__libc_malloc or the like is asking for trouble. But set_variable? There
is no clue at all for the user that function name might be forbidden, no
manpage entry, nothing. Even using ldd and nm to find out all defined
symbols in every linked library would not help, as libsamba-hostconfig
seems to be loaded on demand by libc.
As this particular function name is one other programmers out there
might use as well, would you please change it?
Thanks,
Philipp
PS: Actually, GCC supports limiting which symbols will be exported, see
[0] for details. This would probably be the cleanest way to fix this issue.
[0]
https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html
-------------- next part --------------
#0 0x000000000083a9d9 in set_variable ()
#1 0x00007fffe4451a84 in lpcfg_do_global_parameter (lp_ctx=lp_ctx at entry=0x5188b10,
pszParmName=pszParmName at entry=0x7fffe7f5d5d8 "log level", pszParmValue=pszParmValue at entry=0x7fffe7f5d5d6 "0")
at ../lib/param/loadparm.c:1628
#2 0x00007fffe4451fa4 in lpcfg_set_cmdline (lp_ctx=0x5188b10,
pszParmName=pszParmName at entry=0x7fffe7f5d5d8 "log level", pszParmValue=pszParmValue at entry=0x7fffe7f5d5d6 "0")
at ../lib/param/loadparm.c:1754
#3 0x00007fffe7af8754 in lp_set_cmdline (pszParmName=pszParmName at entry=0x7fffe7f5d5d8 "log level",
pszParmValue=pszParmValue at entry=0x7fffe7f5d5d6 "0") at ../source3/param/loadparm.c:2508
#4 0x00007fffe7f5d3ba in nss_wins_init () at ../nsswitch/wins.c:52
#5 lookup_byname_backend (count=0x7fffffffd51c, name=0x7fffffffd5b0 "nx2.ktas.ph.tum.de")
at ../nsswitch/wins.c:69
#6 _nss_wins_gethostbyname_r (hostname=<optimized out>, he=0x7fffee31de20 <resbuf.11724>,
buffer=0x5132760 "\177", buflen=1024, h_errnop=<optimized out>) at ../nsswitch/wins.c:303
#7 0x00007fffee06e053 in __gethostbyname_r (name=name at entry=0x5140790 "nx2.ktas.ph.tum.de",
resbuf=resbuf at entry=0x7fffee31de20 <resbuf.11724>, buffer=0x5132760 "\177", buflen=1024,
result=result at entry=0x7fffffffd7e0, h_errnop=h_errnop at entry=0x7fffffffd7d0) at ../nss/getXXbyYY_r.c:266
#8 0x00007fffee06d786 in gethostbyname (name=0x5140790 "nx2.ktas.ph.tum.de") at ../nss/getXXbyYY.c:116
-------------- next part --------------
(gdb) info function set_variable
All functions matching regular expression "set_variable":
File ../lib/param/loadparm.c:
_Bool set_variable(TALLOC_CTX *, struct loadparm_service *, int, void *, const char *, const char *,
struct loadparm_context *, _Bool);
static _Bool set_variable_helper(TALLOC_CTX *, int, void *, const char *, const char *);
Non-debugging symbols:
0x000000000083a9d9 set_variable
0x00007fffe444a4e0 set_variable at plt
(gdb) info symbol 0x000000000083a9d9
set_variable in section .text of /home/software/hades/install/hgeant/821p/hgeant
# ^ -----BAD
(gdb) info symbol 0x00007fffe444a4e0
set_variable at plt in section .plt of /usr/lib64/libsamba-hostconfig.so.0
# ^------GOOD
More information about the samba-technical
mailing list