diff options
| author | Philip Paeps <philip@FreeBSD.org> | 2025-04-02 08:56:02 +0000 |
|---|---|---|
| committer | Philip Paeps <philip@FreeBSD.org> | 2025-04-10 14:39:08 +0000 |
| commit | dec0bf8096b312c395421d11c0e76e954a7e2386 (patch) | |
| tree | ed02999689df196c5d5ed3fdd898b035184b18f6 /contrib/expat/tests/benchmark | |
| parent | 74aa5e2a7b1023d4fd7e54dcbb8084efe5249d2d (diff) | |
contrib/expat: update libexpat from 2.6.4 to 2.7.1
Changes: https://github.com/libexpat/libexpat/blob/R_2_7_1/expat/Changes
Note that libbsdxml(3) is only intended to used by utilities in the
FreeBSD base system. The vulnerability addressed by expat 2.7.0 is not
exploitable on FreeBSD as supported by the security-officer@ team.
Approved by: so
Security: FreeBSD-EN-25:05.expat
Security: CVE-2024-8176
(cherry picked from commit fe9278888fd4414abe2d922e469cf608005f4c65)
(cherry picked from commit 41b768ae1970ed484abaaea401453c3902df93c2)
(cherry picked from commit 03a1992591b0ae85b6b250255fe56e17f6d919c6)
(cherry picked from commit adc9e9e8dbddcf7d57bcdef0d9d0a0e7c08c15ba)
(cherry picked from commit 00c8538e87c61f1fd57ccd9e02a6d435b68d9a73)
(cherry picked from commit 5630672e6f6d58597a3d6f01928a7703f1cdd207)
Diffstat (limited to 'contrib/expat/tests/benchmark')
| -rw-r--r-- | contrib/expat/tests/benchmark/benchmark.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/contrib/expat/tests/benchmark/benchmark.c b/contrib/expat/tests/benchmark/benchmark.c index 355d83f896de..a02b84a0131d 100644 --- a/contrib/expat/tests/benchmark/benchmark.c +++ b/contrib/expat/tests/benchmark/benchmark.c @@ -8,7 +8,7 @@ Copyright (c) 2003-2006 Karl Waclawek <karl@waclawek.net> Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> - Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2025 Sebastian Pipping <sebastian@pipping.org> Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> Licensed under the MIT license: @@ -32,10 +32,18 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#define _POSIX_C_SOURCE 1 // fdopen + +#if defined(_MSC_VER) +# include <io.h> // _open, _close +#else +# include <unistd.h> // close +#endif + +#include <fcntl.h> // open #include <sys/stat.h> #include <assert.h> #include <stddef.h> // ptrdiff_t -#include <stdlib.h> #include <stdio.h> #include <time.h> #include "expat.h" @@ -52,17 +60,18 @@ # define XML_FMT_STR "s" #endif -static void +static int usage(const char *prog, int rc) { fprintf(stderr, "usage: %s [-n] filename bufferSize nr_of_loops\n", prog); - exit(rc); + return rc; } int main(int argc, char *argv[]) { XML_Parser parser; char *XMLBuf, *XMLBufEnd, *XMLBufPtr; - FILE *fd; + int fd; + FILE *file; struct stat fileAttr; int nrOfLoops, bufferSize, i, isFinal; size_t fileSize; @@ -76,34 +85,48 @@ main(int argc, char *argv[]) { ns = 1; j = 1; } else - usage(argv[0], 1); + return usage(argv[0], 1); } } if (argc != j + 4) - usage(argv[0], 1); + return usage(argv[0], 1); - if (stat(argv[j + 1], &fileAttr) != 0) { - fprintf(stderr, "could not access file '%s'\n", argv[j + 1]); + fd = open(argv[j + 1], O_RDONLY); + if (fd == -1) { + fprintf(stderr, "could not open file '%s'\n", argv[j + 1]); return 2; } - fd = fopen(argv[j + 1], "r"); - if (! fd) { - fprintf(stderr, "could not open file '%s'\n", argv[j + 1]); - exit(2); + if (fstat(fd, &fileAttr) != 0) { + close(fd); + fprintf(stderr, "could not fstat file '%s'\n", argv[j + 1]); + return 2; + } + + file = fdopen(fd, "r"); + if (! file) { + close(fd); + fprintf(stderr, "could not fdopen file '%s'\n", argv[j + 1]); + return 2; } bufferSize = atoi(argv[j + 2]); nrOfLoops = atoi(argv[j + 3]); if (bufferSize <= 0 || nrOfLoops <= 0) { + fclose(file); // NOTE: this closes fd as well fprintf(stderr, "buffer size and nr of loops must be greater than zero.\n"); - exit(3); + return 3; } XMLBuf = malloc(fileAttr.st_size); - fileSize = fread(XMLBuf, sizeof(char), fileAttr.st_size, fd); - fclose(fd); + if (XMLBuf == NULL) { + fclose(file); // NOTE: this closes fd as well + fprintf(stderr, "ouf of memory.\n"); + return 5; + } + fileSize = fread(XMLBuf, sizeof(char), fileAttr.st_size, file); + fclose(file); // NOTE: this closes fd as well if (ns) parser = XML_ParserCreateNS(NULL, '!'); @@ -132,7 +155,7 @@ main(int argc, char *argv[]) { XML_GetCurrentColumnNumber(parser)); free(XMLBuf); XML_ParserFree(parser); - exit(4); + return 4; } XMLBufPtr += bufferSize; } while (! isFinal); |
