[PATCH 0/3] Build with libbsd for strlcpy

182 views
Skip to first unread message

ba...@linutronix.de

unread,
Dec 29, 2020, 10:36:05 AM12/29/20
to swup...@googlegroups.com, Bastian Germann, sz...@debian.org
From: Bastian Germann <ba...@linutronix.de>

Besides the missing copyright and license information for OpenBSD's
strlcpy implementation, there is another problem with it.

Building with a libbsd-configured zeromq can trigger a linking error.
This series intends to fix that by using libbsd for SWUpdate as well.

Bastian Germann (3):
Revert "Replace own implementation of strlcpy with FreeBSD"
Revert "Introduce strlcpy() as string copy replacement"
Build with libbsd for strlcpy

Makefile.flags | 3 +++
core/util.c | 33 ---------------------------------
doc/source/swupdate.rst | 1 +
include/util.h | 6 +-----
4 files changed, 5 insertions(+), 38 deletions(-)

--
2.29.2

ba...@linutronix.de

unread,
Dec 29, 2020, 10:36:06 AM12/29/20
to swup...@googlegroups.com, Bastian Germann
From: Bastian Germann <ba...@linutronix.de>

This reverts commit 43b59c9bc5a8073f4170d152a10720c6df5e021f.

Signed-off-by: Bastian Germann <ba...@linutronix.de>
---
core/util.c | 41 +++++++++++++++--------------------------
1 file changed, 15 insertions(+), 26 deletions(-)

diff --git a/core/util.c b/core/util.c
index 69d02c5..6f5313e 100644
--- a/core/util.c
+++ b/core/util.c
@@ -224,35 +224,24 @@ char *substring(const char *src, int first, int len) {
}

#if defined(__linux__)
-
-/*
- * Copy string src to buffer dst of size dsize. At most dsize-1
- * chars will be copied. Always NUL terminates (unless dsize == 0).
- * Returns strlen(src); if retval >= dsize, truncation occurred.
- */
size_t
-strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize)
+strlcpy(char *dst, const char * src, size_t size)
{
- const char *osrc = src;
- size_t nleft = dsize;
-
- /* Copy as many bytes as will fit. */
- if (nleft != 0) {
- while (--nleft != 0) {
- if ((*dst++ = *src++) == '\0')
- break;
- }
- }
-
- /* Not enough room in dst, add NUL and traverse rest of src. */
- if (nleft == 0) {
- if (dsize != 0)
- *dst = '\0'; /* NUL-terminate dst */
- while (*src++)
- ;
- }

- return(src - osrc - 1); /* count does not include NUL */
+ size_t len = strlen(src);
+ /*
+ * src is null termintaed,
+ * copy the last '\0', too.
+ */
+ if (len < size) {
+ memcpy(dst, src, len + 1);
+ } else if (len) {
+ /* truncate string */
+ memcpy(dst, src, size - 1);
+ /* Add C string terminator */
+ dst[size - 1] = '\0';
+ }
+ return len;
}
#endif

--
2.29.2

ba...@linutronix.de

unread,
Dec 29, 2020, 10:36:07 AM12/29/20
to swup...@googlegroups.com, Bastian Germann
From: Bastian Germann <ba...@linutronix.de>

The previously included strlcpy implementation can conflict with libbsd
if REMOTE_HANDLER is enabled and zeromq is built with libbsd.

On Linux, build with libbsd to get rid of that error:
handlers/built-in.o: undefined reference to symbol 'strlcpy@@LIBBSD_0.0'

Link: https://salsa.debian.org/debian/swupdate/-/jobs/1288597
Signed-off-by: Bastian Germann <ba...@linutronix.de>
---
Makefile.flags | 3 +++
doc/source/swupdate.rst | 1 +
include/util.h | 1 +
3 files changed, 5 insertions(+)

diff --git a/Makefile.flags b/Makefile.flags
index 7003af1..783cb89 100644
--- a/Makefile.flags
+++ b/Makefile.flags
@@ -101,6 +101,9 @@ KBUILD_CFLAGS += --sysroot=$(CONFIG_SYSROOT)
export SYSROOT=$(CONFIG_SYSROOT)
endif

+ifeq ($(HAVE_LINUX),y)
+LDLIBS += bsd
+endif
# Links always pthread
LDLIBS += pthread
# lua
diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst
index a8144d1..ede3b10 100644
--- a/doc/source/swupdate.rst
+++ b/doc/source/swupdate.rst
@@ -210,6 +210,7 @@ There are only a few libraries that are required to compile SWUpdate.
- openssl / wolfssl / mbedtls (optional) for cryptographic operations
- p11-kit & wolfssl (optional) for PKCS#11 support
- Lua: liblua and the development headers.
+- libbsd is linked on Linux.
- libz is always linked.
- libconfig (optional) for the default parser
- libarchive (optional) for archive handler
diff --git a/include/util.h b/include/util.h
index e5a8955..d6df2b8 100644
--- a/include/util.h
+++ b/include/util.h
@@ -13,6 +13,7 @@
#include <string.h>
#include <stdio.h>
#if defined(__linux__)
+#include <bsd/string.h>
#include <linux/types.h>
#endif
#include "swupdate.h"
--
2.29.2

