Menu

#149 libssp redefines strncasecmp(), needs namespace cleanup

v2.1
closed
None
5
2017-04-07
2015-10-20
No

libslp 2.0.0 redefines strncasecmp() unless HAVE_STRNCASECMP,
it does not #define. This breaks OpenLDAP when linking with
libslp on at least Linux and FreeBSD. Building openslp with
'./configure CPPFLAGS=-DHAVE_STRNCASECMP' fixes it.

The proper way is to call it e.g. slp_strncasecmp(), and
maybe '#define strncasecmp slp_strncasecmp' for convenience
in some private header file. That way it'll work whether
or not the system has an strncasecmp you did not notice.

The same goes for some other function names. 'nm -g libslp.so'
shows a fair number of symbol names which the calling program
might also use, e.g. GetUINT16, timeval_add. A library should
use a much smaller namespace.

Discussion

  • Hallvard B Furuseth

    Your str[n]casecmp() are broken. Arguments to <ctype.h> functions should be in the range of 'unsigned char' or EOF. I.e. tolower((unsigned char)s1) when s1 is a string.
    There are such calls in common/slp_compare.c, libslpattr/libslpattr.c, slpd/slpd_predicate.c.
    Also it should return (int)...
    s1 - (int)...s2, not (int)(...s1 - (int)...*s2); Or just drop the cast since unsigned char will be promoted to int except if the char type is as wide as int.

     
  • John Calcote

    John Calcote - 2017-04-07
    • status: open --> accepted
    • assigned_to: John Calcote
    • Group: --> v2.1
     
  • John Calcote

    John Calcote - 2017-04-07

    Hallvard -

    Thank you so much for the thorough analysis - I've taken all your suggestions into account in this bug fix - as you can see from the outputs below, I've cleaned up libslp significantly, leaving only those items that are highly unlikely to collide with other libraries:

    DEBUG (with security and async api enabled)

    $ nm -g libslp/.libs/libslp.so | grep " [TR] " | grep -vi " [TR] SLP"
    000000000001e4b0 T _fini
    000000000001ee30 R in6addr_srvlocda_link
    000000000001ee20 R in6addr_srvlocda_node
    000000000001ee40 R in6addr_srvlocda_site
    000000000001ee00 R in6addr_srvloc_link
    000000000001edf0 R in6addr_srvloc_node
    000000000001ee10 R in6addr_srvloc_site
    00000000000058a0 T _init
    000000000000b1bb T KnownDABadDA
    000000000000b02f T KnownDAConnect
    000000000000b686 T KnownDAFreeAll
    000000000000b238 T KnownDAGetScopes
    000000000000b564 T KnownDAProcessSrvRqst
    000000000000ad8b T KnownDARefreshCache
    0000000000009eb3 T KnownDASpanningListFind
    000000000000af16 T KnownDASpanningListFromCache
    00000000000104dc T LIBSLPPropertyCleanup
    000000000001045b T LIBSLPPropertyInit
    000000000000bfdb T NetworkConnectToDA
    000000000000c137 T NetworkConnectToSA
    000000000000be1a T NetworkConnectToSlpd
    000000000000bf5a T NetworkDisconnectDA
    000000000000bf9e T NetworkDisconnectSA
    000000000000cf08 T NetworkMcastRqstRply
    000000000000e1e6 T NetworkMultiUcastRqstRply
    000000000000c2a4 T NetworkRqstRply
    000000000000e0ee T NetworkUcastRqstRply

    RELEASE (with security and async api enabled)

    $ nm -g libslp/.libs/libslp.so | grep " [TR] " | grep -vi " [TR] SLP"
    0000000000015fb8 T _fini
    00000000000162f0 R in6addr_srvlocda_link
    0000000000016300 R in6addr_srvlocda_node
    00000000000162e0 R in6addr_srvlocda_site
    0000000000016320 R in6addr_srvloc_link
    0000000000016330 R in6addr_srvloc_node
    0000000000016310 R in6addr_srvloc_site
    00000000000056a0 T _init
    00000000000093a0 T KnownDABadDA
    0000000000009410 T KnownDAConnect
    0000000000009970 T KnownDAFreeAll
    0000000000009620 T KnownDAGetScopes
    0000000000009890 T KnownDAProcessSrvRqst
    00000000000091d0 T KnownDARefreshCache
    0000000000008f30 T KnownDASpanningListFind
    00000000000092a0 T KnownDASpanningListFromCache
    000000000000d1e0 T LIBSLPPropertyCleanup
    000000000000d170 T LIBSLPPropertyInit
    0000000000009b80 T NetworkConnectToDA
    0000000000009d90 T NetworkConnectToSA
    0000000000009a40 T NetworkConnectToSlpd
    0000000000009b20 T NetworkDisconnectDA
    0000000000009b50 T NetworkDisconnectSA
    000000000000aa70 T NetworkMcastRqstRply
    000000000000ba30 T NetworkMultiUcastRqstRply
    0000000000009ff0 T NetworkRqstRply
    000000000000b990 T NetworkUcastRqstRply

    Additionally, I've fixed our implementations of strcasecmp and strncasecmp and, in fact, all ctype function calls throughout the code base, promoting parameters to the 'is' and 'to' methods from char to unsigned char as per your recommendations. Frankly, I was personally unaware of these constraints - you've taught me something. Thank you.

    Regards,
    John

     
  • John Calcote

    John Calcote - 2017-04-07
    • status: accepted --> closed
     

Log in to post a comment.