From 79f9ee9d15cdc4e96faa69135c4a2f734577e9d6 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri, 13 Aug 2004 14:47:23 +0000
Subject: [PATCH] Fix core dumps, inability to count, etc associated with
 canonicalize_path patches.

---
 src/backend/utils/fmgr/dfmgr.c | 5 +++--
 src/bin/psql/command.c         | 5 +++--
 src/bin/psql/copy.c            | 5 +++--
 src/port/path.c                | 8 ++++----
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index 07343f69ed2..111f9747101 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.75 2004/07/12 02:22:49 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.76 2004/08/13 14:47:23 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -405,10 +405,11 @@ find_in_dynamic_libpath(const char *basename)
 		strncpy(piece, p, len);
 		piece[len] = '\0';
 
-		canonicalize_path(piece);
 		mangled = substitute_libpath_macro(piece);
 		pfree(piece);
 
+		canonicalize_path(mangled);
+
 		/* only absolute paths */
 		if (!is_absolute_path(mangled))
 			ereport(ERROR,
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index da2ab92b353..7002ebf7a20 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.122 2004/07/15 03:56:06 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.123 2004/08/13 14:47:23 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -375,7 +375,8 @@ exec_command(const char *cmd,
 			fname = psql_scan_slash_option(scan_state,
 										   OT_NORMAL, NULL, true);
 			expand_tilde(&fname);
-			canonicalize_path(fname);
+			if (fname)
+				canonicalize_path(fname);
 			status = do_edit(fname, query_buf) ? CMD_NEWEDIT : CMD_ERROR;
 			free(fname);
 		}
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index 86c0dde748f..d4a3a460017 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.50 2004/07/11 21:34:03 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.51 2004/08/13 14:47:23 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "copy.h"
@@ -513,7 +513,8 @@ do_copy(const char *args)
 		appendPQExpBuffer(&query, " FORCE NOT NULL %s", options->force_notnull_list);
 	}
 
-	canonicalize_path(options->file);
+	if (options->file)
+		canonicalize_path(options->file);
 
 	if (options->from)
 	{
diff --git a/src/port/path.c b/src/port/path.c
index 50f6476f427..7e99ec80adc 100644
--- a/src/port/path.c
+++ b/src/port/path.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/port/path.c,v 1.29 2004/08/12 19:03:44 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/port/path.c,v 1.30 2004/08/13 14:47:23 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -335,7 +335,7 @@ set_pglocale_pgservice(const char *argv0, const char *app)
 {
 	char path[MAXPGPATH];
 	char my_exec_path[MAXPGPATH];
-	char env_path[MAXPGPATH + sizeof("PGLOCALEDIR=")]; /* longer than PGSYSCONFDIR */
+	char env_path[MAXPGPATH + sizeof("PGSYSCONFDIR=")]; /* longer than PGLOCALEDIR */
 
 	/* don't set LC_ALL in the backend */
 	if (strcmp(app, "postgres") != 0)
@@ -353,7 +353,7 @@ set_pglocale_pgservice(const char *argv0, const char *app)
 	{
 		/* set for libpq to use */
 		snprintf(env_path, sizeof(env_path), "PGLOCALEDIR=%s", path);
-		canonicalize_path(env_path);
+		canonicalize_path(env_path + 12);
 		putenv(strdup(env_path));
 	}
 #endif
@@ -364,7 +364,7 @@ set_pglocale_pgservice(const char *argv0, const char *app)
 	
 		/* set for libpq to use */
 		snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path);
-		canonicalize_path(env_path);
+		canonicalize_path(env_path + 13);
 		putenv(strdup(env_path));
 	}
 }
-- 
GitLab