mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	If /dev/fd/X is a symlink and realpath() expands symlinks, /dev/fd/X
ends up pointing to the wrong place before it is passed to the client. The path is only used internally so there is no real need for realpath(), remove it and move the get_path function to file.c where all the callers are.
This commit is contained in:
		
							
								
								
									
										16
									
								
								file.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								file.c
									
									
									
									
									
								
							@@ -33,6 +33,18 @@ static int	file_next_stream = 3;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
RB_GENERATE(client_files, client_file, entry, file_cmp);
 | 
					RB_GENERATE(client_files, client_file, entry, file_cmp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static char *
 | 
				
			||||||
 | 
					file_get_path(struct client *c, const char *file)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char	*path;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (*file == '/')
 | 
				
			||||||
 | 
							path = xstrdup(file);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							xasprintf(&path, "%s/%s", server_client_get_cwd(c, NULL), file);
 | 
				
			||||||
 | 
						return (path);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
file_cmp(struct client_file *cf1, struct client_file *cf2)
 | 
					file_cmp(struct client_file *cf1, struct client_file *cf2)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -237,7 +249,7 @@ file_write(struct client *c, const char *path, int flags, const void *bdata,
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cf = file_create(c, file_next_stream++, cb, cbdata);
 | 
						cf = file_create(c, file_next_stream++, cb, cbdata);
 | 
				
			||||||
	cf->path = server_client_get_path(c, path);
 | 
						cf->path = file_get_path(c, path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (c == NULL || c->flags & CLIENT_ATTACHED) {
 | 
						if (c == NULL || c->flags & CLIENT_ATTACHED) {
 | 
				
			||||||
		if (flags & O_APPEND)
 | 
							if (flags & O_APPEND)
 | 
				
			||||||
@@ -306,7 +318,7 @@ file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cf = file_create(c, file_next_stream++, cb, cbdata);
 | 
						cf = file_create(c, file_next_stream++, cb, cbdata);
 | 
				
			||||||
	cf->path = server_client_get_path(c, path);
 | 
						cf->path = file_get_path(c, path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (c == NULL || c->flags & CLIENT_ATTACHED) {
 | 
						if (c == NULL || c->flags & CLIENT_ATTACHED) {
 | 
				
			||||||
		f = fopen(cf->path, "rb");
 | 
							f = fopen(cf->path, "rb");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2111,19 +2111,3 @@ server_client_get_cwd(struct client *c, struct session *s)
 | 
				
			|||||||
		return (home);
 | 
							return (home);
 | 
				
			||||||
	return ("/");
 | 
						return ("/");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Resolve an absolute path or relative to client working directory. */
 | 
					 | 
				
			||||||
char *
 | 
					 | 
				
			||||||
server_client_get_path(struct client *c, const char *file)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	char	*path, resolved[PATH_MAX];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (*file == '/')
 | 
					 | 
				
			||||||
		path = xstrdup(file);
 | 
					 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
		xasprintf(&path, "%s/%s", server_client_get_cwd(c, NULL), file);
 | 
					 | 
				
			||||||
	if (realpath(path, resolved) == NULL)
 | 
					 | 
				
			||||||
		return (path);
 | 
					 | 
				
			||||||
	free(path);
 | 
					 | 
				
			||||||
	return (xstrdup(resolved));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							@@ -2228,7 +2228,6 @@ void	 server_client_push_stdout(struct client *);
 | 
				
			|||||||
void	 server_client_push_stderr(struct client *);
 | 
					void	 server_client_push_stderr(struct client *);
 | 
				
			||||||
void printflike(2, 3) server_client_add_message(struct client *, const char *,
 | 
					void printflike(2, 3) server_client_add_message(struct client *, const char *,
 | 
				
			||||||
	     ...);
 | 
						     ...);
 | 
				
			||||||
char	*server_client_get_path(struct client *, const char *);
 | 
					 | 
				
			||||||
const char *server_client_get_cwd(struct client *, struct session *);
 | 
					const char *server_client_get_cwd(struct client *, struct session *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* server-fn.c */
 | 
					/* server-fn.c */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user