6adaa40135
There's been a very long and interesting discussion in linux-man@ and libc-alpha@, where we've discussed all the string-copying functions, their pros and cons, when should each be used and avoided, etc. Paul Eggert pointed out an important problem of strlcpy(3): it is vulnerable to DoS attacks if an attacker controls the length of the source string. And even if it doesn't control it, the function is dead slow (because its API forces it to calculate strlen(src)). We've agreed that the general solution for a truncating string-copying function is to write a wrapper over strnlen(3)+memcpy(3), which is limited to strnlen(src, sizeof(dst)). This is not vulnerable to DoS, and is very fast for all buffer sizes. string_copying(7) has been updated to reflect this, and provides a reference implementation for this wrapper function. This strtcpy(3) (t for truncation) wrapper happens to have the same API that our strlcpy_() function had, so replace it with the better implementation. We don't need to update callers nor tests, since the API is the same. A future commit will rename STRLCPY() to STRTCPY(), and replace remaining calls to strlcpy(3) by calls to this strtcpy(3). Link: <https://lore.kernel.org/linux-man/ZU4SDh-Se5gjPny5@debian/T/#mfb5a3fdeb35487dec6f8d9e3d8548bd0d92c4975/> Signed-off-by: Alejandro Colomar <alx@kernel.org>
64 lines
1.1 KiB
Makefile
64 lines
1.1 KiB
Makefile
AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)
|
|
|
|
if HAVE_CMOCKA
|
|
TESTS = $(check_PROGRAMS)
|
|
|
|
check_PROGRAMS = \
|
|
test_strlcpy \
|
|
test_xasprintf
|
|
|
|
if ENABLE_LOGIND
|
|
check_PROGRAMS += \
|
|
test_logind
|
|
endif # ENABLE_LOGIND
|
|
|
|
check_PROGRAMS += \
|
|
$(NULL)
|
|
|
|
test_logind_SOURCES = \
|
|
../../lib/logind.c \
|
|
test_logind.c \
|
|
$(NULL)
|
|
test_logind_CFLAGS = \
|
|
$(AM_CFLAGS) \
|
|
-lsystemd \
|
|
$(NULL)
|
|
test_logind_LDFLAGS = \
|
|
-Wl,-wrap,prefix_getpwnam \
|
|
-Wl,-wrap,sd_uid_get_sessions \
|
|
$(NULL)
|
|
test_logind_LDADD = \
|
|
$(CMOCKA_LIBS) \
|
|
$(LIBSYSTEMD) \
|
|
$(NULL)
|
|
|
|
test_strlcpy_SOURCES = \
|
|
../../lib/strlcpy.c \
|
|
test_strlcpy.c \
|
|
$(NULL)
|
|
test_strlcpy_CFLAGS = \
|
|
$(AM_FLAGS) \
|
|
$(NULL)
|
|
test_strlcpy_LDFLAGS = \
|
|
$(NULL)
|
|
test_strlcpy_LDADD = \
|
|
$(CMOCKA_LIBS) \
|
|
$(NULL)
|
|
|
|
test_xasprintf_SOURCES = \
|
|
../../lib/sprintf.c \
|
|
test_xasprintf.c \
|
|
$(NULL)
|
|
test_xasprintf_CFLAGS = \
|
|
$(AM_FLAGS) \
|
|
$(NULL)
|
|
test_xasprintf_LDFLAGS = \
|
|
-Wl,-wrap,vasprintf \
|
|
-Wl,-wrap,exit \
|
|
$(NULL)
|
|
test_xasprintf_LDADD = \
|
|
$(CMOCKA_LIBS) \
|
|
$(NULL)
|
|
|
|
endif # HAVE_CMOCKA
|