Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Update libsbuf to the latest version
Baptiste Daroussin committed 9 years ago
commit 0ca616c35f1062bbf2f889ec57d58d097bef10b6
parent e637b1a
3 files changed +111 -50
modified NEWS
@@ -2,7 +2,8 @@ Changes from pkg 1.9
- Fix fd leak on systems without utimensat (merged in release branch)
- Do not use openssl for sha256
- Improve the default output when fetching data
-
- update libfetch to the version of FreeBSD 11
+
- Update libfetch to the version of FreeBSD 11
+
- Update libsbuf to the version of FreeBSD 11

Changes from pkg 1.8

modified external/libsbuf/subr_sbuf.c
@@ -27,17 +27,19 @@
 */

#include <sys/cdefs.h>
-
/* __FBSDID("$FreeBSD: head/sys/kern/subr_sbuf.c 255805 2013-09-22 23:47:56Z des $"); */
+
/* __FBSDID("$FreeBSD: head/sys/kern/subr_sbuf.c 288484 2015-10-02 09:23:14Z phk $"); */

#include <sys/param.h>
#ifndef roundup2
-
#define        roundup2(x, y)  (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
+
#define roundup2(x, y)  (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
#endif

+

#ifdef _KERNEL
#include <sys/ctype.h>
#include <sys/errno.h>
#include <sys/kernel.h>
+
#include <sys/limits.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/uio.h>
@@ -45,6 +47,7 @@
#else /* _KERNEL */
#include <ctype.h>
#include <errno.h>
+
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -73,6 +76,7 @@ static MALLOC_DEFINE(M_SBUF, "sbuf", "string buffers");
#define	SBUF_FREESPACE(s)	((s)->s_size - ((s)->s_len + 1))
#define	SBUF_CANEXTEND(s)	((s)->s_flags & SBUF_AUTOEXTEND)
#define	SBUF_ISSECTION(s)	((s)->s_flags & SBUF_INSECTION)
+
#define	SBUF_NULINCLUDED(s)	((s)->s_flags & SBUF_INCLUDENUL)

/*
 * Set / clear flags
@@ -80,6 +84,7 @@ static MALLOC_DEFINE(M_SBUF, "sbuf", "string buffers");
#define	SBUF_SETFLAG(s, f)	do { (s)->s_flags |= (f); } while (0)
#define	SBUF_CLEARFLAG(s, f)	do { (s)->s_flags &= ~(f); } while (0)

+
#define	SBUF_MINSIZE		 2		/* Min is 1 byte + nulterm. */
#define	SBUF_MINEXTENDSIZE	16		/* Should be power of 2. */

#ifdef PAGE_SIZE
@@ -103,9 +108,15 @@ _assert_sbuf_integrity(const char *fun, struct sbuf *s)
	    ("%s called with a NULL sbuf pointer", fun));
	KASSERT(s->s_buf != NULL,
	    ("%s called with uninitialized or corrupt sbuf", fun));
-
	KASSERT(s->s_len < s->s_size,
-
	    ("wrote past end of sbuf (%jd >= %jd)",
-
	    (intmax_t)s->s_len, (intmax_t)s->s_size));
+
        if (SBUF_ISFINISHED(s) && SBUF_NULINCLUDED(s)) {
+
		KASSERT(s->s_len <= s->s_size,
+
		    ("wrote past end of sbuf (%jd >= %jd)",
+
		    (intmax_t)s->s_len, (intmax_t)s->s_size));
+
	} else {
+
		KASSERT(s->s_len < s->s_size,
+
		    ("wrote past end of sbuf (%jd >= %jd)",
+
		    (intmax_t)s->s_len, (intmax_t)s->s_size));
+
	}
}

static void
@@ -188,8 +199,9 @@ sbuf_newbuf(struct sbuf *s, char *buf, int length, int flags)
	s->s_buf = buf;

	if ((s->s_flags & SBUF_AUTOEXTEND) == 0) {
-
		KASSERT(s->s_size >= 0,
-
		    ("attempt to create a too small sbuf"));
+
		KASSERT(s->s_size >= SBUF_MINSIZE,
+
		    ("attempt to create an sbuf smaller than %d bytes",
+
		    SBUF_MINSIZE));
	}

	if (s->s_buf != NULL)
@@ -265,6 +277,28 @@ sbuf_uionew(struct sbuf *s, struct uio *uio, int *error)
}
#endif

+
int
+
sbuf_get_flags(struct sbuf *s)
+
{
+

+
	return (s->s_flags & SBUF_USRFLAGMSK);
+
}
+

