mirror of
https://github.com/curl/curl.git
synced 2026-04-14 21:41:41 +03:00
Before this patch curl used the C preprocessor to override standard memory allocation symbols: malloc, calloc, strdup, realloc, free. The goal of these is to replace them with curl's debug wrappers in `CURLDEBUG` builds, another was to replace them with the wrappers calling user-defined allocators in libcurl. This solution needed a bunch of workarounds to avoid breaking external headers: it relied on include order to do the overriding last. For "unity" builds it needed to reset overrides before external includes. Also in test apps, which are always built as single source files. It also needed the `(symbol)` trick to avoid overrides in some places. This would still not fix cases where the standard symbols were macros. It was also fragile and difficult to figure out which was the actual function behind an alloc or free call in a specific piece of code. This in turn caused bugs where the wrong allocator was accidentally called. To avoid these problems, this patch replaces this solution with `curlx_`-prefixed allocator macros, and mapping them _once_ to either the libcurl wrappers, the debug wrappers or the standard ones, matching the rest of the code in libtests. This concludes the long journey to avoid redefining standard functions in the curl codebase. Note: I did not update `packages/OS400/*.c` sources. They did not `#include` `curl_setup.h`, `curl_memory.h` or `memdebug.h`, meaning the overrides were never applied to them. This may or may not have been correct. For now I suppressed the direct use of standard allocators via a local `.checksrc`. Probably they (except for `curlcl.c`) should be updated to include `curl_setup.h` and use the `curlx_` macros. This patch changes mappings in two places: - `lib/curl_threads.c` in libtests: Before this patch it mapped to libcurl allocators. After, it maps to standard allocators, like the rest of libtests code. - `units`: before this patch it mapped to standard allocators. After, it maps to libcurl allocators. Also: - drop all position-dependent `curl_memory.h` and `memdebug.h` includes, and delete the now unnecessary headers. - rename `Curl_tcsdup` macro to `curlx_tcsdup` and define like the other allocators. - map `curlx_strdup()` to `_strdup()` on Windows (was: `strdup()`). To fix warnings silenced via `_CRT_NONSTDC_NO_DEPRECATE`. - multibyte: map `curlx_convert_*()` to `_strdup()` on Windows (was: `strdup()`). - src: do not reuse the `strdup` name for the local replacement. - lib509: call `_strdup()` on Windows (was: `strdup()`). - test1132: delete test obsoleted by this patch. - CHECKSRC.md: update text for `SNPRINTF`. - checksrc: ban standard allocator symbols. Follow-up tob12da22db1#18866 Follow-up todb98daab05#18844 Follow-up to4deea9396b#18814 Follow-up to9678ff5b1b#18776 Follow-up to10bac43b87#18774 Follow-up to20142f5d06#18634 Follow-up tobf7375ecc5#18503 Follow-up to9863599d69#18502 Follow-up to3bb5e58c10#17827 Closes #19626
179 lines
7.2 KiB
C
179 lines
7.2 KiB
C
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
#include "first.h"
|
|
|
|
static CURLcode test_lib517(const char *URL)
|
|
{
|
|
struct dcheck {
|
|
const char *input;
|
|
time_t output;
|
|
};
|
|
|
|
static const struct dcheck dates[] = {
|
|
{"Sun, 06 Nov 1994 08:49:37 GMT", 784111777 },
|
|
{"Sunday, 06-Nov-94 08:49:37 GMT", 784111777 },
|
|
{"Sun Nov 6 08:49:37 1994", 784111777 },
|
|
{"Sun Nov 6 8:49:37 1994", 784111777 },
|
|
{"Sun Nov 6 8:9:37 1994", 784109377 },
|
|
{"Sun Nov 6 008:09:37 1994", -1 },
|
|
{"Nov Sun 6 8:9:7 1994", 784109347 },
|
|
{"06 Nov 1994 08:49:37 GMT", 784111777 },
|
|
{"06-Nov-94 08:49:37 GMT", 784111777 },
|
|
{"Nov 6 08:49:37 1994", 784111777 },
|
|
{"06 Nov 1994 08:49:37", 784111777 },
|
|
{"06-Nov-94 08:49:37", 784111777 },
|
|
{"1994 Nov 6 08:49:37", 784111777 },
|
|
{"GMT 08:49:37 06-Nov-94 Sunday", 784111777 },
|
|
{"94 6 Nov 08:49:37", 784111777 },
|
|
{"1994 Nov 6", 784080000 },
|
|
{"06-Nov-94", 784080000 },
|
|
{"Sun Nov 6 94", 784080000 },
|
|
{"1994.Nov.6", 784080000 },
|
|
{"Sun/Nov/6/94/GMT", 784080000 },
|
|
{"Sun, 06 Nov 1994 08:49:37 CET", 784108177 },
|
|
{"06 Nov 1994 08:49:37 EST", 784129777 },
|
|
{"Sun, 06 Nov 1994 08:49:37 UT", 784111777 },
|
|
{"Sun, 12 Sep 2004 15:05:58 -0700", 1095026758 },
|
|
{"Sat, 11 Sep 2004 21:32:11 +0200", 1094931131 },
|
|
{"20040912 15:05:58 -0700", 1095026758 },
|
|
{"20040911 +0200", 1094853600 },
|
|
{"Thu, 01-Jan-1970 00:59:59 GMT", 3599 },
|
|
{"Thu, 01-Jan-1970 01:00:00 GMT", 3600 },
|
|
{"Sat, 15-Apr-17 21:01:22 GMT", 1492290082 },
|
|
{"Thu, 19-Apr-2007 16:00:00 GMT", 1176998400 },
|
|
{"Wed, 25 Apr 2007 21:02:13 GMT", 1177534933 },
|
|
{"Thu, 19/Apr\\2007 16:00:00 GMT", 1176998400 },
|
|
{"Fri, 1 Jan 2010 01:01:50 GMT", 1262307710 },
|
|
{"Wednesday, 1-Jan-2003 00:00:00 GMT", 1041379200 },
|
|
{", 1-Jan-2003 00:00:00 GMT", 1041379200 },
|
|
{"1-Jan-2003 00:00:00 GMT", 1041379200 },
|
|
{"1-Jan-2003 00:00:00 GMT", 1041379200 },
|
|
{"Wed,18-Apr-07 22:50:12 GMT", 1176936612 },
|
|
{"WillyWonka , 18-Apr-07 22:50:12 GMT", -1 },
|
|
{"WillyWonka , 18-Apr-07 22:50:12", -1 },
|
|
{"WillyWonka , 18-apr-07 22:50:12", -1 },
|
|
{"Mon, 18-Apr-1977 22:50:13 GMT", 230251813 },
|
|
{"Mon, 18-Apr-77 22:50:13 GMT", 230251813 },
|
|
{"Sat, 15-Apr-17\"21:01:22\"GMT", 1492290082 },
|
|
{"Partyday, 18- April-07 22:50:12", -1 },
|
|
{"Partyday, 18 - Apri-07 22:50:12", -1 },
|
|
{"Wednes, 1-Januar-2003 00:00:00 GMT", -1 },/* spellchecker:disable-line */
|
|
{"Sat, 15-Apr-17 21:01:22", 1492290082 },
|
|
{"Sat, 15-Apr-17 21:01:22 GMT-2", 1492290082 },
|
|
{"Sat, 15-Apr-17 21:01:22 GMT BLAH", 1492290082 },
|
|
{"Sat, 15-Apr-17 21:01:22 GMT-0400", 1492290082 },
|
|
{"Sat, 15-Apr-17 21:01:22 GMT-0400 (EDT)", 1492290082 },
|
|
{"Sat, 15-Apr-17 21:01:22 DST", -1 },
|
|
{"Sat, 15-Apr-17 21:01:22 -0400", 1492304482 },
|
|
{"Sat, 15-Apr-17 21:01:22 (hello there)", -1 },
|
|
{"Sat, 15-Apr-17 21:01:22 11:22:33", -1 },
|
|
{"Sat, 15-Apr-17 ::00 21:01:22", -1 },
|
|
{"Sat, 15-Apr-17 boink:z 21:01:22", -1 },
|
|
{"Sat, 15-Apr-17 91:22:33 21:01:22", -1 },
|
|
{"Thu Apr 18 22:50:12 2007 GMT", 1176936612 },
|
|
{"22:50:12 Thu Apr 18 2007 GMT", 1176936612 },
|
|
{"Thu 22:50:12 Apr 18 2007 GMT", 1176936612 },
|
|
{"Thu Apr 22:50:12 18 2007 GMT", 1176936612 },
|
|
{"Thu Apr 18 22:50:12 2007 GMT", 1176936612 },
|
|
{"Thu Apr 18 2007 22:50:12 GMT", 1176936612 },
|
|
{"Thu Apr 18 2007 GMT 22:50:12", 1176936612 },
|
|
|
|
{"\"Thu Apr 18 22:50:12 2007 GMT\"", 1176936612 },
|
|
{"-\"22:50:12 Thu Apr 18 2007 GMT\"", 1176936612 },
|
|
{"*\"Thu 22:50:12 Apr 18 2007 GMT\"", 1176936612 },
|
|
{";\"Thu Apr 22:50:12 18 2007 GMT\"", 1176936612 },
|
|
{".\"Thu Apr 18 22:50:12 2007 GMT\"", 1176936612 },
|
|
{"\"Thu Apr 18 2007 22:50:12 GMT\"", 1176936612 },
|
|
{"\"Thu Apr 18 2007 GMT 22:50:12\"", 1176936612 },
|
|
|
|
{"Sat, 15-Apr-17 21:01:22 GMT", 1492290082 },
|
|
{"15-Sat, Apr-17 21:01:22 GMT", 1492290082 },
|
|
{"15-Sat, Apr 21:01:22 GMT 17", 1492290082 },
|
|
{"15-Sat, Apr 21:01:22 GMT 2017", 1492290082 },
|
|
{"15 Apr 21:01:22 2017", 1492290082 },
|
|
{"15 17 Apr 21:01:22", 1492290082 },
|
|
{"Apr 15 17 21:01:22", 1492290082 },
|
|
{"Apr 15 21:01:22 17", 1492290082 },
|
|
{"2017 April 15 21:01:22", -1 },
|
|
{"15 April 2017 21:01:22", -1 },
|
|
{"98 April 17 21:01:22", -1 },
|
|
{"Thu, 012-Aug-2008 20:49:07 GMT", 1218574147 },
|
|
{"Thu, 999999999999-Aug-2007 20:49:07 GMT", -1 },
|
|
{"Thu, 12-Aug-2007 20:61:99999999999 GMT", -1 },
|
|
{"IAintNoDateFool", -1 },
|
|
{"Thu Apr 18 22:50 2007 GMT", 1176936600 },
|
|
{"20110623 12:34:56", 1308832496 },
|
|
{"20110632 12:34:56", -1 },
|
|
{"20110623 56:34:56", -1 },
|
|
{"20111323 12:34:56", -1 },
|
|
{"20110623 12:34:79", -1 },
|
|
{"Wed, 31 Dec 2008 23:59:60 GMT", 1230768000 },
|
|
{"Wed, 31 Dec 2008 23:59:61 GMT", -1 },
|
|
{"Wed, 31 Dec 2008 24:00:00 GMT", -1 },
|
|
{"Wed, 31 Dec 2008 23:60:59 GMT", -1 },
|
|
{"20110623 12:3", 1308830580 },
|
|
{"20110623 1:3", 1308790980 },
|
|
{"20110623 1:30", 1308792600 },
|
|
{"20110623 12:12:3", 1308831123 },
|
|
{"20110623 01:12:3", 1308791523 },
|
|
{"20110623 01:99:30", -1 },
|
|
{"Thu, 01-Jan-1970 00:00:00 GMT", 0 },
|
|
{"Thu, 31-Dec-1969 23:59:58 GMT", -2 },
|
|
{"Thu, 31-Dec-1969 23:59:59 GMT", 0 }, /* avoids -1 ! */
|
|
#if SIZEOF_TIME_T > 4
|
|
{"Sun, 06 Nov 2044 08:49:37 GMT", (time_t)2362034977LL },
|
|
{"Sun, 06 Nov 3144 08:49:37 GMT", 37074617377 },
|
|
#ifndef HAVE_TIME_T_UNSIGNED
|
|
{"Sun, 06 Nov 1900 08:49:37 GMT", (time_t)-2182259423LL },
|
|
{"Sun, 06 Nov 1800 08:49:37 GMT", -5337933023 },
|
|
{"Thu, 01-Jan-1583 00:00:00 GMT", -12212553600 },
|
|
#endif /* HAVE_TIME_T_UNSIGNED */
|
|
{"Thu, 01-Jan-1499 00:00:00 GMT", -1 },
|
|
#else
|
|
{"Sun, 06 Nov 2044 08:49:37 GMT", -1 },
|
|
#endif /* SIZEOF_TIME_T > 4 */
|
|
#ifndef HAVE_TIME_T_UNSIGNED
|
|
{"Sun, 06 Nov 1968 08:49:37 GMT", -36342623 },
|
|
#endif /* !HAVE_TIME_T_UNSIGNED */
|
|
{ NULL, 0 }
|
|
};
|
|
|
|
int i;
|
|
int error = 0;
|
|
|
|
(void)URL;
|
|
|
|
for(i = 0; dates[i].input; i++) {
|
|
time_t out = curl_getdate(dates[i].input, NULL);
|
|
if(out != dates[i].output) {
|
|
curl_mprintf("WRONGLY %s => %" CURL_FORMAT_CURL_OFF_T
|
|
" (instead of %" CURL_FORMAT_CURL_OFF_T ")\n",
|
|
dates[i].input,
|
|
(curl_off_t)out, (curl_off_t)dates[i].output);
|
|
error++;
|
|
}
|
|
}
|
|
|
|
return error == 0 ? CURLE_OK : TEST_ERR_FAILURE;
|
|
}
|