← Commit list

83b7ad083d

Daniel Stenberg
Daniel Stenberg
2026-09-05
SUCCESS Duration: 432s

Subject

curl_fopen: restore the uid and gid checks

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

CMake/unix-cache.cmake+1 -0
@@ -80,6 +80,7 @@ if((APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.9) OR
elseif(NOT APPLE)
set(HAVE_MEMSET_S 0)
endif()
+set(HAVE_FCHMOD 1)
set(HAVE_FCNTL 1)
set(HAVE_FCNTL_H 1)
set(HAVE_FCNTL_O_NONBLOCK 1)
CMakeLists.txt+1 -0
@@ -1669,6 +1669,7 @@ endif()
if(NOT WIN32)
check_include_file("dirent.h" HAVE_DIRENT_H)
+ check_function_exists("fchmod" HAVE_FCHMOD)
check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY) # sys/time.h
check_function_exists("if_nametoindex" HAVE_IF_NAMETOINDEX) # net/if.h
check_function_exists("realpath" HAVE_REALPATH)
configure.ac+1 -0
@@ -4249,6 +4249,7 @@ fi
if test "$curl_cv_native_windows" != "yes"; then
AC_CHECK_FUNCS([\
+ fchmod \
gettimeofday \
if_nametoindex \
realpath \
lib/curl_config-cmake.h.in+3 -0
@@ -206,6 +206,9 @@
/* Define to 1 if you have the `accept4' function. */
#cmakedefine HAVE_ACCEPT4 1
+/* Define to 1 if you have the `fchmod' function. */
+#cmakedefine HAVE_FCHMOD 1
+
/* Define to 1 if you have the `fnmatch' function. */
#cmakedefine HAVE_FNMATCH 1
lib/curl_fopen.c+14 -9
@@ -102,13 +102,6 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename,
return CURLE_OK;
}
curlx_fclose(*fh);
-#ifdef HAVE_GETEUID
- /* If the existing file is not owned by the user, do not inherit
- * its permissions at the temp file created below. The permissions
- * might be unsuitable for holding user private data. */
- if(sb.st_uid != geteuid())
- sb.st_mode = 0;
-#endif
#endif /* !_WIN32 */
*fh = NULL;
@@ -136,14 +129,26 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename,
#elif (defined(ANDROID) || defined(__ANDROID__)) && \
(defined(__i386__) || defined(__arm__))
fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL,
- (mode_t)(S_IRUSR | S_IWUSR | sb.st_mode));
+ (mode_t)(S_IRUSR | S_IWUSR | 0600));
#else
fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL,
- S_IRUSR | S_IWUSR | sb.st_mode);
+ S_IRUSR | S_IWUSR | 0600);
#endif
if(fd == -1)
goto fail;
+#ifdef HAVE_FCHMOD
+ {
+ curlx_struct_stat nsb;
+ if((curlx_fstat(fd, &nsb) != -1) &&
+ (nsb.st_uid == sb.st_uid) && (nsb.st_gid == sb.st_gid)) {
+ /* if the user and group are the same, clone the original mode */
+ if(fchmod(fd, sb.st_mode) == -1)
+ goto fail;
+ }
+ }
+#endif
+
*fh = curlx_fdopen(fd, FOPEN_WRITETEXT);
if(!*fh)
goto fail;