ba...@linutronix.de

unread,
Dec 29, 2020, 10:36:07 AM12/29/20
to swup...@googlegroups.com, Bastian Germann
From: Bastian Germann <ba...@linutronix.de>

This reverts commit ca00d834c6f335ac53ab97dfd8e64fce3c24f3c0.

Signed-off-by: Bastian Germann <ba...@linutronix.de>
---
core/util.c | 22 ----------------------
include/util.h | 5 -----
2 files changed, 27 deletions(-)

diff --git a/core/util.c b/core/util.c
index 6f5313e..2025276 100644
--- a/core/util.c
+++ b/core/util.c
@@ -223,28 +223,6 @@ char *substring(const char *src, int first, int len) {
return s;
}

-#if defined(__linux__)
-size_t
-strlcpy(char *dst, const char * src, size_t size)
-{
-
- size_t len = strlen(src);
- /*
- * src is null termintaed,
- * copy the last '\0', too.
- */
- if (len < size) {
- memcpy(dst, src, len + 1);
- } else if (len) {
- /* truncate string */
- memcpy(dst, src, size - 1);
- /* Add C string terminator */
- dst[size - 1] = '\0';
- }
- return len;
-}
-#endif
-
int openfileoutput(const char *filename)
{
int fdout;
diff --git a/include/util.h b/include/util.h
index a0edd3e..e5a8955 100644
--- a/include/util.h
+++ b/include/util.h
@@ -181,11 +181,6 @@ int copy_write(void *out, const void *buf, unsigned int len);
#if defined(__FreeBSD__)
int copy_write_padded(void *out, const void *buf, unsigned int len);
#endif
-#if defined(__linux__)
-/* strlcpy was originally developped in FreeBSD, not present in glibc */
-size_t
-strlcpy(char *dst, const char * src, size_t size);
-#endif
int copyfile(int fdin, void *out, unsigned int nbytes, unsigned long *offs,
unsigned long long seek,
int skip_file, int compressed, uint32_t *checksum,
--
2.29.2

Stefano Babic

unread,
Dec 29, 2020, 11:01:05 AM12/29/20
to ba...@linutronix.de, swup...@googlegroups.com, sz...@debian.org
Hi Bastian,

On 29.12.20 16:35, ba...@linutronix.de wrote:
> From: Bastian Germann <ba...@linutronix.de>
>
> Besides the missing copyright and license information for OpenBSD's
> strlcpy implementation, there is another problem with it.
>
> Building with a libbsd-configured zeromq can trigger a linking error.
> This series intends to fix that by using libbsd for SWUpdate as well.
>

I am quite prudent to add further libraries and dependencies to the
project if they are not really needed. In this case, we are talking
about a single function that consists of just a bunch of code. Sure, it
should be added to the function that code is coming from BSD or from
libsd itself. But I tend to prefer the own implementation in SWUpdate if
no other functions from libsd are used.

Regarding zeroMQ, I am hitting another bigger issue. zeroMQ is released
under LGPL, but LGPLv3.

This is then incompatible with GPLv2. I am to remove the remote handler
(and zeroMQ) completely from SWUpdate. Are you using the remote handler
or is there anybody out there complaining abot its removal ?

Best regards,
Stefano Babic

> Bastian Germann (3):
> Revert "Replace own implementation of strlcpy with FreeBSD"
> Revert "Introduce strlcpy() as string copy replacement"
> Build with libbsd for strlcpy
>
> Makefile.flags | 3 +++
> core/util.c | 33 ---------------------------------
> doc/source/swupdate.rst | 1 +
> include/util.h | 6 +-----
> 4 files changed, 5 insertions(+), 38 deletions(-)
>


--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================

Bastian Germann

unread,
Dec 29, 2020, 11:11:23 AM12/29/20
to Stefano Babic, swup...@googlegroups.com
Am 29.12.20 um 17:00 schrieb Stefano Babic:
> Hi Bastian,
>
>> Besides the missing copyright and license information for OpenBSD's
>> strlcpy implementation, there is another problem with it.
>>
>> Building with a libbsd-configured zeromq can trigger a linking error.
>> This series intends to fix that by using libbsd for SWUpdate as well.
>>
>
> I am quite prudent to add further libraries and dependencies to the
> project if they are not really needed. In this case, we are talking
> about a single function that consists of just a bunch of code. Sure, it
> should be added to the function that code is coming from BSD or from
> libsd itself. But I tend to prefer the own implementation in SWUpdate if
> no other functions from libsd are used.

Please add the copyright/license information then.

>
> Regarding zeroMQ, I am hitting another bigger issue. zeroMQ is released
> under LGPL, but LGPLv3.
>
> This is then incompatible with GPLv2. I am to remove the remote handler
> (and zeroMQ) completely from SWUpdate. Are you using the remote handler
> or is there anybody out there complaining abot its removal ?

I do not use the remote handler.

According to http://wiki.zeromq.org/area:licensing, zeroMQ has a linking
exception which intends to heal this license issue. They also want to
relicense under MPLv2 in the future.
Reply all
Reply to author
Forward
0 new messages