Compare commits

...

13 Commits
0.8.1 ... 0.8.3

Author SHA1 Message Date
Guillem Jover
9bed430ee3 Release libbsd 0.8.3 2016-04-23 10:13:23 +02:00
Szabolcs Nagy
cbfe0ebca9 Add missing <fcntl.h> includes
These are required due to the O_* macro usage, but have passed
undetected on glibc-based systems due to implicit inclusions.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2016-03-27 12:42:34 +02:00
Guillem Jover
f3b566bd7c test: Add a unit test for md5 2016-03-27 12:31:58 +02:00
Guillem Jover
e86c1b5f43 man: Fix ungrammatical construct
Warned-by: lintian
2016-02-14 09:01:24 +01:00
Guillem Jover
b7ce33cf51 build: Support clock_gettime() provided in librt
In older glibc versions (< 2.17) clock_gettime() is in librt. Add a
check for this to avoid build breakage for programs/libraries that
use libbsd on such systems.

Based-on-patch-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2016-02-13 08:46:47 +01:00
Guillem Jover
ed84bec5aa Switch URLs from http or git to https 2016-02-13 08:46:35 +01:00
Guillem Jover
cbe3057703 Fix file descriptor leak in HASHFileChunk helper
This leak only happens on error conditions, so it's not too bad.

Warned-by: coverity
2016-02-07 09:17:08 +01:00
Guillem Jover
5a32ea0a72 Fix unportable sizeof() usage
We are calculating the size of the array, and need to pass the size of
each element, not the size of a pointer to an element. Although this
happens to be the same in many cases, this is not a portable assumption.

Warned-by: coverity
2016-02-07 09:16:47 +01:00
Guillem Jover
2fb148a290 Release libbsd 0.8.2 2016-01-27 15:25:23 +01:00
Hanno Boeck
c8f0723d2b Fix heap buffer overflow in fgetwln()
In the function fgetwln() there's a 4 byte heap overflow.

There is a while loop that has this check to see whether there's still
enough space in the buffer:

		if (!fb->len || wused > fb->len) {

If this is true more memory gets allocated. However this test won't be
true if wused == fb->len, but at that point wused already points out
of the buffer. Some lines later there's a write to the buffer:

		fb->wbuf[wused++] = wc;

This bug was found with the help of address sanitizer.

Warned-by: ASAN
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=93881
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2016-01-27 15:24:50 +01:00
Hanno Boeck
008316aa29 test: Add missing <sys/stat.h> include
The test in test/strmode.c can fail to compile depending on the
optimization flags used.

The constants that are used in this file (S_IFREG etc.) come from the
<sys/stat.h> include file. It seems gcc ignores this error if one
compiles with "-O2" (default), but if one uses no optimization it fails.

Add the missing include and it works all the time.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=93880
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2016-01-27 15:24:39 +01:00
Guillem Jover
e4ab2c62cd test: Fix success return code for arc4random unit test 2016-01-11 02:35:34 +01:00
Lukas Fleischer
bf5573f86c test: Fix race condition in headers-*.sh
When running tests in parallel (e.g. using `make -j4 check`), the header
tests currently fail due to headers-overlay.sh and headers-system.sh
both generating headers-gen.c simultaneously, resulting in garbled
output. Fix this by using separate C files for the tests.

Signed-off-by: Lukas Fleischer <lfleischer@lfos.de>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2016-01-10 17:36:34 +01:00
22 changed files with 97 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Files: Files:
* *

13
README
View File

@@ -9,7 +9,7 @@ code over and over again on each project.
Releases Releases
-------- --------
<http://libbsd.freedesktop.org/releases/> <https://libbsd.freedesktop.org/releases/>
Mailing List Mailing List
@@ -17,7 +17,7 @@ Mailing List
The subscription interface and web archives can be found at: The subscription interface and web archives can be found at:
<http://lists.freedesktop.org/mailman/listinfo/libbsd> <https://lists.freedesktop.org/mailman/listinfo/libbsd>
The mail address is: The mail address is:
@@ -27,5 +27,10 @@ The mail address is:
Source Repository Source Repository
----------------- -----------------
<http://cgit.freedesktop.org/libbsd> The master repository can be browsed at:
<git://anongit.freedesktop.org/git/libbsd>
<https://cgit.freedesktop.org/libbsd>
and cloned from:
<https://anongit.freedesktop.org/git/libbsd>

View File

@@ -13,7 +13,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
LIBBSD_ABI_MAJOR=0 LIBBSD_ABI_MAJOR=0
LIBBSD_ABI_MINOR=8 LIBBSD_ABI_MINOR=8
LIBBSD_ABI_PATCH=1 LIBBSD_ABI_PATCH=3
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH" LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
AC_SUBST([LIBBSD_ABI]) AC_SUBST([LIBBSD_ABI])
@@ -44,6 +44,16 @@ AC_SUBST([TESTU01_LIBS])
AM_CONDITIONAL([HAVE_LIBTESTU01], AM_CONDITIONAL([HAVE_LIBTESTU01],
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"]) [test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
# In old glibc versions (< 2.17) clock_gettime() is in librt.
AS_CASE([$host_os],
[*-gnu], [
saved_LIBS="$LIBS"
AC_SEARCH_LIBS([clock_gettime], [rt], [CLOCK_GETTIME_LIBS="-lrt"])
AC_SUBST([CLOCK_GETTIME_LIBS])
LIBS="$saved_LIBS"
]
)
# Checks for header files. # Checks for header files.
AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h]) AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h])