+
void
+
sbuf_clear_flags(struct sbuf *s, int flags)
+
{
+

+
	s->s_flags &= ~(flags & SBUF_USRFLAGMSK);
+
}
+

+
void
+
sbuf_set_flags(struct sbuf *s, int flags)
+
{
+

+

+
	s->s_flags |= (flags & SBUF_USRFLAGMSK);
+
}
+

/*
 * Clear an sbuf and reset its position.
 */
@@ -355,34 +389,51 @@ sbuf_drain(struct sbuf *s)
}

/*
-
 * Append a byte to an sbuf.  This is the core function for appending
+
 * Append bytes to an sbuf.  This is the core function for appending
 * to an sbuf and is the main place that deals with extending the
 * buffer and marking overflow.
 */
static void
-
sbuf_put_byte(struct sbuf *s, int c)
+
sbuf_put_bytes(struct sbuf *s, const char *buf, size_t len)
{
+
	size_t n;

	assert_sbuf_integrity(s);
	assert_sbuf_state(s, 0);

	if (s->s_error != 0)
		return;
-
	if (SBUF_FREESPACE(s) <= 0) {
-
		/*
-
		 * If there is a drain, use it, otherwise extend the
-
		 * buffer.
-
		 */
-
		if (s->s_drain_func != NULL)
-
			(void)sbuf_drain(s);
-
		else if (sbuf_extend(s, 1) < 0)
-
			s->s_error = ENOMEM;
-
		if (s->s_error != 0)
-
			return;
+
	while (len > 0) {
+
		if (SBUF_FREESPACE(s) <= 0) {
+
			/*
+
			 * If there is a drain, use it, otherwise extend the
+
			 * buffer.
+
			 */
+
			if (s->s_drain_func != NULL)
+
				(void)sbuf_drain(s);
+
			else if (sbuf_extend(s, len > INT_MAX ? INT_MAX : len)
+
			    < 0)
+
				s->s_error = ENOMEM;
+
			if (s->s_error != 0)
+
				return;
+
		}
+
		n = SBUF_FREESPACE(s);
+
		if (len < n)
+
			n = len;
+
		memcpy(&s->s_buf[s->s_len], buf, n);
+
		s->s_len += n;
+
		if (SBUF_ISSECTION(s))
+
			s->s_sect_len += n;
+
		len -= n;
+
		buf += n;
	}
-
	s->s_buf[s->s_len++] = c;
-
	if (SBUF_ISSECTION(s))
-
		s->s_sect_len++;
+
}
+

+
static void
+
sbuf_put_byte(struct sbuf *s, char c)
+
{
+

+
	sbuf_put_bytes(s, &c, 1);
}

/*
@@ -391,19 +442,10 @@ sbuf_put_byte(struct sbuf *s, int c)
int
sbuf_bcat(struct sbuf *s, const void *buf, size_t len)
{
-
	const char *str = buf;
-
	const char *end = str + len;
-

-
	assert_sbuf_integrity(s);
-
	assert_sbuf_state(s, 0);

+
	sbuf_put_bytes(s, buf, len);
	if (s->s_error != 0)
		return (-1);
-
	for (; str < end; str++) {
-
		sbuf_put_byte(s, *str);
-
		if (s->s_error != 0)
-
			return (-1);
-
	}
	return (0);
}

@@ -457,18 +499,12 @@ sbuf_bcpy(struct sbuf *s, const void *buf, size_t len)
int
sbuf_cat(struct sbuf *s, const char *str)
{
+
	size_t n;

-
	assert_sbuf_integrity(s);
-
	assert_sbuf_state(s, 0);
-

+
	n = strlen(str);
+
	sbuf_put_bytes(s, str, n);
	if (s->s_error != 0)
		return (-1);
-

-
	while (*str != '\0') {
-
		sbuf_put_byte(s, *str++);
-
		if (s->s_error != 0)
-
			return (-1);
-
	}
	return (0);
}

@@ -591,6 +627,10 @@ sbuf_vprintf(struct sbuf *s, const char *fmt, va_list ap)
		va_copy(ap_copy, ap);
		len = vsnprintf(&s->s_buf[s->s_len], SBUF_FREESPACE(s) + 1,
		    fmt, ap_copy);
+
		if (len < 0) {
+
			s->s_error = errno;
+
			return (-1);
+
		}
		va_end(ap_copy);

		if (SBUF_FREESPACE(s) >= len)
@@ -700,11 +740,13 @@ sbuf_finish(struct sbuf *s)
	assert_sbuf_integrity(s);
	assert_sbuf_state(s, 0);

+
	s->s_buf[s->s_len] = '\0';
+
	if (SBUF_NULINCLUDED(s))
+
		s->s_len++;
	if (s->s_drain_func != NULL) {
		while (s->s_len > 0 && s->s_error == 0)
			s->s_error = sbuf_drain(s);
	}
-
	s->s_buf[s->s_len] = '\0';
	SBUF_SETFLAG(s, SBUF_FINISHED);
#ifdef _KERNEL
	return (s->s_error);
@@ -746,6 +788,10 @@ sbuf_len(struct sbuf *s)

	if (s->s_error != 0)
		return (-1);
+

+
	/* If finished, nulterm is already in len, else add one. */
+
	if (SBUF_NULINCLUDED(s) && !SBUF_ISFINISHED(s))
+
		return (s->s_len + 1);
	return (s->s_len);
}

modified external/libsbuf/sys/sbuf.h
@@ -25,15 +25,13 @@
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
-
 *      $FreeBSD: head/sys/sys/sbuf.h 249377 2013-04-11 19:49:18Z trociny $
+
 *      $FreeBSD: head/sys/sys/sbuf.h 284192 2015-06-09 21:39:38Z ken $
 */

#ifndef _SYS_SBUF_H_
#define	_SYS_SBUF_H_

-
#include <sys/cdefs.h>
-
#include <sys/types.h>
-
#include <stdarg.h>
+
#include <sys/_types.h>

struct sbuf;
typedef int (sbuf_drain_func)(void *, const char *, int);
@@ -50,6 +48,7 @@ struct sbuf {
	ssize_t		 s_len;		/* current length of string */
#define	SBUF_FIXEDLEN	0x00000000	/* fixed length buffer (default) */
#define	SBUF_AUTOEXTEND	0x00000001	/* automatically extend buffer */
+
#define	SBUF_INCLUDENUL	0x00000002	/* nulterm byte is counted in len */
#define	SBUF_USRFLAGMSK	0x0000ffff	/* mask of flags the user may specify */
#define	SBUF_DYNAMIC	0x00010000	/* s_buf must be freed */
#define	SBUF_FINISHED	0x00020000	/* set by sbuf_finish() */
@@ -59,6 +58,14 @@ struct sbuf {
	ssize_t		 s_sect_len;	/* current length of section */
};

+
#ifndef HD_COLUMN_MASK
+
#define	HD_COLUMN_MASK	0xff
+
#define	HD_DELIM_MASK	0xff00
+
#define	HD_OMIT_COUNT	(1 << 16)
+
#define	HD_OMIT_HEX	(1 << 17)
+
#define	HD_OMIT_CHARS	(1 << 18)
+
#endif /* HD_COLUMN_MASK */
+

__BEGIN_DECLS
/*
 * API functions
@@ -66,14 +73,19 @@ __BEGIN_DECLS
struct sbuf	*sbuf_new(struct sbuf *, char *, int, int);
#define		 sbuf_new_auto()				\
	sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND)
+
int		 sbuf_get_flags(struct sbuf *);
+
void		 sbuf_clear_flags(struct sbuf *, int);
+
void		 sbuf_set_flags(struct sbuf *, int);
void		 sbuf_clear(struct sbuf *);
int		 sbuf_setpos(struct sbuf *, ssize_t);
int		 sbuf_bcat(struct sbuf *, const void *, size_t);
int		 sbuf_bcpy(struct sbuf *, const void *, size_t);
int		 sbuf_cat(struct sbuf *, const char *);
int		 sbuf_cpy(struct sbuf *, const char *);
-
int		 sbuf_printf(struct sbuf *, const char *, ...);
-
int		 sbuf_vprintf(struct sbuf *, const char *, va_list);
+
int		 sbuf_printf(struct sbuf *, const char *, ...)
+
	__printflike(2, 3);
+
int		 sbuf_vprintf(struct sbuf *, const char *, __va_list)
+
	__printflike(2, 0);
int		 sbuf_putc(struct sbuf *, int);
void		 sbuf_set_drain(struct sbuf *, sbuf_drain_func *, void *);
int		 sbuf_trim(struct sbuf *);
@@ -85,6 +97,8 @@ int sbuf_done(const struct sbuf *);
void		 sbuf_delete(struct sbuf *);
void		 sbuf_start_section(struct sbuf *, ssize_t *);
ssize_t		 sbuf_end_section(struct sbuf *, ssize_t, size_t, int);
+
void		 sbuf_hexdump(struct sbuf *, const void *, int, const char *,
+
		     int);

#ifdef _KERNEL
struct uio;