summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-03-15 16:04:45 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-03-15 16:04:45 +0000
commit103655d67086a3377668236662363fa3146fbd32 (patch)
tree7e8ab22895c6b62f8a5098305c44bb41d5d00ddb
parentcc047a445a9b74e38f1f3128545302f26d83ff81 (diff)
downloadpsycopg2-103655d67086a3377668236662363fa3146fbd32.tar.gz
Password scrubbing refactored in a separate functionfix-528
-rw-r--r--psycopg/connection_type.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c
index 26100b2..53e9e0f 100644
--- a/psycopg/connection_type.c
+++ b/psycopg/connection_type.c
@@ -1248,10 +1248,25 @@ static struct PyGetSetDef connectionObject_getsets[] = {
/* initialization and finalization methods */
+static void
+obscure_password(connectionObject *conn)
+{
+ char *pos;
+
+ if (!conn || !conn->dsn) {
+ return;
+ }
+
+ pos = strstr(conn->dsn, "password");
+ if (pos != NULL) {
+ for (pos = pos+9 ; *pos != '\0' && *pos != ' '; pos++)
+ *pos = 'x';
+ }
+}
+
static int
connection_setup(connectionObject *self, const char *dsn, long int async)
{
- char *pos;
int res = -1;
Dprintf("connection_setup: init connection object at %p, "
@@ -1288,15 +1303,11 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
exit:
/* here we obfuscate the password even if there was a connection error */
- pos = strstr(self->dsn, "password");
- if (pos != NULL) {
- for (pos = pos+9 ; *pos != '\0' && *pos != ' '; pos++)
- *pos = 'x';
- }
-
+ obscure_password(self);
return res;
}
+
static int
connection_clear(connectionObject *self)
{