mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Handle absolute paths properly, and don't use resolved path in
realpath() fails.
This commit is contained in:
		@@ -77,11 +77,15 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
 | 
			
		||||
	else
 | 
			
		||||
		cwd = ".";
 | 
			
		||||
 | 
			
		||||
	xasprintf(&file, "%s/%s", cwd, path);
 | 
			
		||||
	if (realpath(file, resolved) == NULL)
 | 
			
		||||
		f = NULL;
 | 
			
		||||
	if (*path == '/')
 | 
			
		||||
		file = xstrdup(path);
 | 
			
		||||
	else
 | 
			
		||||
		f = fopen(resolved, "rb");
 | 
			
		||||
		xasprintf(&file, "%s/%s", cwd, path);
 | 
			
		||||
	if (realpath(file, resolved) == NULL) {
 | 
			
		||||
		cmdq_error(cmdq, "%s: %s", file, strerror(errno));
 | 
			
		||||
		return (CMD_RETURN_ERROR);
 | 
			
		||||
	}
 | 
			
		||||
	f = fopen(resolved, "rb");
 | 
			
		||||
	free(file);
 | 
			
		||||
	if (f == NULL) {
 | 
			
		||||
		cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));
 | 
			
		||||
 
 | 
			
		||||
@@ -103,11 +103,15 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
 | 
			
		||||
	if (args_has(self->args, 'a'))
 | 
			
		||||
		flags = "ab";
 | 
			
		||||
 | 
			
		||||
	xasprintf(&file, "%s/%s", cwd, path);
 | 
			
		||||
	if (realpath(file, resolved) == NULL)
 | 
			
		||||
		f = NULL;
 | 
			
		||||
	if (*path == '/')
 | 
			
		||||
		file = xstrdup(path);
 | 
			
		||||
	else
 | 
			
		||||
		f = fopen(resolved, flags);
 | 
			
		||||
		xasprintf(&file, "%s/%s", cwd, path);
 | 
			
		||||
	if (realpath(file, resolved) == NULL)  {
 | 
			
		||||
		cmdq_error(cmdq, "%s: %s", file, strerror(errno));
 | 
			
		||||
		return (CMD_RETURN_ERROR);
 | 
			
		||||
	}
 | 
			
		||||
	f = fopen(resolved, flags);
 | 
			
		||||
	free(file);
 | 
			
		||||
	if (f == NULL) {
 | 
			
		||||
		cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user