Skip to content

initdb: Reject empty string for -U/--username option#1209

Merged
yjhjstz merged 1 commit intoapache:mainfrom
yjhjstz:fix_initdb
Jul 4, 2025
Merged

initdb: Reject empty string for -U/--username option#1209
yjhjstz merged 1 commit intoapache:mainfrom
yjhjstz:fix_initdb

Conversation

@yjhjstz
Copy link
Member

@yjhjstz yjhjstz commented Jul 2, 2025

performing post-bootstrap initialization ... 2025-07-01 19:48:42.006 PDT [14888] FATAL:  role """ does not exist at character 72

2025-07-01 19:48:42.006 PDT [14888] STATEMENT:  

	UPDATE pg_class   SET relacl = (SELECT array_agg(a.acl) FROM  (SELECT E'=r/""' as acl   UNION SELECT unnest(pg_catalog.acldefault(    CASE WHEN relkind = 'S' THEN 's'          ELSE 'r' END::"char",10::oid)) ) as a)   WHERE relkind IN ('r', 'v', 'm', 'S')  AND relacl IS NULL;

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.

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


Copy link
Contributor

@my-ship-it my-ship-it left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@reshke
Copy link
Contributor

reshke commented Jul 4, 2025

The only question here is how this works in PostgreSQL and why this is not an issue for pg (or is it?)

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.
@yjhjstz
Copy link
Member Author

yjhjstz commented Jul 4, 2025

The only question here is how this works in PostgreSQL and why this is not an issue for pg (or is it?)

yes , I also submit a patch. https://www.postgresql.org/message-id/CAAZLFmRK+XFp=mqCeruyNVkqGq5mH45CP+e-8oNttPRtLuB5eQ@mail.gmail.com

@yjhjstz yjhjstz merged commit ffce584 into apache:main Jul 4, 2025
26 checks passed
@yjhjstz yjhjstz deleted the fix_initdb branch November 17, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants