Added a configure script to emulate GNU autoconf and related changes.
Changes included in this set: * Added strlcat() and strlcpy() from OpenBSD, always use them if the system does not have them built in. * Changed an array of PATH_MAX size allocated in the stack, to a dynamically allocated buffer from heap. This should reduce memory usage a bit. * Simplify code that implemented a homegrown realpath(3) implementation, simply use realpath(3). * If compiler supports -fstack-protector, build all code with -D_FORTIFY_SOURCE=2 and --param ssp-buffer-size=1 so that all buffers are protected.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
include ../vars.mk
|
||||
-include ../config.mk
|
||||
|
||||
LIBXBPS_MAJOR = 0
|
||||
LIBXBPS_MINOR = 0
|
||||
@@ -15,7 +15,7 @@ LIBPROP_OBJS += portableproplib/prop_stack.o portableproplib/prop_string.o
|
||||
LIBPROP_OBJS += portableproplib/prop_array_util.o portableproplib/prop_number.o
|
||||
LIBPROP_OBJS += portableproplib/prop_dictionary_util.o
|
||||
LIBPROP_OBJS += portableproplib/prop_data.o
|
||||
LIBPROP_CFLAGS = -Wno-cast-qual -Wno-unused-parameter -Wno-stack-protector
|
||||
LIBPROP_CFLAGS = -Wno-cast-qual -Wno-unused-parameter
|
||||
|
||||
ifdef USE_EXTERNAL_PROPLIB
|
||||
LIBPROP_OBJS =
|
||||
@@ -26,7 +26,7 @@ endif
|
||||
LIBFETCH_OBJS = fetch/common.o fetch/fetch.o fetch/file.o
|
||||
LIBFETCH_OBJS += fetch/ftp.o fetch/http.o
|
||||
LIBFETCH_CPPFLAGS = -DFTP_COMBINE_CWDS -DNETBSD -DINET6 -DWITH_SSL
|
||||
LIBFETCH_CFLAGS = -Wno-unused-macros -Wno-conversion -Wno-stack-protector
|
||||
LIBFETCH_CFLAGS = -Wno-unused-macros -Wno-conversion
|
||||
LIBFETCH_SHLIBCFLAGS = -fvisibility=hidden
|
||||
LIBFETCH_INCS = fetch/common.h
|
||||
LIBFETCH_GEN = fetch/ftperr.h fetch/httperr.h
|
||||
@@ -38,6 +38,7 @@ OBJS += regpkgs_dictionary.o remove.o remove_obsoletes.o repository.o
|
||||
OBJS += repository_finddeps.o repository_findpkg.o repository_plist.o
|
||||
OBJS += repository_pool.o repository_sync_index.o requiredby.o sha256.o
|
||||
OBJS += sortdeps.o state.o unpack.o util.o pkgmatch.o mkpath.o
|
||||
OBJS += $(COMPAT_SRCS)
|
||||
|
||||
.PHONY: all
|
||||
all: libxbps.so libxbps.a
|
||||
|
57
lib/compat/strlcat.c
Normal file
57
lib/compat/strlcat.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "strlcat.h"
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return(dlen + strlen(s));
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
}
|
53
lib/compat/strlcpy.c
Normal file
53
lib/compat/strlcpy.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "strlcpy.h"
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0) {
|
||||
while (--n != 0) {
|
||||
if ((*d++ = *s++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
@@ -26,6 +26,7 @@
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "config.h"
|
||||
|
||||
/**
|
||||
* @file lib/pkgmatch.c
|
||||
@@ -116,7 +117,8 @@ int
|
||||
xbps_pkgpattern_match(const char *instpkg, char *pattern)
|
||||
{
|
||||
const char *fname = instpkg;
|
||||
char basefname[PATH_MAX], condchar = '\0', *condition;
|
||||
char *basefname, condchar = '\0', *condition;
|
||||
size_t len = 0;
|
||||
int rv = 0;
|
||||
|
||||
memset(&basefname, 0, sizeof(basefname));
|
||||
@@ -134,7 +136,11 @@ xbps_pkgpattern_match(const char *instpkg, char *pattern)
|
||||
*condition = '\0';
|
||||
ch = strrchr(fname, '-');
|
||||
if (ch && ch - fname < PATH_MAX) {
|
||||
strncpy(basefname, fname, ch - fname);
|
||||
len = ch - fname + 1;
|
||||
basefname = malloc(len);
|
||||
if (basefname == NULL)
|
||||
return -1;
|
||||
strlcpy(basefname, fname, len);
|
||||
fname = basefname;
|
||||
}
|
||||
}
|
||||
@@ -177,6 +183,8 @@ xbps_pkgpattern_match(const char *instpkg, char *pattern)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (basefname)
|
||||
free(basefname);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@@ -41,6 +41,10 @@
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* _prop_object_init --
|
||||
* Initialize an object. Called when sub-classes create
|
||||
@@ -812,7 +816,10 @@ _prop_object_externalize_write_file(const char *fname, const char *xml,
|
||||
size_t len, bool do_compress)
|
||||
{
|
||||
gzFile *gzf = NULL;
|
||||
char tname[PATH_MAX], *otname;
|
||||
char tname[PATH_MAX];
|
||||
#ifndef HAVE_STRLCAT
|
||||
char *otname;
|
||||
#endif
|
||||
int fd;
|
||||
int save_errno;
|
||||
mode_t myumask;
|
||||
|
13
lib/util.c
13
lib/util.c
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
||||
* Copyright (c) 2008-2010 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "sha256.h"
|
||||
#include "config.h"
|
||||
|
||||
/**
|
||||
* @file lib/util.c
|
||||
@@ -242,10 +243,11 @@ xbps_get_pkg_name(const char *pkg)
|
||||
return NULL;
|
||||
|
||||
len = strlen(pkg) - strlen(tmp) + 1;
|
||||
|
||||
pkgname = malloc(len);
|
||||
strncpy(pkgname, pkg, len);
|
||||
pkgname[len - 1] = '\0';
|
||||
if (pkgname == NULL)
|
||||
return NULL;
|
||||
|
||||
strlcpy(pkgname, pkg, len);
|
||||
|
||||
return pkgname;
|
||||
}
|
||||
@@ -267,8 +269,7 @@ xbps_get_pkgpattern_name(const char *pkg)
|
||||
if (pkgname == NULL)
|
||||
return NULL;
|
||||
|
||||
strncpy(pkgname, pkg, len);
|
||||
pkgname[len - 1] = '\0';
|
||||
strlcpy(pkgname, pkg, len);
|
||||
|
||||
return pkgname;
|
||||
}
|
||||
|
Reference in New Issue
Block a user