mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Fix readlink() for non-PostgreSQL junction points on Windows.
Since commitc5cb8f3btaught stat() to follow symlinks, and since initdb uses pg_mkdir_p(), and that examines parent directories, our humble readlink() implementation can now be exposed to junction points not of PostgreSQL origin. Those might be corrupted by our naive path mangling, which doesn't really understand NT paths in general. Simply decline to transform paths that don't look like a drive absolute path. That means that readlink() returns the NT path directly when checking a parent directory of PGDATA that happen to point to a drive using "rooted" format. That works for the purposes of our stat() emulation. Reported-by: Roman Zharkov <r.zharkov@postgrespro.ru> Reviewed-by: Roman Zharkov <r.zharkov@postgrespro.ru> Discussion: https://postgr.es/m/4590c37927d7b8ee84f9855d83229018%40postgrespro.ru Discussion: https://postgr.es/m/CA%2BhUKG%2BajSQ_8eu2AogTncOnZ5me2D-Cn66iN_-wZnRjLN%2Bicg%40mail.gmail.com Backpatched commitf71007fbas above by Thomas Munro into releases 13 thru 15 Discussion: https://postgr.es/m/CA+hUKGLbnv+pe3q1fYOVkLD3pMra7GuihfMxUN-1831YH9RYQg@mail.gmail.com
This commit is contained in:
		
				
					committed by
					
						
						Andrew Dunstan
					
				
			
			
				
	
			
			
			
						parent
						
							e708f31881
						
					
				
				
					commit
					9b136b0f2e
				
			@@ -351,10 +351,21 @@ pgreadlink(const char *path, char *buf, size_t size)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * If the path starts with "\??\", which it will do in most (all?) cases,
 | 
						 * If the path starts with "\??\" followed by a "drive absolute" path
 | 
				
			||||||
	 * strip those out.
 | 
						 * (known to Windows APIs as RtlPathTypeDriveAbsolute), then strip that
 | 
				
			||||||
 | 
						 * prefix.  This undoes some of the transformation performed by
 | 
				
			||||||
 | 
						 * pqsymlink(), to get back to a format that users are used to seeing.  We
 | 
				
			||||||
 | 
						 * don't know how to transform other path types that might be encountered
 | 
				
			||||||
 | 
						 * outside PGDATA, so we just return them directly.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (r > 4 && strncmp(buf, "\\??\\", 4) == 0)
 | 
						if (r >= 7 &&
 | 
				
			||||||
 | 
							buf[0] == '\\' &&
 | 
				
			||||||
 | 
							buf[1] == '?' &&
 | 
				
			||||||
 | 
							buf[2] == '?' &&
 | 
				
			||||||
 | 
							buf[3] == '\\' &&
 | 
				
			||||||
 | 
							isalpha(buf[4]) &&
 | 
				
			||||||
 | 
							buf[5] == ':' &&
 | 
				
			||||||
 | 
							buf[6] == '\\')
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		memmove(buf, buf + 4, strlen(buf + 4) + 1);
 | 
							memmove(buf, buf + 4, strlen(buf + 4) + 1);
 | 
				
			||||||
		r -= 4;
 | 
							r -= 4;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user