public inbox for [email protected]  
help / color / mirror / Atom feed
From: Mahendra Singh Thalor <[email protected]>
To: Peter Eisentraut <[email protected]>
Cc: Andrew Dunstan <[email protected]>
Cc: jian he <[email protected]>
Cc: tushar <[email protected]>
Cc: Vaibhav Dalvi <[email protected]>
Cc: [email protected]
Subject: Re: Non-text mode for pg_dumpall
Date: Tue, 3 Mar 2026 16:47:52 +0530
Message-ID: <CAKYtNAp+SBSVENOtvEqpAcZCeQZhNZFU005Jy5-eP+2kC-3ryA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<CAC6VRoZbP=-=a+a78RoWcs2L4=4VEDZqJMg+7SyUAcSHATyDAQ@mail.gmail.com>
	<CAC6VRoY-1WC_O5UDwKzNc18LXLwjuTFb+qMNY3gaF3cCov6M6g@mail.gmail.com>
	<CAKYtNArc3j8Akb+nB1QyJLKic7ej7vKZqKnv_mbB+iQAJRzLnA@mail.gmail.com>
	<CAC6VRoat6NPcS6vfGrPrwaQB3G1JHLSqDeAkf1AJ7npWrwhnUQ@mail.gmail.com>
	<CAKYtNAp=TFEZWQbTRZso3kNaD9BH=-JPNQ30mT60cJN_04hEog@mail.gmail.com>
	<[email protected]>
	<CAKYtNAq73_UeL4-0wgu9rawctHdS2zhpzWtqVuOChCS3M+2Ymg@mail.gmail.com>
	<CACJufxFs9NXXTeb78i2MD+pnZootayAtiGcNHNeU35SmQgMjbA@mail.gmail.com>
	<[email protected]>
	<CACJufxEnmJ8otfmN7Kp110Wqi=M4YE0-zn-W6SK+eTpWuZw_fg@mail.gmail.com>
	<CAKYtNAqxjQMLVPfz6XESqszhxZKgigi7UEBzBhz_Wj_Bnasdag@mail.gmail.com>
	<[email protected]>
	<CACJufxE-zJiBAaZABtJBJr8FZdj=xP5adf_excmu9S6Op=KpLA@mail.gmail.com>
	<[email protected]>
	<[email protected]>

On Tue, 3 Mar 2026 at 14:55, Peter Eisentraut <[email protected]> wrote:
>
> I noticed this cast in the committed code:
>
> > + num_total_db = get_dbname_oid_list_from_mfile((char *) inputFileSpec,
> > &dbname_oid_list);
>
> The cast drops the const qualifier from inputFileSpec.
> get_dbname_oid_list_from_mfile() writes into the space pointed to by its
> argument, so it's really not "const".  (And inputFileSpec points into
> argv, so this ends up writing directly into argv.)
>
> Please see if you can clean this up.  It might be best if
> get_dbname_oid_list_from_mfile() made a copy of its argument that it can
> write into, and then the argument can be "const".
>

Thanks Peter.

Here, I am attaching a patch to fix this issue.

-- 
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com


Attachments:

  [text/x-patch] v01_pg_restore-don-t-edit-inputfile-name-instead-use-local.patch (2.1K, 2-v01_pg_restore-don-t-edit-inputfile-name-instead-use-local.patch)
  download | inline diff:
From cb744c481ff045a95f11d2a0217aba928ede22db Mon Sep 17 00:00:00 2001
From: Mahendra Singh Thalor <[email protected]>
Date: Tue, 3 Mar 2026 16:43:33 +0530
Subject: [PATCH] pg_restore: don't edit inputfile name, instead use local copy

In get_dbname_oid_list_from_mfile, we are editing filename by passing is
char *, instead of const char*. Fixed this by adding local copy.
---
 src/bin/pg_dump/pg_restore.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 14d886fc86e..54c8b9d48b0 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -68,7 +68,7 @@ static int	restore_all_databases(const char *inputFileSpec,
 static int	get_dbnames_list_to_restore(PGconn *conn,
 										SimplePtrList *dbname_oid_list,
 										SimpleStringList db_exclude_patterns);
-static int	get_dbname_oid_list_from_mfile(char *dumpdirpath,
+static int	get_dbname_oid_list_from_mfile(const char *dumpdirpatharg,
 										   SimplePtrList *dbname_oid_list);
 
 /*
@@ -1082,14 +1082,18 @@ get_dbnames_list_to_restore(PGconn *conn,
  * Returns, total number of database names in map.dat file.
  */
 static int
-get_dbname_oid_list_from_mfile(char *dumpdirpath, SimplePtrList *dbname_oid_list)
+get_dbname_oid_list_from_mfile(const char *dumpdirpatharg, SimplePtrList *dbname_oid_list)
 {
 	StringInfoData linebuf;
 	FILE	   *pfile;
 	char		map_file_path[MAXPGPATH];
 	int			count = 0;
 	int			len;
+	char			*dumpdirpath;
 
+	len = strlen(dumpdirpatharg);
+	dumpdirpath = pg_malloc0(len + 1);
+	memcpy(dumpdirpath, dumpdirpatharg, len);
 
 	/*
 	 * If there is no map.dat file in dump, then return from here as there is
@@ -1206,7 +1210,7 @@ restore_all_databases(const char *inputFileSpec,
 	if (opts->cparams.dbname)
 		connected_db = opts->cparams.dbname;
 
-	num_total_db = get_dbname_oid_list_from_mfile((char *) inputFileSpec, &dbname_oid_list);
+	num_total_db = get_dbname_oid_list_from_mfile(inputFileSpec, &dbname_oid_list);
 
 	pg_log_info(ngettext("found %d database name in \"%s\"",
 						 "found %d database names in \"%s\"",
-- 
2.52.0



view thread (111+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Non-text mode for pg_dumpall
  In-Reply-To: <CAKYtNAp+SBSVENOtvEqpAcZCeQZhNZFU005Jy5-eP+2kC-3ryA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox