Viktor Dukhovni:
> On Fri, Oct 12, 2012 at 07:13:43PM -0400, Wietse Venema wrote:
>
> > > So the ADDINT macro should use " %lu" rather than "%lu".
> >
> > Just to be safe, should not there be a delimiter between
> > string fields, too? That would be the equivalent of " %s".
>
> Those are already NUL delimited. The vstring_memcat includes the
> terminating NUL byte. The hash table key is binary not ASCII.
>
> We could for consistency NUL terminate the ints also:
>
> "%lu%c", (unsigned long) i, '\0'
If strings are separated with a trailer (the *printf equivalent of
``"%s%c", value, 0''), then the numbers should also be separated
with a trailer, for example "%lu " or ``"%lu%c", value, 0''.
The null is guaranteed not to appear in the strings or in formatted
numbers, so that would be the safest choice.
Wietse
*** ./src/global/dict_ldap.c- Tue Jan 31 16:27:12 2012
--- ./src/global/dict_ldap.c Sat Oct 13 07:50:31 2012
***************
*** 930,937 ****
#endif
LDAP_CONN *conn;
#define ADDSTR(vp, s) vstring_memcat((vp), (s), strlen((s))+1)
! #define ADDINT(vp, i) vstring_sprintf_append((vp), "%lu", (unsigned long)(i))
ADDSTR(keybuf, dict_ldap->server_host);
ADDINT(keybuf, dict_ldap->server_port);
--- 930,940 ----
#endif
LDAP_CONN *conn;
+ /*
+ * Join key fields with null characters.
+ */
#define ADDSTR(vp, s) vstring_memcat((vp), (s), strlen((s))+1)
! #define ADDINT(vp, i) vstring_sprintf_append((vp), "%lu%c", (unsigned
long)(i), 0)
ADDSTR(keybuf, dict_ldap->server_host);
ADDINT(keybuf, dict_ldap->server_port);