diff options
author | Simon Josefsson <simon@josefsson.org> | 2004-10-05 19:23:32 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2004-10-05 19:23:32 +0000 |
commit | 44f36671ed0ea24b60afdf8a033faf3d258a24c3 (patch) | |
tree | e69dca84aa9ed595fc218bb536091f2112b875f9 | |
parent | c959c9d135876d62dc00f743c27f23cb4b30f74c (diff) | |
download | gnutls-44f36671ed0ea24b60afdf8a033faf3d258a24c3.tar.gz |
Update Gnulib.
Replace memstr with memmem, see continued discussion on bug-gnulib.
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | gl/Makefile.am | 7 | ||||
-rw-r--r-- | gl/error.c | 2 | ||||
-rw-r--r-- | gl/getndelim2.c | 4 | ||||
-rw-r--r-- | gl/getpass.c | 4 | ||||
-rw-r--r-- | gl/m4/gnulib.m4 | 7 | ||||
-rw-r--r-- | gl/m4/memmem.m4 (renamed from gl/m4/memstr.m4) | 17 | ||||
-rw-r--r-- | gl/memmem.c | 57 | ||||
-rw-r--r-- | gl/memmem.h (renamed from gl/memstr.h) | 14 | ||||
-rw-r--r-- | gl/memstr.c | 50 | ||||
-rw-r--r-- | gl/unlocked-io.h | 132 | ||||
-rw-r--r-- | lib/defines.h | 2 | ||||
-rw-r--r-- | lib/gnutls_x509.c | 31 | ||||
-rw-r--r-- | lib/x509_b64.c | 8 |
14 files changed, 110 insertions, 227 deletions
diff --git a/configure.in b/configure.in index 3749af47f1..35c1be848f 100644 --- a/configure.in +++ b/configure.in @@ -466,7 +466,7 @@ AC_MSG_RESULT([*** gl_SOURCE_BASE(gl) gl_M4_BASE(gl/m4) -gl_MODULES(getline error exit progname getpass-gnu minmax memstr) +gl_MODULES(getline error exit progname getpass-gnu minmax memmem) gl_INIT AC_MSG_RESULT([*** diff --git a/gl/Makefile.am b/gl/Makefile.am index 98d95bdab7..799395915e 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -10,7 +10,7 @@ # Generated by gnulib-tool. # # Invoked as: gnulib-tool --import -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool error exit extensions getline getpass-gnu gettext memstr minmax progname stdbool unlocked-io +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool error exit getline getpass-gnu gettext memmem minmax progname stdbool AUTOMAKE_OPTIONS = 1.8 gnits @@ -28,7 +28,6 @@ MAINTAINERCLEANFILES = libgnu_la_SOURCES += exit.h - libgnu_la_SOURCES += getline.h EXTRA_DIST += getndelim2.h getndelim2.c @@ -36,7 +35,7 @@ libgnu_la_SOURCES += getpass.h libgnu_la_SOURCES += gettext.h -libgnu_la_SOURCES += memstr.h +libgnu_la_SOURCES += memmem.h libgnu_la_SOURCES += minmax.h @@ -53,7 +52,5 @@ stdbool.h: stdbool_.h mv $@-t $@ MOSTLYCLEANFILES += stdbool.h stdbool.h-t -libgnu_la_SOURCES += unlocked-io.h - # Makefile.am ends here diff --git a/gl/error.c b/gl/error.c index 5a5e126b0d..9bb3e558cb 100644 --- a/gl/error.c +++ b/gl/error.c @@ -40,7 +40,7 @@ # define mbsrtowcs __mbsrtowcs #endif -#if !_LIBC +#if USE_UNLOCKED_IO # include "unlocked-io.h" #endif diff --git a/gl/getndelim2.c b/gl/getndelim2.c index 9571e50a8f..aef97807a1 100644 --- a/gl/getndelim2.c +++ b/gl/getndelim2.c @@ -29,7 +29,9 @@ #include <stdlib.h> #include <stddef.h> -#include "unlocked-io.h" +#if USE_UNLOCKED_IO +# include "unlocked-io.h" +#endif #include <limits.h> #if HAVE_INTTYPES_H diff --git a/gl/getpass.c b/gl/getpass.c index 9ac01f2277..bc8eb4498d 100644 --- a/gl/getpass.c +++ b/gl/getpass.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2001, 2003 Free Software Foundation, Inc. +/* Copyright (C) 1992-2001, 2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -55,7 +55,7 @@ #if _LIBC # define flockfile(s) _IO_flockfile (s) # define funlockfile(s) _IO_funlockfile (s) -#else +#elif USE_UNLOCKED_IO # include "unlocked-io.h" #endif diff --git a/gl/m4/gnulib.m4 b/gl/m4/gnulib.m4 index 04f0ac84d9..ad4c5ebef3 100644 --- a/gl/m4/gnulib.m4 +++ b/gl/m4/gnulib.m4 @@ -8,24 +8,21 @@ # Generated by gnulib-tool. # # Invoked as: gnulib-tool --import -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool error exit extensions getline getpass-gnu gettext memstr minmax progname stdbool unlocked-io +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool error exit getline getpass-gnu gettext memmem minmax progname stdbool AC_DEFUN([gl_EARLY], [ AC_GNU_SOURCE - gl_USE_SYSTEM_EXTENSIONS ]) AC_DEFUN([gl_INIT], [ gl_ERROR - dnl gl_USE_SYSTEM_EXTENSIONS must be added quite early to configure.ac. AM_FUNC_GETLINE gl_FUNC_GETPASS_GNU dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. - gl_FUNC_MEMSTR + gl_FUNC_MEMMEM AM_STDBOOL_H - gl_FUNC_GLIBC_UNLOCKED_IO ]) dnl Usage: gl_MODULES(module1 module2 ...) diff --git a/gl/m4/memstr.m4 b/gl/m4/memmem.m4 index 43414d9ed6..2e4a20bc3c 100644 --- a/gl/m4/memstr.m4 +++ b/gl/m4/memmem.m4 @@ -1,4 +1,4 @@ -# memstr.m4 serial 1 +# memmem.m4 serial 1 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General @@ -6,12 +6,15 @@ dnl Public License, this file may be distributed as part of a program dnl that contains a configuration script generated by Autoconf, under dnl the same distribution terms as the rest of that program. -AC_DEFUN([gl_FUNC_MEMSTR], +AC_DEFUN([gl_FUNC_MEMMEM], [ - AC_REPLACE_FUNCS(memstr) - AC_CHECK_DECLS_ONCE(memstr) - gl_PREREQ_MEMSTR + dnl Persuade glibc <string.h> to declare memmem(). + AC_REQUIRE([AC_GNU_SOURCE]) + + AC_REPLACE_FUNCS(memmem) + AC_CHECK_DECLS_ONCE(memmem) + gl_PREREQ_MEMMEM ]) -# Prerequisites of lib/memstr.c. -AC_DEFUN([gl_PREREQ_MEMSTR], [:]) +# Prerequisites of lib/memmem.c. +AC_DEFUN([gl_PREREQ_MEMMEM], [:]) diff --git a/gl/memmem.c b/gl/memmem.c new file mode 100644 index 0000000000..04e384cf1d --- /dev/null +++ b/gl/memmem.c @@ -0,0 +1,57 @@ +/* Copyright (C) 1991,92,93,94,96,97,98,2000,2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include <stddef.h> +#include <string.h> + +#ifndef _LIBC +# define __builtin_expect(expr, val) (expr) +#endif + +#undef memmem + +/* Return the first occurrence of NEEDLE in HAYSTACK. */ +void * +memmem (haystack, haystack_len, needle, needle_len) + const void *haystack; + size_t haystack_len; + const void *needle; + size_t needle_len; +{ + const char *begin; + const char *const last_possible + = (const char *) haystack + haystack_len - needle_len; + + if (needle_len == 0) + /* The first occurrence of the empty string is deemed to occur at + the beginning of the string. */ + return (void *) haystack; + + /* Sanity check, otherwise the loop might search through the whole + memory. */ + if (__builtin_expect (haystack_len < needle_len, 0)) + return NULL; + + for (begin = (const char *) haystack; begin <= last_possible; ++begin) + if (begin[0] == ((const char *) needle)[0] && + !memcmp ((const void *) &begin[1], + (const void *) ((const char *) needle + 1), + needle_len - 1)) + return (void *) begin; + + return NULL; +} diff --git a/gl/memstr.h b/gl/memmem.h index 519036ec05..47dcbd8363 100644 --- a/gl/memstr.h +++ b/gl/memmem.h @@ -17,14 +17,16 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ -#ifndef MEMSTR_H -# define MEMSTR_H +#ifndef MEMMEM_H +# define MEMMEM_H -/* Get memstr, if available. */ +/* Get memmem, if available. */ # include <string.h> -# if defined HAVE_DECL_MEMSTR && !HAVE_DECL_MEMSTR -char *memstr (const char *big, const char *little, size_t len); +# if defined HAVE_DECL_MEMMEM && !HAVE_DECL_MEMMEM +void * +memmem (const void *haystack, size_t haystack_len, + const void *needle, size_t needle_len); # endif -#endif /* MEMSTR_H */ +#endif /* MEMMEM_H */ diff --git a/gl/memstr.c b/gl/memstr.c deleted file mode 100644 index 489e38d8d5..0000000000 --- a/gl/memstr.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2004 Free Software Foundation - * Written by Simon Josefsson - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -/* Get strlen, strncmp, size_t. */ -#include <string.h> - -/* Locate first occurance of zero terminated string LITTLE in the - first LEN characters of the string BIG. The terminating zero in - LITTLE is not used for comparison. Return pointer to match within - BIG, or NULL if no match is found. If LITTLE is the empty string, - BIG is returned. */ -char * -memstr (const char *big, const char *little, size_t len) -{ - size_t littlelen = strlen (little); - char *p = (char*) big; - size_t i; - - if (*little == '\0') - return p; - - if (len < littlelen) - return NULL; - - for (i = 0; i <= len - littlelen; i++) - if (memcmp (&p[i], little, littlelen) == 0) - return &p[i]; - - return NULL; -} diff --git a/gl/unlocked-io.h b/gl/unlocked-io.h deleted file mode 100644 index 36a7a4885d..0000000000 --- a/gl/unlocked-io.h +++ /dev/null @@ -1,132 +0,0 @@ -/* Prefer faster, non-thread-safe stdio functions if available. - - Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* Written by Jim Meyering. */ - -#ifndef UNLOCKED_IO_H -# define UNLOCKED_IO_H 1 - -# ifndef USE_UNLOCKED_IO -# define USE_UNLOCKED_IO 1 -# endif - -# if USE_UNLOCKED_IO - -/* These are wrappers for functions/macros from the GNU C library, and - from other C libraries supporting POSIX's optional thread-safe functions. - - The standard I/O functions are thread-safe. These *_unlocked ones are - more efficient but not thread-safe. That they're not thread-safe is - fine since all of the applications in this package are single threaded. - - Also, some code that is shared with the GNU C library may invoke - the *_unlocked functions directly. On hosts that lack those - functions, invoke the non-thread-safe versions instead. */ - -# include <stdio.h> - -# if HAVE_DECL_CLEARERR_UNLOCKED -# undef clearerr -# define clearerr(x) clearerr_unlocked (x) -# else -# define clearerr_unlocked(x) clearerr (x) -# endif -# if HAVE_DECL_FEOF_UNLOCKED -# undef feof -# define feof(x) feof_unlocked (x) -# else -# define feof_unlocked(x) feof (x) -# endif -# if HAVE_DECL_FERROR_UNLOCKED -# undef ferror -# define ferror(x) ferror_unlocked (x) -# else -# define ferror_unlocked(x) ferror (x) -# endif -# if HAVE_DECL_FFLUSH_UNLOCKED -# undef fflush -# define fflush(x) fflush_unlocked (x) -# else -# define fflush_unlocked(x) fflush (x) -# endif -# if HAVE_DECL_FGETS_UNLOCKED -# undef fgets -# define fgets(x,y,z) fgets_unlocked (x,y,z) -# else -# define fgets_unlocked(x,y,z) fgets (x,y,z) -# endif -# if HAVE_DECL_FPUTC_UNLOCKED -# undef fputc -# define fputc(x,y) fputc_unlocked (x,y) -# else -# define fputc_unlocked(x,y) fputc (x,y) -# endif -# if HAVE_DECL_FPUTS_UNLOCKED -# undef fputs -# define fputs(x,y) fputs_unlocked (x,y) -# else -# define fputs_unlocked(x,y) fputs (x,y) -# endif -# if HAVE_DECL_FREAD_UNLOCKED -# undef fread -# define fread(w,x,y,z) fread_unlocked (w,x,y,z) -# else -# define fread_unlocked(w,x,y,z) fread (w,x,y,z) -# endif -# if HAVE_DECL_FWRITE_UNLOCKED -# undef fwrite -# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z) -# else -# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) -# endif -# if HAVE_DECL_GETC_UNLOCKED -# undef getc -# define getc(x) getc_unlocked (x) -# else -# define getc_unlocked(x) getc (x) -# endif -# if HAVE_DECL_GETCHAR_UNLOCKED -# undef getchar -# define getchar() getchar_unlocked () -# else -# define getchar_unlocked() getchar () -# endif -# if HAVE_DECL_PUTC_UNLOCKED -# undef putc -# define putc(x,y) putc_unlocked (x,y) -# else -# define putc_unlocked(x,y) putc (x,y) -# endif -# if HAVE_DECL_PUTCHAR_UNLOCKED -# undef putchar -# define putchar(x) putchar_unlocked (x) -# else -# define putchar_unlocked(x) putchar (x) -# endif - -# undef flockfile -# define flockfile(x) ((void) 0) - -# undef ftrylockfile -# define ftrylockfile(x) 0 - -# undef funlockfile -# define funlockfile(x) ((void) 0) - -# endif /* USE_UNLOCKED_IO */ -#endif /* UNLOCKED_IO_H */ diff --git a/lib/defines.h b/lib/defines.h index 267fe43cf2..5773b12ab1 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -40,7 +40,7 @@ typedef int ssize_t; # include <strings.h> #endif -#include <memstr.h> +#include <memmem.h> #ifdef HAVE_STDDEF_H # include <stddef.h> diff --git a/lib/gnutls_x509.c b/lib/gnutls_x509.c index e5dc7e5229..f5d59e2958 100644 --- a/lib/gnutls_x509.c +++ b/lib/gnutls_x509.c @@ -438,8 +438,8 @@ static int parse_pem_cert_mem(gnutls_cert ** cert_list, uint * ncerts, int ret, count; #ifdef ENABLE_PKI - if ((ptr = - memstr(input_cert, PEM_PKCS7_SEP, input_cert_size)) != NULL) { + if ((ptr = memmem(input_cert, input_cert_size, + PEM_PKCS7_SEP, sizeof (PEM_PKCS7_SEP) - 1)) != NULL) { size = strlen(ptr); ret = parse_pkcs7_cert_mem(cert_list, ncerts, ptr, size, CERT_PEM); @@ -450,9 +450,11 @@ static int parse_pem_cert_mem(gnutls_cert ** cert_list, uint * ncerts, /* move to the certificate */ - ptr = memstr(input_cert, PEM_CERT_SEP, input_cert_size); + ptr = memmem(input_cert, input_cert_size, + PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1); if (ptr == NULL) - ptr = memstr(input_cert, PEM_CERT_SEP2, input_cert_size); + ptr = memmem(input_cert, input_cert_size, + PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1); if (ptr == NULL) { gnutls_assert(); @@ -502,9 +504,10 @@ static int parse_pem_cert_mem(gnutls_cert ** cert_list, uint * ncerts, if (size > 0) { char *ptr2; - ptr2 = memstr(ptr, PEM_CERT_SEP, size); + ptr2 = memmem(ptr, size, PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1); if (ptr2 == NULL) - ptr2 = memstr(ptr, PEM_CERT_SEP2, size); + ptr2 = memmem(ptr, size, PEM_CERT_SEP2, + sizeof (PEM_CERT_SEP2) - 1); ptr = ptr2; } else @@ -1123,9 +1126,11 @@ static int parse_pem_ca_mem(gnutls_x509_crt_t ** cert_list, uint * ncerts, /* move to the certificate */ - ptr = memstr(input_cert, PEM_CERT_SEP, input_cert_size); + ptr = memmem(input_cert, input_cert_size, + PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1); if (ptr == NULL) - ptr = memstr(input_cert, PEM_CERT_SEP2, input_cert_size); + ptr = memmem(input_cert, input_cert_size, + PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1); if (ptr == NULL) { gnutls_assert(); @@ -1177,9 +1182,10 @@ static int parse_pem_ca_mem(gnutls_x509_crt_t ** cert_list, uint * ncerts, if (size > 0) { char *ptr2; - ptr2 = memstr(ptr, PEM_CERT_SEP, size); + ptr2 = memmem(ptr, size, PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1); if (ptr2 == NULL) - ptr = memstr(ptr, PEM_CERT_SEP2, size); + ptr = memmem(ptr, size, + PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1); ptr = ptr2; } else @@ -1395,7 +1401,8 @@ static int parse_pem_crl_mem(gnutls_x509_crl_t ** crl_list, uint * ncrls, /* move to the certificate */ - ptr = memstr(input_crl, PEM_CRL_SEP, input_crl_size); + ptr = memmem(input_crl, input_crl_size, + PEM_CRL_SEP, sizeof (PEM_CRL_SEP) -1); if (ptr == NULL) { gnutls_assert(); return GNUTLS_E_BASE64_DECODING_ERROR; @@ -1445,7 +1452,7 @@ static int parse_pem_crl_mem(gnutls_x509_crl_t ** crl_list, uint * ncrls, size = input_crl_size - (ptr - input_crl); if (size > 0) - ptr = memstr(ptr, PEM_CRL_SEP, size); + ptr = memmem(ptr, size, PEM_CRL_SEP, sizeof (PEM_CRL_SEP) - 1); else ptr = NULL; i++; diff --git a/lib/x509_b64.c b/lib/x509_b64.c index 3a5f06140f..2c20602391 100644 --- a/lib/x509_b64.c +++ b/lib/x509_b64.c @@ -413,7 +413,7 @@ int _gnutls_fbase64_decode(const char *header, const opaque * data, if (header != NULL) _gnutls_str_cat(pem_header, sizeof(pem_header), header); - rdata = memstr(data, pem_header, data_size); + rdata = memmem(data, data_size, pem_header, strlen (pem_header)); if (rdata == NULL) { gnutls_assert(); @@ -428,11 +428,11 @@ int _gnutls_fbase64_decode(const char *header, const opaque * data, return GNUTLS_E_BASE64_DECODING_ERROR; } - kdata = memstr(rdata, ENDSTR, data_size); + kdata = memmem(rdata, data_size, ENDSTR, sizeof (ENDSTR) - 1); /* allow CR as well. */ if (kdata == NULL) - kdata = memstr(rdata, ENDSTR2, data_size); + kdata = memmem(rdata, data_size, ENDSTR2, sizeof (ENDSTR2) - 1); if (kdata == NULL) { gnutls_assert(); @@ -446,7 +446,7 @@ int _gnutls_fbase64_decode(const char *header, const opaque * data, /* position is now after the ---BEGIN--- headers */ - kdata = memstr(rdata, bottom, data_size); + kdata = memmem(rdata, data_size, bottom, strlen (bottom)); if (kdata == NULL) { gnutls_assert(); return GNUTLS_E_BASE64_DECODING_ERROR; |