Avoid masking EOF (no-password-supplied) conditions in auth.c.
authorTom Lane <[email protected]>
Wed, 3 Jan 2024 22:40:38 +0000 (17:40 -0500)
committerTom Lane <[email protected]>
Wed, 3 Jan 2024 22:40:38 +0000 (17:40 -0500)
CheckPWChallengeAuth() would return STATUS_ERROR if the user does not
exist or has no password assigned, even if the client disconnected
without responding to the password challenge (as libpq often will,
for example).  We should return STATUS_EOF in that case, and the
lower-level functions do, but this code level got it wrong since the
refactoring done in 7ac955b34.  This breaks the intent of not logging
anything for EOF cases (cf. comments in auth_failed()) and might
also confuse users of ClientAuthentication_hook.

Per report from Liu Lang.  Back-patch to all supported versions.

Discussion: https://postgr.es/m/b725238c-539d-cb09-2bff-b5e6cb2c069c@esgyn.cn

src/backend/libpq/auth.c

index be14f2f16dd76fce1fb68bd020131d289339722e..70f2e2c0dabd1b304971aa229f073f25b2c4856e 100644 (file)
@@ -857,15 +857,13 @@ CheckPWChallengeAuth(Port *port, char **logdetail)
 
    if (shadow_pass)
        pfree(shadow_pass);
-
-   /*
-    * If get_role_password() returned error, return error, even if the
-    * authentication succeeded.
-    */
-   if (!shadow_pass)
+   else
    {
+       /*
+        * If get_role_password() returned error, authentication better not
+        * have succeeded.
+        */
        Assert(auth_result != STATUS_OK);
-       return STATUS_ERROR;
    }
 
    if (auth_result == STATUS_OK)