mirror of
https://github.com/curl/curl.git
synced 2026-08-26 04:13:31 +03:00
checksrc: reduce directory-specific exceptions
By making them defaults, then fixing and/or reshuffling remaining exceptions as necessary. - checksrc: ban by default: `snprintf`, `vsnprintf`, `sscanf`, `strtol`. - examples: replace `strtol` with `atoi` to avoid a checksrc exception. - tests/libtest: replace `strtol` with `atol`. - tests/server: replace most `strtol` with `atol`. - tests/server: replace most `strtoul` with `atol`/`atoi`. - tests/server: drop no longer used `util_ultous`. - fix typo in checksrc rules: `vsnprint` -> `vsnprintf`. - update local exceptions. Also: - examples: ban curl printf functions. They're discouraged in user code. - examples: replace curl printf with system printf. Add `snprintf` workaround for <VS2015. - examples/synctime: fix `-Wfloat-equal`. - examples/synctime: exclude for non-Windows and non-UWP Windows. - examples/synctime: build by default. Closes #18823
This commit is contained in:
parent
fff36a360e
commit
45438c8d6f
36 changed files with 124 additions and 142 deletions
|
|
@ -4,4 +4,14 @@ allowfunc fopen
|
|||
allowfunc gmtime
|
||||
allowfunc localtime
|
||||
allowfunc open
|
||||
allowfunc snprintf
|
||||
allowfunc socket
|
||||
allowfunc sscanf
|
||||
banfunc curl_maprintf
|
||||
banfunc curl_mfprintf
|
||||
banfunc curl_mprintf
|
||||
banfunc curl_msnprintf
|
||||
banfunc curl_mvaprintf
|
||||
banfunc curl_mvfprintf
|
||||
banfunc curl_mvprintf
|
||||
banfunc curl_mvsnprintf
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ check_PROGRAMS = \
|
|||
smtp-tls \
|
||||
smtp-vrfy \
|
||||
sslbackend \
|
||||
synctime \
|
||||
unixsocket \
|
||||
url2file \
|
||||
urlapi \
|
||||
|
|
@ -155,7 +156,6 @@ COMPLICATED_EXAMPLES = \
|
|||
multithread.c \
|
||||
sessioninfo.c \
|
||||
smooth-gtk-thread.c \
|
||||
synctime.c \
|
||||
threaded-ssl.c \
|
||||
usercertinmem.c \
|
||||
version-check.pl \
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ int main(int argc, char *argv[])
|
|||
case 'm':
|
||||
case 'M':
|
||||
if(argv[0][2] == '=') {
|
||||
long m = strtol((*argv) + 3, NULL, 10);
|
||||
int m = atoi((*argv) + 3);
|
||||
switch(m) {
|
||||
case 1:
|
||||
url = URL_1M;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@
|
|||
#include <curl/curl.h>
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
static int print_cookies(CURL *curl)
|
||||
{
|
||||
CURLcode res;
|
||||
|
|
@ -93,10 +97,10 @@ main(void)
|
|||
printf("-----------------------------------------------\n"
|
||||
"Setting a cookie \"PREF\" via cookie interface:\n");
|
||||
/* Netscape format cookie */
|
||||
curl_msnprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0f\t%s\t%s",
|
||||
".example.com", "TRUE", "/", "FALSE",
|
||||
difftime(time(NULL) + 31337, (time_t)0),
|
||||
"PREF", "hello example, i like you!");
|
||||
snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0f\t%s\t%s",
|
||||
".example.com", "TRUE", "/", "FALSE",
|
||||
difftime(time(NULL) + 31337, (time_t)0),
|
||||
"PREF", "hello example, I like you!");
|
||||
res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
|
||||
if(res != CURLE_OK) {
|
||||
fprintf(stderr, "Curl curl_easy_setopt failed: %s\n",
|
||||
|
|
@ -109,7 +113,7 @@ main(void)
|
|||
modified, likely not what you intended. For more information refer to
|
||||
the CURLOPT_COOKIELIST documentation.
|
||||
*/
|
||||
curl_msnprintf(nline, sizeof(nline),
|
||||
snprintf(nline, sizeof(nline),
|
||||
"Set-Cookie: OLD_PREF=3d141414bf4209321; "
|
||||
"expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.example.com");
|
||||
res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
|
||||
|
|
|
|||
|
|
@ -38,6 +38,10 @@
|
|||
#include <curl/curl.h>
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#ifndef CURLPIPE_MULTIPLEX
|
||||
/* This little trick makes sure that we do not enable pipelining for libcurls
|
||||
old enough to not have this symbol. It is _not_ defined to zero in a recent
|
||||
|
|
@ -149,7 +153,7 @@ static int setup(struct transfer *t, int num)
|
|||
|
||||
hnd = t->easy = curl_easy_init();
|
||||
|
||||
curl_msnprintf(filename, 128, "dl-%d", num);
|
||||
snprintf(filename, sizeof(filename), "dl-%d", num);
|
||||
|
||||
t->out = fopen(filename, "wb");
|
||||
if(!t->out) {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@
|
|||
#include <curl/curl.h>
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#ifndef CURLPIPE_MULTIPLEX
|
||||
#error "too old libcurl, cannot do HTTP/2 server push!"
|
||||
#endif
|
||||
|
|
@ -173,7 +177,7 @@ static int server_push_callback(CURL *parent,
|
|||
|
||||
(void)parent;
|
||||
|
||||
curl_msnprintf(filename, 128, "push%u", count++);
|
||||
snprintf(filename, sizeof(filename), "push%u", count++);
|
||||
|
||||
/* here's a new stream, save it in a new file for each new push */
|
||||
out = fopen(filename, "wb");
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@
|
|||
#ifndef _MSC_VER
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#elif (_MSC_VER < 1900)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
|
@ -162,8 +164,8 @@ int my_trace(CURL *handle, curl_infotype type,
|
|||
}
|
||||
secs = epoch_offset + tv.tv_sec;
|
||||
now = localtime(&secs); /* not thread safe but we do not care */
|
||||
curl_msnprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
|
||||
now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
|
||||
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
|
||||
now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
|
||||
|
||||
switch(type) {
|
||||
case CURLINFO_TEXT:
|
||||
|
|
@ -215,7 +217,7 @@ static int setup(struct input *i, int num, const char *upload)
|
|||
hnd = i->hnd = NULL;
|
||||
|
||||
i->num = num;
|
||||
curl_msnprintf(filename, 128, "dl-%d", num);
|
||||
snprintf(filename, sizeof(filename), "dl-%d", num);
|
||||
out = fopen(filename, "wb");
|
||||
if(!out) {
|
||||
fprintf(stderr, "error: could not open file %s for writing: %s\n", upload,
|
||||
|
|
@ -223,7 +225,7 @@ static int setup(struct input *i, int num, const char *upload)
|
|||
return 1;
|
||||
}
|
||||
|
||||
curl_msnprintf(url, 256, "https://localhost:8443/upload-%d", num);
|
||||
snprintf(url, sizeof(url), "https://localhost:8443/upload-%d", num);
|
||||
|
||||
i->in = fopen(upload, "rb");
|
||||
if(!i->in) {
|
||||
|
|
|
|||
|
|
@ -72,15 +72,32 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#ifndef _WIN32
|
||||
int main(void) { printf("Platform not supported.\n"); return 1; }
|
||||
#else
|
||||
#error "This example requires Windows."
|
||||
|
||||
#if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
|
||||
defined(WINAPI_FAMILY)
|
||||
# include <winapifamily.h>
|
||||
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
|
||||
!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
# define CURL_WINDOWS_UWP
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CURL_WINDOWS_UWP
|
||||
int main(void) { printf("Platform not supported.\n"); return 1; }
|
||||
#else
|
||||
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#define MAX_STRING 256
|
||||
#define MAX_STRING1 MAX_STRING + 1
|
||||
|
|
@ -139,7 +156,7 @@ static size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb,
|
|||
*TmpStr1 = 0;
|
||||
*TmpStr2 = 0;
|
||||
if(strlen((char *)(ptr)) > 50) /* Can prevent buffer overflow to
|
||||
TmpStr1 & 2? */
|
||||
TmpStr1 & 2? */
|
||||
AutoSyncTime = 0;
|
||||
else {
|
||||
int RetVal = sscanf((char *)(ptr), "Date: %25s %hu %s %hu %hu:%hu:%hu",
|
||||
|
|
@ -305,7 +322,7 @@ int main(int argc, char *argv[])
|
|||
tzonediffFloat = difftime(tt_local, tt_gmt);
|
||||
tzonediffWord = (int)(tzonediffFloat/3600.0);
|
||||
|
||||
if((double)(tzonediffWord * 3600) == tzonediffFloat)
|
||||
if(tzonediffWord == (int)(tzonediffFloat/3600.0))
|
||||
snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'00'", tzonediffWord);
|
||||
else
|
||||
snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'30'", tzonediffWord);
|
||||
|
|
@ -358,3 +375,5 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
return RetValue;
|
||||
}
|
||||
#endif /* CURL_WINDOWS_UWP */
|
||||
#endif /* _WIN32 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue