mime: fix use of fseek()

Avoid the possible 64-bit offset truncation when used on systems with
small 'long', like Windows.

bonus: make mime_open_file() return bool

Pointed out by ZeroPath
Closes #19100
This commit is contained in:
Daniel Stenberg 2025-10-17 14:41:08 +02:00
parent c0564ceb3a
commit 4fb12f2891
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 19 additions and 19 deletions

View file

@ -771,20 +771,6 @@ static CURLcode setname(curl_mimepart *part, const char *name, size_t len)
return res;
}
/* wrap call to fseeko so it matches the calling convention of callback */
static int fseeko_wrapper(void *stream, curl_off_t offset, int whence)
{
#if defined(_WIN32) && defined(USE_WIN32_LARGE_FILES)
return _fseeki64(stream, (__int64)offset, whence);
#elif defined(HAVE_FSEEKO) && defined(HAVE_DECL_FSEEKO)
return fseeko(stream, (off_t)offset, whence);
#else
if(offset > LONG_MAX)
return -1;
return fseek(stream, (long)offset, whence);
#endif
}
/*
* Curl_getformdata() converts a linked list of "meta data" into a mime
* structure. The input list is in 'post', while the output is stored in
@ -874,7 +860,7 @@ CURLcode Curl_getformdata(CURL *data,
#endif
result = curl_mime_data_cb(part, (curl_off_t) -1,
(curl_read_callback) fread,
fseeko_wrapper,
Curl_fseeko,
NULL, (void *) stdin);
#if defined(__clang__) && __clang_major__ >= 16
#pragma clang diagnostic pop