View File

@@ -1059,7 +1059,7 @@ However, unlike their unsafe counterparts,
.Nm TAILQ_FOREACH .Nm TAILQ_FOREACH
and and
.Nm TAILQ_FOREACH_REVERSE .Nm TAILQ_FOREACH_REVERSE
permit to both remove make it possible to both remove
.Fa var .Fa var
as well as free it from within the loop safely without interfering with the as well as free it from within the loop safely without interfering with the
traversal. traversal.

View File

@@ -52,6 +52,8 @@ hash/md5hl.c: $(srcdir)/hash/helper.c
libbsd_la_DEPENDENCIES = \ libbsd_la_DEPENDENCIES = \
$(libbsd_la_included_sources) \ $(libbsd_la_included_sources) \
libbsd.map libbsd.map
libbsd_la_LIBADD = \
$(CLOCK_GETTIME_LIBS)
libbsd_la_LDFLAGS = \ libbsd_la_LDFLAGS = \
-Wl,--version-script=$(srcdir)/libbsd.map \ -Wl,--version-script=$(srcdir)/libbsd.map \
-version-number $(LIBBSD_ABI) -version-number $(LIBBSD_ABI)

View File

@@ -60,7 +60,7 @@ fgetwln(FILE *stream, size_t *lenp)
fb->fp = stream; fb->fp = stream;
while ((wc = fgetwc(stream)) != WEOF) { while ((wc = fgetwc(stream)) != WEOF) {
if (!fb->len || wused > fb->len) { if (!fb->len || wused >= fb->len) {
wchar_t *wp; wchar_t *wp;
if (fb->len) if (fb->len)

View File

@@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h>
#include <stdarg.h> #include <stdarg.h>
#include <unistd.h> #include <unistd.h>
#include <libutil.h> #include <libutil.h>

View File

@@ -67,8 +67,10 @@ HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
} }
len = sb.st_size; len = sb.st_size;
} }
if ((len < 0) || (off > 0 && lseek(fd, off, SEEK_SET) < 0)) if ((len < 0) || (off > 0 && lseek(fd, off, SEEK_SET) < 0)) {
close(fd);
return (NULL); return (NULL);
}
while ((nr = read(fd, buffer, while ((nr = read(fd, buffer,
(size_t)(len ? MIN(BUFSIZ, len) : BUFSIZ))) > 0) { (size_t)(len ? MIN(BUFSIZ, len) : BUFSIZ))) > 0) {

View File

@@ -6,7 +6,7 @@ includedir=@includedir@
Name: libbsd-ctor Name: libbsd-ctor
Description: Automatic constructor functions for libbsd Description: Automatic constructor functions for libbsd
Version: @VERSION@ Version: @VERSION@
URL: http://libbsd.freedesktop.org/ URL: https://libbsd.freedesktop.org/
Cflags: -I${includedir} Cflags: -I${includedir}
Libs: -L${libdir} -Wl,-z,nodlopen -Wl,-u,libbsd_init_func -lbsd-ctor Libs: -L${libdir} -Wl,-z,nodlopen -Wl,-u,libbsd_init_func -lbsd-ctor
Requires: libbsd Requires: libbsd

View File

@@ -6,6 +6,6 @@ includedir=@includedir@
Name: libbsd Name: libbsd
Description: Utility functions from BSD systems (overlay) Description: Utility functions from BSD systems (overlay)
Version: @VERSION@ Version: @VERSION@
URL: http://libbsd.freedesktop.org/ URL: https://libbsd.freedesktop.org/
Libs: -L${libdir} -lbsd Libs: -L${libdir} -lbsd
Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY Cflags: -isystem ${includedir}/bsd -DLIBBSD_OVERLAY

View File

@@ -6,6 +6,6 @@ includedir=@includedir@
Name: libbsd Name: libbsd
Description: Utility functions from BSD systems Description: Utility functions from BSD systems
Version: @VERSION@ Version: @VERSION@
URL: http://libbsd.freedesktop.org/ URL: https://libbsd.freedesktop.org/
Libs: -L${libdir} -lbsd Libs: -L${libdir} -lbsd
Cflags: -I${includedir} Cflags: -I${includedir}

View File

@@ -39,6 +39,7 @@ static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93";
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h>
#include <a.out.h> #include <a.out.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

View File

@@ -25,9 +25,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* /*
Rejected in glibc (http://sourceware.org/ml/libc-alpha/2006-03/msg00125.html) * Rejected in glibc
*/ * <https://sourceware.org/ml/libc-alpha/2006-03/msg00125.html>.
*/
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>

View File

@@ -118,7 +118,7 @@ sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
if (n < THRESHOLD) if (n < THRESHOLD)
simplesort(a, n, 0, tr, endch); simplesort(a, n, 0, tr, endch);
else { else {
ta = reallocarray(NULL, n, sizeof(a)); ta = reallocarray(NULL, n, sizeof(*a));
if (ta == NULL) if (ta == NULL)
return (-1); return (-1);
r_sort_b(a, ta, n, 0, tr, endch); r_sort_b(a, ta, n, 0, tr, endch);

View File

@@ -56,7 +56,7 @@ spt_min(size_t a, size_t b)
/* /*
* For discussion on the portability of the various methods, see * For discussion on the portability of the various methods, see
* http://lists.freebsd.org/pipermail/freebsd-stable/2008-June/043136.html * https://lists.freebsd.org/pipermail/freebsd-stable/2008-June/043136.html
*/ */
static int static int
spt_clearenv(void) spt_clearenv(void)

1
test/.gitignore vendored
View File

@@ -8,6 +8,7 @@ fparseln
fpurge fpurge
headers-gen.c headers-gen.c
humanize humanize
md5
overlay overlay
proctitle-init proctitle-init
proctitle proctitle

View File

@@ -39,6 +39,7 @@ check_PROGRAMS = \
funopen \ funopen \
fparseln \ fparseln \
fpurge \ fpurge \
md5 \
proctitle-init \ proctitle-init \
strmode \ strmode \
$(nil) $(nil)

View File

@@ -99,6 +99,8 @@ main(int argc, char **argv)
/* XXX: We should probably FAIL the test, but we currently /* XXX: We should probably FAIL the test, but we currently
* have one test always failing. */ * have one test always failing. */
rc = TEST_SKIP; rc = TEST_SKIP;
} else {
rc = TEST_OK;
} }
return rc; return rc;

View File

@@ -12,14 +12,14 @@ incdir="${top_srcdir}/include/bsd"
CPPFLAGS="$CPPFLAGS -DLIBBSD_OVERLAY" CPPFLAGS="$CPPFLAGS -DLIBBSD_OVERLAY"
for inc in $(cd $incdir; find -name '*.h' | sort | cut -c3-); do for inc in $(cd $incdir; find -name '*.h' | sort | cut -c3-); do
cat >headers-gen.c <<SOURCE cat >headers-overlay-gen.c <<SOURCE
#include <$inc> #include <$inc>
int main() { return 0; } int main() { return 0; }
SOURCE SOURCE
echo "testing header $inc" echo "testing header $inc"
run $CC -isystem "$incdir" $CPPFLAGS headers-gen.c -o /dev/null run $CC -isystem "$incdir" $CPPFLAGS headers-overlay-gen.c -o /dev/null
echo echo
rm -f headers-gen* rm -f headers-overlay-gen*
done done

View File

@@ -11,14 +11,14 @@ run()
incdir="${top_srcdir}/include" incdir="${top_srcdir}/include"
for inc in $(cd $incdir; find -name '*.h' | sort | cut -c3-); do for inc in $(cd $incdir; find -name '*.h' | sort | cut -c3-); do
cat >headers-gen.c <<SOURCE cat >headers-system-gen.c <<SOURCE
#include <$inc> #include <$inc>
int main() { return 0; } int main() { return 0; }
SOURCE SOURCE
echo "testing header $inc" echo "testing header $inc"
run $CC -isystem "$incdir" $CPPFLAGS headers-gen.c -o /dev/null run $CC -isystem "$incdir" $CPPFLAGS headers-system-gen.c -o /dev/null
echo echo
rm -f headers-gen.* rm -f headers-system-gen.*
done done

47
test/md5.c Normal file
View File

@@ -0,0 +1,47 @@
/*
* Copyright © 2016 Guillem Jover <guillem@hadrons.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <assert.h>
#include <md5.h>
#include <string.h>
void
test_md5(const char *digest, const char *string)
{
char result[MD5_DIGEST_STRING_LENGTH];
assert(strcmp(digest, MD5Data((uint8_t *)string, strlen(string), result)) == 0);
}
int
main()
{
test_md5("d41d8cd98f00b204e9800998ecf8427e", "");
test_md5("900150983cd24fb0d6963f7d28e17f72", "abc");
test_md5("827ccb0eea8a706c4c34a16891f84e7b", "12345");
return 0;
}

View File

@@ -24,6 +24,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <sys/stat.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>