Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use wrapper for curl_mime_data fseek callback #11918

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -1037,6 +1037,7 @@ check_include_file_concat("signal.h" HAVE_SIGNAL_H)
check_include_file_concat("stdatomic.h" HAVE_STDATOMIC_H)
check_include_file_concat("stdbool.h" HAVE_STDBOOL_H)
check_include_file_concat("stdint.h" HAVE_STDINT_H)
check_include_file_concat("stdio.h" HAVE_STDIO_H)
Copy link
Member

@vszakats vszakats Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this check added?

HAVE_STDIO_H is not used in the source. stdio.h is a standard C89 header and we use it everywhere unconditionally.

If fseek detection needs it, this would seem to avoid requiring an extra check:

check_symbol_exists(fseeko         "${CURL_INCLUDES};stdio.h" HAVE_FSEEKO)
check_symbol_exists(_fseeki64      "${CURL_INCLUDES};stdio.h" HAVE__FSEEKI64)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is the Fseek detection that needs it.

Copy link
Member

@bagder bagder Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that due to some funky cmakeism? We don't have to check for stdio.h, but maybe it needs to be set somehow so that it gets used for the fseeko check?

edit: Just as @vszakats said...

check_include_file_concat("stdlib.h" HAVE_STDLIB_H)
check_include_file_concat("string.h" HAVE_STRING_H)
check_include_file_concat("strings.h" HAVE_STRINGS_H)
Expand Down Expand Up @@ -1122,6 +1123,8 @@ endif()
check_symbol_exists(freeaddrinfo "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
check_symbol_exists(pipe "${CURL_INCLUDES}" HAVE_PIPE)
check_symbol_exists(ftruncate "${CURL_INCLUDES}" HAVE_FTRUNCATE)
check_symbol_exists(fseeko "${CURL_INCLUDES}" HAVE_FSEEKO)
check_symbol_exists(_fseeki64 "${CURL_INCLUDES}" HAVE__FSEEKI64)
check_symbol_exists(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
check_symbol_exists(if_nametoindex "${CURL_INCLUDES}" HAVE_IF_NAMETOINDEX)
Expand Down
7 changes: 5 additions & 2 deletions configure.ac
Expand Up @@ -3583,9 +3583,13 @@ AC_CHECK_DECLS([getpwuid_r], [], [AC_DEFINE(HAVE_DECL_GETPWUID_R_MISSING, 1, "Se
#include <sys/types.h>]])


AC_CHECK_FUNCS([fnmatch \
AC_CHECK_FUNCS([\
_fseeki64 \
arc4random \
fchmod \
fnmatch \
fork \
fseeko \
geteuid \
getpass_r \
getppid \
Expand All @@ -3604,7 +3608,6 @@ AC_CHECK_FUNCS([fnmatch \
snprintf \
utime \
utimes \
arc4random
],[
],[
func="$ac_func"
Expand Down
17 changes: 15 additions & 2 deletions lib/formdata.c
Expand Up @@ -789,6 +789,20 @@ static CURLcode setname(curl_mimepart *part, const char *name, size_t len)
return res;
}

/* wrap call to fseeko so it matches the calling convetion of callback */
static int fseeko_wrapper(void *stream, curl_off_t offset, int whence)
{
#if defined(HAVE_FSEEKO)
return fseeko(stream, (off_t)offset, whence);
ncopa marked this conversation as resolved.
Show resolved Hide resolved
#elif defined(HAVE__FSEEKI64)
return _fseeki64(stream, (__int64)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
Expand Down Expand Up @@ -874,8 +888,7 @@ CURLcode Curl_getformdata(struct Curl_easy *data,
compatibility: use of "-" pseudo file name should be avoided. */
result = curl_mime_data_cb(part, (curl_off_t) -1,
(curl_read_callback) fread,
CURLX_FUNCTION_CAST(curl_seek_callback,
fseek),
fseeko_wrapper,
NULL, (void *) stdin);
}
else
Expand Down