diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2023-11-27 13:06:38 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-11-27 13:06:38 +0100 |
commit | 6e695a47da88f3d26d48db3e676ee34cbaccb905 (patch) | |
tree | 0c6e1dc1a935820c6ba30194238abb1c0d99ae60 /lib | |
parent | 150868bd01a909b85cd588caa6a7727460808888 (diff) | |
parent | 4bab1d86794843e177fa26ab2d85642ea977665c (diff) | |
download | barebox-6e695a47da88f3d26d48db3e676ee34cbaccb905.tar.gz barebox-6e695a47da88f3d26d48db3e676ee34cbaccb905.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/base64.c | 60 | ||||
-rw-r--r-- | lib/fnmatch.c | 45 | ||||
-rw-r--r-- | lib/glob.c | 107 | ||||
-rw-r--r-- | lib/kasan/test_kasan.c | 11 |
5 files changed, 86 insertions, 139 deletions
diff --git a/lib/Makefile b/lib/Makefile index 8817b5f47b..9bb871f94f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -38,7 +38,7 @@ obj-$(CONFIG_CMDLINE_EDITING) += readline.o obj-$(CONFIG_SIMPLE_READLINE) += readline_simple.o obj-$(CONFIG_FNMATCH) += fnmatch.o obj-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o -obj-y += glob.o +obj-$(CONFIG_GLOB) += glob.o obj-y += notifier.o obj-y += random.o obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o diff --git a/lib/base64.c b/lib/base64.c index ac165ab168..d5ab217528 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -25,6 +25,25 @@ static const char uuenc_tbl_base64[65 + 1] = { '\0' /* needed for uudecode.c only */ }; +static char base64_trchr(char ch, bool url) +{ + if (!url) + return ch; + + switch (ch) { + case '+': + return '-'; + case '/': + return '_'; + case '-': + return '+'; + case '_': + return '/'; + default: + return ch; + } +} + /* * Encode bytes at S of length LENGTH to uuencode or base64 format and place it * to STORE. STORE will be 0-terminated, and must point to a writable @@ -68,13 +87,14 @@ EXPORT_SYMBOL(uuencode); * Decode base64 encoded string. Stops on '\0'. * */ -int decode_base64(char *p_dst, int dst_len, const char *src) +static int __decode_base64(char *p_dst, int dst_len, const char *src, bool url) { const char *src_tail; char *dst = p_dst; int length = 0; + bool end_reached = false; - while (dst_len > 0) { + while (dst_len > 0 && !end_reached) { unsigned char six_bit[4]; int count = 0; @@ -101,13 +121,23 @@ int decode_base64(char *p_dst, int dst_len, const char *src) * because we did fully decode * the string (to "ABC"). */ - if (count == 0) + if (count == 0) { src_tail = src; + } else if (url) { + end_reached = true; + goto out; + } + goto ret; } src++; - table_ptr = strchr(uuenc_tbl_base64, ch); - } while (!table_ptr); + table_ptr = strchr(uuenc_tbl_base64, base64_trchr(ch, url)); + } while (!table_ptr && !url); + + if (!table_ptr) { + end_reached = true; + goto out; + } /* Convert encoded character to decimal */ ch = table_ptr - uuenc_tbl_base64; @@ -119,6 +149,7 @@ int decode_base64(char *p_dst, int dst_len, const char *src) six_bit[count] = ch; count++; } +out: /* * Transform 6-bit values to 8-bit ones. @@ -151,4 +182,23 @@ ret: return length; } + +/* + * Decode base64 encoded string. Stops on '\0'. + * + */ +int decode_base64(char *p_dst, int dst_len, const char *src) +{ + return __decode_base64(p_dst, dst_len, src, false); +} EXPORT_SYMBOL(decode_base64); + +/* + * Decode base64url encoded string. Stops on '\0'. + * + */ +int decode_base64url(char *p_dst, int dst_len, const char *src) +{ + return __decode_base64(p_dst, dst_len, src, true); +} +EXPORT_SYMBOL(decode_base64url); diff --git a/lib/fnmatch.c b/lib/fnmatch.c index 0ab530d3b1..ac87ba7621 100644 --- a/lib/fnmatch.c +++ b/lib/fnmatch.c @@ -1,50 +1,11 @@ -/* Copyright (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -This library 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with this library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -/* Enable GNU extensions in fnmatch.h. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif +// SPDX-License-Identifier: LGPL-2.1-or-later +// SPDX-FileCopyrightText: (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc. #include <errno.h> #include <fnmatch.h> #include <linux/ctype.h> - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -# if defined (STDC_HEADERS) || !defined (isascii) -# define ISASCII(c) 1 -# else -# define ISASCII(c) isascii(c) -# endif - -# define ISUPPER(c) (ISASCII (c) && isupper (c)) - - -# ifndef errno -extern int errno; -# endif +# define ISUPPER(c) (isascii(c) && isupper(c)) /* Match STRING against the filename pattern PATTERN, returning zero if it matches, nonzero if not. */ diff --git a/lib/glob.c b/lib/glob.c index 8523bad9a7..389580b0ed 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -1,19 +1,5 @@ -/* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -This library 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with this library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ +// SPDX-License-Identifier: LGPL-2.1-or-later +// SPDX-FileCopyrightText: (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. #include <common.h> #include <errno.h> @@ -23,25 +9,15 @@ Cambridge, MA 02139, USA. */ #include <xfuncs.h> #include <fnmatch.h> #include <qsort.h> -#define _GNU_SOURCE #include <glob.h> -#ifdef CONFIG_GLOB - -extern __ptr_t(*__glob_opendir_hook) __P((const char *directory)); -extern void (*__glob_closedir_hook) __P((__ptr_t stream)); -extern const char *(*__glob_readdir_hook) __P((__ptr_t stream)); - -static int glob_in_dir __P((const char *pattern, const char *directory, +static int glob_in_dir (const char *pattern, const char *directory, int flags, - int (*errfunc) __P((const char *, int)), - glob_t * pglob)); -static int prefix_array __P((const char *prefix, char **array, size_t n, - int add_slash)); - -#ifdef __GLOB64 -extern int glob_pattern_p(const char *pattern, int quote); -#else + int (*errfunc) (const char *, int), + glob_t * pglob); +static int prefix_array (const char *prefix, char **array, size_t n, + int add_slash); + /* Return nonzero if PATTERN contains any metacharacters. Metacharacters can be quoted with backslashes if QUOTE is nonzero. */ int glob_pattern_p(const char *pattern, int quote) @@ -72,7 +48,6 @@ int glob_pattern_p(const char *pattern, int quote) return 0; } -#endif #ifdef CONFIG_GLOB_SORT /* Do a collated comparison of A and B. */ @@ -100,7 +75,7 @@ static int collated_compare(const void *a, const void *b) If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. Otherwise, `glob' returns zero. */ int glob(const char *pattern, int flags, - int (*errfunc) __P((const char *, int)), glob_t *pglob) + int (*errfunc) (const char *, int), glob_t *pglob) { const char *filename; char *dirname = NULL; @@ -169,19 +144,6 @@ int glob(const char *pattern, int flags, for (i = 0; i < dirs.gl_pathc; ++i) { int oldcount1; -#ifdef SHELL - { - /* Make globbing interruptible in the bash shell. */ - extern int interrupt_state; - - if (interrupt_state) { - globfree(&dirs); - globfree(&files); - status = GLOB_ABEND goto out; - } - } -#endif /* SHELL. */ - oldcount1 = pglob->gl_pathc; status = glob_in_dir(filename, dirs.gl_pathv[i], (flags | GLOB_APPEND) & @@ -263,7 +225,7 @@ int glob(const char *pattern, int flags, #ifdef CONFIG_GLOB_SORT if (!(flags & GLOB_NOSORT)) /* Sort the vector. */ - qsort((__ptr_t) & pglob->gl_pathv[oldcount], + qsort(&pglob->gl_pathv[oldcount], pglob->gl_pathc - oldcount, sizeof(char *), collated_compare); #endif @@ -299,7 +261,7 @@ static int prefix_array(const char *dirname, char **array, size_t n, memcpy(new, dirname, dirlen); new[dirlen] = '/'; memcpy(&new[dirlen + 1], array[i], eltlen); - free((__ptr_t) array[i]); + free(array[i]); array[i] = new; } @@ -311,9 +273,9 @@ static int prefix_array(const char *dirname, char **array, size_t n, The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done. The GLOB_APPEND flag is assumed to be set (always appends). */ static int glob_in_dir(const char *pattern, const char *directory, - int flags, int (*errfunc) __P((const char *, int)), glob_t *pglob) + int flags, int (*errfunc) (const char *, int), glob_t *pglob) { - __ptr_t stream = NULL; + void *stream = NULL; struct globlink { struct globlink *next; @@ -356,7 +318,7 @@ static int glob_in_dir(const char *pattern, const char *directory, (struct globlink *)xmalloc(sizeof(struct globlink)); len = strlen(name); new->name = xmalloc(len + ((flags & GLOB_MARK) ? 1 : 0) + 1); - memcpy((__ptr_t) new->name, name, len); + memcpy(new->name, name, len); new->name[len] = '\0'; new->next = names; names = new; @@ -414,44 +376,7 @@ void globfree(glob_t *pglob) int i = pglob->gl_flags & GLOB_DOOFFS ? pglob->gl_offs : 0; for (; i < pglob->gl_pathc; ++i) if (pglob->gl_pathv[i] != NULL) - free((__ptr_t) pglob->gl_pathv[i]); - free((__ptr_t) pglob->gl_pathv); - } -} -#endif /* CONFIG_GLOB */ - -#ifdef CONFIG_FAKE_GLOB -/* Fake version of glob. We simply put the input string into - * the gl_pathv array. Currently we don't need it as hush.c won't - * call us if no glob support is available. - */ -int glob(pattern, flags, errfunc, pglob) -const char *pattern; -int flags; -int (*errfunc) __P((const char *, int)); -glob_t *pglob; -{ - int elems, i; - - if (!(flags & GLOB_APPEND)) { - pglob->gl_pathc = 0; - pglob->gl_pathv = NULL; + free(pglob->gl_pathv[i]); + free(pglob->gl_pathv); } - - elems = pglob->gl_pathc + 2; - if (flags & GLOB_DOOFFS) - elems += pglob->gl_offs; - - pglob->gl_pathv = xrealloc(pglob->gl_pathv, elems * sizeof(char *)); - - if (flags & GLOB_DOOFFS) - for (i = 0; i < pglob->gl_offs; i++) - pglob->gl_pathv[i] = NULL; - - pglob->gl_pathv[pglob->gl_pathc] = strdup(pattern); - pglob->gl_pathc++; - pglob->gl_pathv[pglob->gl_pathc] = NULL; - - return 0; } -#endif /* CONFIG_FAKE_GLOB */ diff --git a/lib/kasan/test_kasan.c b/lib/kasan/test_kasan.c index 14511cdb80..a74251a6d9 100644 --- a/lib/kasan/test_kasan.c +++ b/lib/kasan/test_kasan.c @@ -38,6 +38,8 @@ static noinline void malloc_oob_right(void) return; } + OPTIMIZER_HIDE_VAR(ptr); + ptr[size] = 'x'; free(ptr); @@ -55,6 +57,8 @@ static noinline void malloc_oob_left(void) return; } + OPTIMIZER_HIDE_VAR(ptr); + *ptr = *(ptr - 1); free(ptr); } @@ -75,6 +79,8 @@ static noinline void malloc_oob_realloc_more(void) return; } + OPTIMIZER_HIDE_VAR(ptr2); + ptr2[size2] = 'x'; free(ptr2); @@ -95,6 +101,8 @@ static noinline void malloc_oob_realloc_less(void) return; } + OPTIMIZER_HIDE_VAR(ptr2); + ptr2[size2] = 'x'; free(ptr2); @@ -115,6 +123,9 @@ static noinline void malloc_oob_16(void) free(ptr2); return; } + + OPTIMIZER_HIDE_VAR(ptr1); + *ptr1 = *ptr2; free(ptr1); free(ptr2); |