Skip to content

Commit 57467ec

Browse files
committed
Fix unintentional 'NULL' string literal in pg_upgrade.
Introduced in 2a083ab. Note: backport of commit 9451262, which was missed at the time. Discussion: https://postgr.es/m/e852442da35b4f31acc600ed98bbee0f12e65e0c.camel@j-davis.com Reviewed-by: Michael Paquier <michael@paquier.xyz> Backpatch-through: 16
1 parent 1980ec2 commit 57467ec

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ set_locale_and_encoding(void)
383383
char *datcollate_literal;
384384
char *datctype_literal;
385385
char *daticulocale_literal = NULL;
386-
char *daticulocale_src;
387386
DbLocaleInfo *locale = old_cluster.template0;
388387

389388
prep_status("Setting locale and encoding for new cluster");
@@ -397,10 +396,13 @@ set_locale_and_encoding(void)
397396
datctype_literal = PQescapeLiteral(conn_new_template1,
398397
locale->db_ctype,
399398
strlen(locale->db_ctype));
400-
daticulocale_src = locale->db_iculocale ? locale->db_iculocale : "NULL";
401-
daticulocale_literal = PQescapeLiteral(conn_new_template1,
402-
daticulocale_src,
403-
strlen(daticulocale_src));
399+
400+
if (locale->db_iculocale)
401+
daticulocale_literal = PQescapeLiteral(conn_new_template1,
402+
locale->db_iculocale,
403+
strlen(locale->db_iculocale));
404+
else
405+
daticulocale_literal = "NULL";
404406

405407
/* update template0 in new cluster */
406408
if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1500)
@@ -430,7 +432,8 @@ set_locale_and_encoding(void)
430432

431433
PQfreemem(datcollate_literal);
432434
PQfreemem(datctype_literal);
433-
PQfreemem(daticulocale_literal);
435+
if (locale->db_iculocale)
436+
PQfreemem(daticulocale_literal);
434437

435438
PQfinish(conn_new_template1);
436439

0 commit comments

Comments
 (0)