Skip to content

Commit e685a8e

Browse files
committed
libpq: Small code clarification, and avoid casting away const
1 parent 19dbc34 commit e685a8e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/interfaces/libpq/fe-auth.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,8 @@ static int
739739
pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
740740
{
741741
int ret;
742-
char *crypt_pwd;
742+
char *crypt_pwd = NULL;
743+
const char *pwd_to_send;
743744

744745
/* Encrypt the password if needed. */
745746

@@ -771,21 +772,22 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
771772
free(crypt_pwd);
772773
return STATUS_ERROR;
773774
}
775+
776+
pwd_to_send = crypt_pwd;
774777
break;
775778
}
776779
case AUTH_REQ_PASSWORD:
777-
/* discard const so we can assign it */
778-
crypt_pwd = (char *) password;
780+
pwd_to_send = password;
779781
break;
780782
default:
781783
return STATUS_ERROR;
782784
}
783785
/* Packet has a message type as of protocol 3.0 */
784786
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
785-
ret = pqPacketSend(conn, 'p', crypt_pwd, strlen(crypt_pwd) + 1);
787+
ret = pqPacketSend(conn, 'p', pwd_to_send, strlen(pwd_to_send) + 1);
786788
else
787-
ret = pqPacketSend(conn, 0, crypt_pwd, strlen(crypt_pwd) + 1);
788-
if (areq == AUTH_REQ_MD5)
789+
ret = pqPacketSend(conn, 0, pwd_to_send, strlen(pwd_to_send) + 1);
790+
if (crypt_pwd)
789791
free(crypt_pwd);
790792
return ret;
791793
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy