mirror of
https://github.com/curl/curl.git
synced 2026-05-02 22:57:53 +03:00
examples: fix two more cases of stat() TOCTOU
Also:
- ftpupload: bump an intermediate variable size.
Follow-up to f13250edf1 #18605
Closes #18778
This commit is contained in:
parent
5b086ba188
commit
c478c7efdf
2 changed files with 35 additions and 17 deletions
|
|
@ -33,6 +33,9 @@
|
|||
#ifdef _WIN32
|
||||
#undef stat
|
||||
#define stat _stat
|
||||
#undef fstat
|
||||
#define fstat _fstat
|
||||
#define fileno _fileno
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -79,9 +82,6 @@ int main(int argc, char **argv)
|
|||
file = argv[1];
|
||||
url = argv[2];
|
||||
|
||||
/* get the file size of the local file */
|
||||
stat(file, &file_info);
|
||||
|
||||
/* get a FILE * of the same file, could also be made with
|
||||
fdopen() from the previous descriptor, but hey this is just
|
||||
an example! */
|
||||
|
|
@ -89,6 +89,16 @@ int main(int argc, char **argv)
|
|||
if(!hd_src)
|
||||
return 2;
|
||||
|
||||
/* get the file size of the local file */
|
||||
#ifdef UNDER_CE
|
||||
if(stat(file, &file_info) != 0) {
|
||||
#else
|
||||
if(fstat(fileno(hd_src), &file_info) != 0) {
|
||||
#endif
|
||||
fclose(hd_src);
|
||||
return 1; /* cannot continue */
|
||||
}
|
||||
|
||||
/* In Windows, this inits the Winsock stuff */
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue