This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/main by this push:
     new ffce58412af initdb: Reject empty string for -U/--username option
ffce58412af is described below

commit ffce58412afd4abb0775d37c157462813f0a4860
Author: Jianghua Yang <[email protected]>
AuthorDate: Wed Jul 2 13:17:36 2025 -0700

    initdb: Reject empty string for -U/--username option
    
    Previously, passing an empty string to the -U or --username option
    (e.g., `initdb -U ''`) would cause confusing errors during bootstrap,
    as initdb attempted to create a role with an empty name.
    
    This patch adds an explicit check for empty usernames and exits
    immediately with a clear error message.
    
    A test case is added to verify that initdb fails when -U is given an
    empty string.
---
 src/bin/initdb/initdb.c        | 5 +++++
 src/bin/initdb/t/001_initdb.pl | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 42c22a0690a..53c3a82a45e 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -3391,6 +3391,11 @@ main(int argc, char *argv[])
                                pwprompt = true;
                                break;
                        case 'U':
+                               if (optarg[0] == '\0')
+                               {
+                                       pg_log_error("superuser name must not 
be empty.");
+                                       exit(1);
+                               }
                                username = pg_strdup(optarg);
                                break;
                        case 'd':
diff --git a/src/bin/initdb/t/001_initdb.pl b/src/bin/initdb/t/001_initdb.pl
index 635ff79b475..b5f3cd632da 100644
--- a/src/bin/initdb/t/001_initdb.pl
+++ b/src/bin/initdb/t/001_initdb.pl
@@ -38,6 +38,11 @@ command_fails(
        [ 'initdb', '-U', 'pg_test', $datadir ],
        'role names cannot begin with "pg_"');
 
+command_fails_like(
+       [ 'initdb', '--username' => '', $datadir ],
+       qr/superuser name must not be empty./,
+       'empty username not allowed');
+
 mkdir $datadir;
 
 # make sure we run one successful test without a TZ setting so we test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to