]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix unintentional 'NULL' string literal in pg_upgrade.
authorJeff Davis <jdavis@postgresql.org>
Sun, 6 Apr 2025 16:13:43 +0000 (09:13 -0700)
committerJeff Davis <jdavis@postgresql.org>
Sun, 6 Apr 2025 16:13:43 +0000 (09:13 -0700)
Introduced in 2a083ab807.

Note: backport of commit 945126234b, 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

src/bin/pg_upgrade/pg_upgrade.c

index 4fcd4bac153c099caefb7ba653600d7a31394978..bb5a223e1c6a1401f633b204fc60485bae8dff51 100644 (file)
@@ -408,7 +408,6 @@ set_locale_and_encoding(void)
        char       *datcollate_literal;
        char       *datctype_literal;
        char       *datlocale_literal = NULL;
-       char       *datlocale_src;
        DbLocaleInfo *locale = old_cluster.template0;
 
        prep_status("Setting locale and encoding for new cluster");
@@ -422,10 +421,13 @@ set_locale_and_encoding(void)
        datctype_literal = PQescapeLiteral(conn_new_template1,
                                                                           locale->db_ctype,
                                                                           strlen(locale->db_ctype));
-       datlocale_src = locale->db_locale ? locale->db_locale : "NULL";
-       datlocale_literal = PQescapeLiteral(conn_new_template1,
-                                                                               datlocale_src,
-                                                                               strlen(datlocale_src));
+
+       if (locale->db_locale)
+               datlocale_literal = PQescapeLiteral(conn_new_template1,
+                                                                                       locale->db_locale,
+                                                                                       strlen(locale->db_locale));
+       else
+               datlocale_literal = "NULL";
 
        /* update template0 in new cluster */
        if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1700)
@@ -469,7 +471,8 @@ set_locale_and_encoding(void)
 
        PQfreemem(datcollate_literal);
        PQfreemem(datctype_literal);
-       PQfreemem(datlocale_literal);
+       if (locale->db_locale)
+               PQfreemem(datlocale_literal);
 
        PQfinish(conn_new_template1);