Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uX5K2-005ZlK-Vl for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 21:48:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uX5K0-005vtL-DK for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 21:48:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uX5K0-005vtD-29 for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 21:48:52 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uX5Jy-005NaR-1L for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 21:48:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 562LmkDU3793880; Wed, 2 Jul 2025 17:48:46 -0400 From: Tom Lane To: Peter Eisentraut cc: Jianghua Yang , pgsql-hackers@lists.postgresql.org Subject: Re: [PATCH] initdb: Treat empty -U argument as unset username In-reply-to: References: Comments: In-reply-to Peter Eisentraut message dated "Wed, 02 Jul 2025 16:39:22 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3793878.1751492926.1@sss.pgh.pa.us> Date: Wed, 02 Jul 2025 17:48:46 -0400 Message-ID: <3793879.1751492926@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Eisentraut writes: > ... The aclitem parsing ends up in getid() > in src/backend/utils/adt/acl.c, which thinks that an input string > consisting entirely of "" is an escaped double quote. Yeah, that is definitely broken, and also it occurs to me that this coding is not robust in the face of non-ASCII identifiers (since the behavior of isalnum is unportable in that case). I've posted a draft patch for that in a separate thread [1]. > Maybe it's worth fixing that, and making putid() also print empty user > names correspondingly. putid() prints an empty name as an empty string, which seems fine at least at this level. > Alternatively, it's the fault of initdb that it constructs aclitem > values that don't follow the aclitem-specific quoting rules. With the patch at [1], initdb -U '' still fails at the same place, but now with FATAL: a name must follow the "/" sign at character 72 which is a consequence of getid()'s output not distinguishing "I found nothing" from "I found an empty string". Now if we cared to support empty identifiers, we could make some more revisions here so that those were consistently represented as "" rather than nothing. But I fail to see that that's a useful expenditure of time: we're never going to allow empty names. > Another thought is, if we don't allow zero-length names, shouldn't > namein() reject empty input strings? I'm inclined to think not. It's introducing too much of a gotcha for too little return. As a perhaps-not-quite-exact analogy, NULL::name also doesn't correspond to any identifier you can spell in SQL; but we're not going to try to forbid that value. So there is at least one value of type "name" that isn't valid in SQL, and I don't see why ''::name can't be another. regards, tom lane [1] https://www.postgresql.org/message-id/3792884.1751492172%40sss.pgh.pa.us