@@ -379,6 +379,8 @@ int open_sender_source_path(const char *path, int flags, int *matched)
379379 errno = saved_errno ;
380380 return fd ;
381381#else
382+ (void )path ;
383+ (void )flags ;
382384 * matched = 0 ;
383385 errno = ENOSYS ;
384386 return -1 ;
@@ -2259,14 +2261,21 @@ static void interpret_stat_error(const char *fname, int is_dir)
22592261static DIR * secure_opendir (const char * fbuf )
22602262{
22612263 int dfd , fl , matched ;
2264+ int dir_flags = O_RDONLY ;
22622265 DIR * d ;
22632266
2267+ #ifdef O_DIRECTORY
2268+ dir_flags |= O_DIRECTORY ;
2269+ #elif defined O_NONBLOCK
2270+ /* Avoid blocking on a raced special file before fdopendir validates it. */
2271+ dir_flags |= O_NONBLOCK ;
2272+ #endif
22642273 if (filesfrom_owner_walk_active ()) {
22652274 /* The source base is operator-selected, while each list entry may not
22662275 * be. Follow only trusted-owned symlinks while opening the directory. */
2267- dfd = open_no_attacker_symlinks (fbuf , O_RDONLY | O_DIRECTORY , 0 );
2276+ dfd = open_no_attacker_symlinks (fbuf , dir_flags , 0 );
22682277 } else if (!am_daemon && am_sender
2269- && (dfd = open_sender_source_path (fbuf , O_RDONLY | O_DIRECTORY , & matched ), matched )) {
2278+ && (dfd = open_sender_source_path (fbuf , dir_flags , & matched ), matched )) {
22702279 /* The command-line directory is the operator-selected transfer root.
22712280 * Follow that root, then keep every recursive scan beneath its held fd. */
22722281 } else if (am_daemon && (!am_chrooted || module_dirlen )
@@ -2295,18 +2304,18 @@ static DIR *secure_opendir(const char *fbuf)
22952304 return NULL ;
22962305 }
22972306 dfd = secure_relative_open_at (module_dirfd , * modrel ? modrel : "." ,
2298- O_RDONLY | O_DIRECTORY , 0 );
2307+ dir_flags , 0 );
22992308 } else if (* fbuf == '/' ) {
23002309 /* An absolute scan path (an absolute --relative / --files-from name, or a
23012310 * "/" transfer root): anchor at "/" -- operator-named, trusted. */
23022311 const char * relp = fbuf ;
23032312 while (* relp == '/' )
23042313 relp ++ ;
2305- dfd = secure_relative_open ("/" , relp , O_RDONLY | O_DIRECTORY , 0 );
2314+ dfd = secure_relative_open ("/" , relp , dir_flags , 0 );
23062315 } else {
23072316 /* Non-daemon (or chrooted) sender: confine beneath the cwd the sender
23082317 * chdir'd into (the transfer root). */
2309- dfd = secure_relative_open (NULL , fbuf , O_RDONLY | O_DIRECTORY , 0 );
2318+ dfd = secure_relative_open (NULL , fbuf , dir_flags , 0 );
23102319 }
23112320
23122321 if (dfd < 0 )
0 commit comments