Skip site navigation (1) Skip section navigation (2)

0x1A in control file on Windows

From: ITAGAKI Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org, pgsql-bugs(at)postgresql(dot)org
Subject: 0x1A in control file on Windows
Date: 2008-09-18 02:32:31
Message-ID: 20080918112547.80C7.52131E4D@oss.ntt.co.jp (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-hackers
I found a bug that pg_controldata ends with error if control files
contain 0x1A (Ctrl+Z) on Windows.

We probably need to add PG_BINARY when we open control files
because 0x1A is an end-of-file marker on Windows.
This fix needs to be applied in back versions (8.2, 8.3 and HEAD).


Index: src/bin/pg_controldata/pg_controldata.c
===================================================================
--- src/bin/pg_controldata/pg_controldata.c	(head)
+++ src/bin/pg_controldata/pg_controldata.c	(pg_control_0x1A)
@@ -107,7 +107,7 @@
 
 	snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
 
-	if ((fd = open(ControlFilePath, O_RDONLY, 0)) == -1)
+	if ((fd = open(ControlFilePath, O_RDONLY | PG_BINARY, 0)) == -1)
 	{
 		fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
 				progname, ControlFilePath, strerror(errno));
Index: src/bin/pg_resetxlog/pg_resetxlog.c
===================================================================
--- src/bin/pg_resetxlog/pg_resetxlog.c	(head)
+++ src/bin/pg_resetxlog/pg_resetxlog.c	(pg_control_0x1A)
@@ -373,7 +373,7 @@
 	char	   *buffer;
 	pg_crc32	crc;
 
-	if ((fd = open(XLOG_CONTROL_FILE, O_RDONLY, 0)) < 0)
+	if ((fd = open(XLOG_CONTROL_FILE, O_RDONLY | PG_BINARY, 0)) < 0)
 	{
 		/*
 		 * If pg_control is not there at all, or we can't read it, the odds

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center


Responses

pgsql-hackers by date

Next:From: Zhe HeDate: 2008-09-18 02:39:55
Subject: Where is Aggregation Attribute
Previous:From: Decibel!Date: 2008-09-18 02:00:32
Subject: Re: New FSM patch

pgsql-bugs by date

Next:From: Tom LaneDate: 2008-09-18 04:48:34
Subject: Re: [HACKERS] 0x1A in control file on Windows
Previous:From: Tom LaneDate: 2008-09-17 17:46:55
Subject: Re: BUG #4421: convert_to() should be immutable

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group