mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-25 13:17:41 +03:00 
			
		
		
		
	Previously, pg_logicalinspect functions were too trusting of their input and blindly passed it to SnapBuildRestoreSnapshot(). If the input pointed to a directory, the server could a PANIC error while attempting to fsync_fname() with isdir=false on a directory. This commit adds validation checks for input filenames and passes the LSN extracted from the filename to SnapBuildRestoreSnapshot() instead of the filename itself. It also adds regression tests for various input patterns and permission checks. Bug: #18828 Reported-by: Robins Tharakan <tharakan@gmail.com> Co-authored-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Co-authored-by: Masahiko Sawada <sawada.mshk@gmail.com> Discussion: https://postgr.es/m/18828-0f4701c635064211@postgresql.org
		
			
				
	
	
		
			82 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| CREATE EXTENSION pg_logicalinspect;
 | |
| -- ===================================================================
 | |
| -- Tests for input validation
 | |
| -- ===================================================================
 | |
| SELECT pg_get_logical_snapshot_info('0-40796E18.foo');
 | |
| ERROR:  invalid snapshot file name "0-40796E18.foo"
 | |
| SELECT pg_get_logical_snapshot_info('0--40796E18.snap');
 | |
| ERROR:  invalid snapshot file name "0--40796E18.snap"
 | |
| SELECT pg_get_logical_snapshot_info('-1--40796E18.snap');
 | |
| ERROR:  invalid snapshot file name "-1--40796E18.snap"
 | |
| SELECT pg_get_logical_snapshot_info('0/40796E18.foo.snap');
 | |
| ERROR:  invalid snapshot file name "0/40796E18.foo.snap"
 | |
| SELECT pg_get_logical_snapshot_info('0/40796E18.snap');
 | |
| ERROR:  invalid snapshot file name "0/40796E18.snap"
 | |
| SELECT pg_get_logical_snapshot_info('');
 | |
| ERROR:  invalid snapshot file name ""
 | |
| SELECT pg_get_logical_snapshot_info(NULL);
 | |
|  pg_get_logical_snapshot_info 
 | |
| ------------------------------
 | |
|  
 | |
| (1 row)
 | |
| 
 | |
| SELECT pg_get_logical_snapshot_info('../snapshots');
 | |
| ERROR:  invalid snapshot file name "../snapshots"
 | |
| SELECT pg_get_logical_snapshot_info('../snapshots/0-40796E18.snap');
 | |
| ERROR:  invalid snapshot file name "../snapshots/0-40796E18.snap"
 | |
| SELECT pg_get_logical_snapshot_meta('0-40796E18.foo');
 | |
| ERROR:  invalid snapshot file name "0-40796E18.foo"
 | |
| SELECT pg_get_logical_snapshot_meta('0-40796E18.foo.snap');
 | |
| ERROR:  invalid snapshot file name "0-40796E18.foo.snap"
 | |
| SELECT pg_get_logical_snapshot_meta('0/40796E18.snap');
 | |
| ERROR:  invalid snapshot file name "0/40796E18.snap"
 | |
| SELECT pg_get_logical_snapshot_meta('');
 | |
| ERROR:  invalid snapshot file name ""
 | |
| SELECT pg_get_logical_snapshot_meta(NULL);
 | |
|  pg_get_logical_snapshot_meta 
 | |
| ------------------------------
 | |
|  
 | |
| (1 row)
 | |
| 
 | |
| SELECT pg_get_logical_snapshot_meta('../snapshots');
 | |
| ERROR:  invalid snapshot file name "../snapshots"
 | |
| -- ===================================================================
 | |
| -- Tests for permissions
 | |
| -- ===================================================================
 | |
| CREATE ROLE regress_pg_logicalinspect;
 | |
| SELECT has_function_privilege('regress_pg_logicalinspect',
 | |
|   'pg_get_logical_snapshot_info(text)', 'EXECUTE'); -- no
 | |
|  has_function_privilege 
 | |
| ------------------------
 | |
|  f
 | |
| (1 row)
 | |
| 
 | |
| SELECT has_function_privilege('regress_pg_logicalinspect',
 | |
|   'pg_get_logical_snapshot_meta(text)', 'EXECUTE'); -- no
 | |
|  has_function_privilege 
 | |
| ------------------------
 | |
|  f
 | |
| (1 row)
 | |
| 
 | |
| -- Functions accessible by users with role pg_read_server_files.
 | |
| GRANT pg_read_server_files TO regress_pg_logicalinspect;
 | |
| SELECT has_function_privilege('regress_pg_logicalinspect',
 | |
|   'pg_get_logical_snapshot_info(text)', 'EXECUTE'); -- yes
 | |
|  has_function_privilege 
 | |
| ------------------------
 | |
|  t
 | |
| (1 row)
 | |
| 
 | |
| SELECT has_function_privilege('regress_pg_logicalinspect',
 | |
|   'pg_get_logical_snapshot_meta(text)', 'EXECUTE'); -- yes
 | |
|  has_function_privilege 
 | |
| ------------------------
 | |
|  t
 | |
| (1 row)
 | |
| 
 | |
| -- ===================================================================
 | |
| -- Clean up
 | |
| -- ===================================================================
 | |
| DROP ROLE regress_pg_logicalinspect;
 | |
| DROP EXTENSION pg_logicalinspect;
 |