libbsd: Branch 'main' - 5 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 4 02:30:24 UTC 2022


 COPYING               |    2 +-
 README                |    5 ++++-
 src/fgetwln.c         |    3 +++
 src/setmode.c         |    4 +++-
 test/explicit_bzero.c |   15 +++++++++++++++
 5 files changed, 26 insertions(+), 3 deletions(-)

New commits:
commit ef981f930b0e7ab64eef1985d5e812bada3a6332
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Oct 4 04:28:05 2022 +0200

    doc: Add missing empty line to separate README sections

diff --git a/README b/README
index 195f5f0..c545bdc 100644
--- a/README
+++ b/README
@@ -9,6 +9,7 @@ A BSD compatible message-digest library is required, on systems where
 this is not provided by its libc or libmd libraries, the canonical
 implementation to use is <https://www.hadrons.org/software/libmd/>.
 
+
 Releases
 --------
 
@@ -38,6 +39,7 @@ and cloned from:
 
   <https://anongit.freedesktop.org/git/libbsd>
 
+
 Building from git source
 ------------------------
 
@@ -55,6 +57,7 @@ the git tree:
 
 the source should be roughly equivalent to the distributed tar source.
 
+
 Building from tar source
 ------------------------
 
commit 6928d7895edfe8a62d3c73d8938713c5ddb29774
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Oct 4 04:27:44 2022 +0200

    doc: Refer to the main git repository as primary

diff --git a/README b/README
index 4e4b43f..195f5f0 100644
--- a/README
+++ b/README
@@ -30,7 +30,7 @@ The mail address is:
 Source Repository
 -----------------
 
-The master repository can be browsed at:
+The primary repository can be browsed at:
 
   <https://cgit.freedesktop.org/libbsd>
 
commit d5865759f8698f1c75339451a26fa3ae00276a51
Author: Guillem Jover <guillem at hadrons.org>
Date:   Thu Aug 25 00:52:43 2022 +0200

    test: Fix explicit_bzero() test on the Hurd
    
    On the Hurd a small read(3) might end up (indirectly) copying the data
    on the stack, which we will end up finding even when we have cleared
    the buffer.
    
    To avoid these side effects, we add a new function, that we force not
    to be inlined, so that we can reuse the same stack space, that will
    blank any possible stack side effects. This should be portable
    regardless of stack growing up or down.
    
    Diagnosis-by: Samuel Thibault <sthibault at debian.org>

diff --git a/COPYING b/COPYING
index 67223d4..cf43edd 100644
--- a/COPYING
+++ b/COPYING
@@ -369,7 +369,7 @@ Copyright:
  Copyright © 2014 Theo de Raadt <deraadt at openbsd.org>
  Copyright © 2014 Google Inc.
  Copyright © 2015 Michael Felt <aixtools at gmail.com>
- Copyright © 2015 Guillem Jover <guillem at hadrons.org>
+ Copyright © 2015, 2022 Guillem Jover <guillem at hadrons.org>
 License: ISC
  Permission to use, copy, modify, and distribute this software for any
  purpose with or without fee is hereby granted, provided that the above
diff --git a/test/explicit_bzero.c b/test/explicit_bzero.c
index 74993c2..bee29de 100644
--- a/test/explicit_bzero.c
+++ b/test/explicit_bzero.c
@@ -1,6 +1,7 @@
 /*	$OpenBSD: explicit_bzero.c,v 1.7 2021/03/27 11:17:58 bcook Exp $	*/
 /*
  * Copyright (c) 2014 Google Inc.
+ * Copyright (c) 2022 Guillem Jover <guillem at hadrons.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -123,6 +124,18 @@ populate_secret(char *buf, ssize_t len)
 	ASSERT_EQ(0, close(fds[0]));
 }
 
+static void __attribute__((__noinline__))
+blank_stack_side_effects(char *buf, size_t len)
+{
+	char scratch[SECRETBYTES * 4];
+
+	/* If the read(3) in populate_secret() wrote into the stack, as it
+	 * might happen on the Hurd for small data, then we might incorrectly
+	 * detect the wrong secret on the stack. */
+	memset(scratch, 0xFF, sizeof(scratch));
+	ASSERT_EQ(NULL, memmem(scratch, sizeof(scratch), buf, len));
+}
+
 static int
 count_secrets(const char *buf)
 {
@@ -143,6 +156,7 @@ test_without_bzero(void)
 	char *res;
 	assert_on_stack();
 	populate_secret(buf, sizeof(buf));
+	blank_stack_side_effects(buf, sizeof(buf));
 	res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf));
 	ASSERT_NE(NULL, res);
 	return (res);
@@ -155,6 +169,7 @@ test_with_bzero(void)
 	char *res;
 	assert_on_stack();
 	populate_secret(buf, sizeof(buf));
+	blank_stack_side_effects(buf, sizeof(buf));
 	res = memmem(altstack, ALTSTACK_SIZE, buf, sizeof(buf));
 	ASSERT_NE(NULL, res);
 	explicit_bzero(buf, sizeof(buf));
commit be327c6ebe408ae144e9c93aab9cb65fce116f33
Author: Guillem Jover <guillem at hadrons.org>
Date:   Wed Aug 24 01:58:58 2022 +0200

    fgetwln: Add comment about lack of getwline(3) for recommendation
    
    Ideally we'd recommend getwline(3), but unfortunately even though it
    was part of the ISO/IEC TR 24731-2:2010 draft, it did not make it into
    C11 and is not widely implemented.

diff --git a/src/fgetwln.c b/src/fgetwln.c
index f2ea094..0b8e7d9 100644
--- a/src/fgetwln.c
+++ b/src/fgetwln.c
@@ -87,6 +87,9 @@ fgetwln(FILE *stream, size_t *lenp)
 	*lenp = wused;
 	return wused ? fb->wbuf : NULL;
 }
+/* XXX: Ideally we'd recommend getwline(3), but unfortunately even though it
+ * was part of the ISO/IEC TR 24731-2:2010 draft, it did not make it into C11
+ * and is not widely implemented. */
 libbsd_link_warning(fgetwln,
                     "The fgetwln() function cannot be safely ported, use fgetwc(3) "
                     "instead, as it is supported by C99 and POSIX.1-2001.");
commit a14612d96819d5e0561bff2da89a6fdea990223c
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Aug 23 23:49:34 2022 +0200

    setmode: Dot not use saveset after free
    
    While we are only doing a pointer difference and not dereferencing it,
    it's easier and more correct to do the pointer difference before passing
    it to reallocarray().
    
    Warned-by: gcc

diff --git a/src/setmode.c b/src/setmode.c
index f65875e..c92cdc5 100644
--- a/src/setmode.c
+++ b/src/setmode.c
@@ -36,6 +36,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include <stddef.h>
 #include <ctype.h>
 #include <errno.h>
 #include <signal.h>
@@ -144,12 +145,13 @@ common:			if (set->cmd2 & CMD2_CLR) {
 
 #define	ADDCMD(a, b, c, d) do {						\
 	if (set >= endset) {						\
+		ptrdiff_t setdiff = set - saveset;			\
 		BITCMD *newset;						\
 		setlen += SET_LEN_INCR;					\
 		newset = reallocarray(saveset, setlen, sizeof(BITCMD));	\
 		if (newset == NULL)					\
 			goto out;					\
-		set = newset + (set - saveset);				\
+		set = newset + setdiff;					\
 		saveset = newset;					\
 		endset = newset + (setlen - 2);				\
 	}								\


More information about the libbsd mailing list