diff options
Diffstat (limited to 'src/interfaces/libpq')
| -rw-r--r-- | src/interfaces/libpq/fe-connect.c | 85 | ||||
| -rw-r--r-- | src/interfaces/libpq/fe-exec.c | 117 | ||||
| -rw-r--r-- | src/interfaces/libpq/fe-secure.c | 33 | ||||
| -rw-r--r-- | src/interfaces/libpq/libpq-fe.h | 6 | ||||
| -rw-r--r-- | src/interfaces/libpq/libpq-int.h | 11 |
5 files changed, 124 insertions, 128 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 89e61a7ec7..9302e28782 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.387 2010/02/17 04:19:41 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.388 2010/02/26 02:01:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -228,7 +228,7 @@ static const PQconninfoOption PQconninfoOptions[] = { #endif {"replication", NULL, NULL, NULL, - "Replication", "D", 5}, + "Replication", "D", 5}, /* Terminating entry --- MUST BE LAST */ {NULL, NULL, NULL, NULL, @@ -268,8 +268,8 @@ static void closePGconn(PGconn *conn); static PQconninfoOption *conninfo_parse(const char *conninfo, PQExpBuffer errorMessage, bool use_defaults); static PQconninfoOption *conninfo_array_parse(const char **keywords, - const char **values, PQExpBuffer errorMessage, - bool use_defaults, int expand_dbname); + const char **values, PQExpBuffer errorMessage, + bool use_defaults, int expand_dbname); static char *conninfo_getval(PQconninfoOption *connOptions, const char *keyword); static void defaultNoticeReceiver(void *arg, const PGresult *res); @@ -277,10 +277,10 @@ static void defaultNoticeProcessor(void *arg, const char *message); static int parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage); static int parseServiceFile(const char *serviceFile, - const char *service, - PQconninfoOption *options, - PQExpBuffer errorMessage, - bool *group_found); + const char *service, + PQconninfoOption *options, + PQExpBuffer errorMessage, + bool *group_found); static char *pwdfMatchesString(char *buf, char *token); static char *PasswordFromFile(char *hostname, char *port, char *dbname, char *username); @@ -306,7 +306,7 @@ pgthreadlock_t pg_g_threadlock = default_threadlock; * terminated arrays instead. * * To connect in an asynchronous (non-blocking) manner, use the functions - * PQconnectStart or PQconnectStartParams (which differ in the same way as + * PQconnectStart or PQconnectStartParams (which differ in the same way as * PQconnectdb and PQconnectdbParams) and PQconnectPoll. * * Internally, the static functions connectDBStart, connectDBComplete @@ -406,8 +406,8 @@ PQconnectStartParams(const char **keywords, const char **values, int expand_dbname) { - PGconn *conn; - PQconninfoOption *connOptions; + PGconn *conn; + PQconninfoOption *connOptions; /* * Allocate memory for the conn structure @@ -432,7 +432,7 @@ PQconnectStartParams(const char **keywords, /* * Move option values into conn structure */ - fillPGconn(conn, connOptions); + fillPGconn(conn, connOptions); /* * Free the option info - all is in conn now @@ -609,7 +609,7 @@ connectOptions1(PGconn *conn, const char *conninfo) /* * Move option values into conn structure */ - fillPGconn(conn, connOptions); + fillPGconn(conn, connOptions); /* * Free the option info - all is in conn now @@ -1326,9 +1326,9 @@ keep_going: /* We will come back to here until there is * We have three methods of blocking SIGPIPE during * send() calls to this socket: * - * - setsockopt(sock, SO_NOSIGPIPE) - * - send(sock, ..., MSG_NOSIGNAL) - * - setting the signal mask to SIG_IGN during send() + * - setsockopt(sock, SO_NOSIGPIPE) + * - send(sock, ..., MSG_NOSIGNAL) + * - setting the signal mask to SIG_IGN during send() * * The third method requires three syscalls per send, * so we prefer either of the first two, but they are @@ -1350,7 +1350,7 @@ keep_going: /* We will come back to here until there is conn->sigpipe_flag = true; #else conn->sigpipe_flag = false; -#endif /* MSG_NOSIGNAL */ +#endif /* MSG_NOSIGNAL */ #ifdef SO_NOSIGPIPE optval = 1; @@ -1360,7 +1360,7 @@ keep_going: /* We will come back to here until there is conn->sigpipe_so = true; conn->sigpipe_flag = false; } -#endif /* SO_NOSIGPIPE */ +#endif /* SO_NOSIGPIPE */ /* * Start/make connection. This should not block, since we @@ -2034,7 +2034,7 @@ keep_going: /* We will come back to here until there is /* * If we tried to send application_name, check to see * if the error is about that --- pre-9.0 servers will - * reject it at this stage of the process. If so, + * reject it at this stage of the process. If so, * close the connection and retry without sending * application_name. We could possibly get a false * SQLSTATE match here and retry uselessly, but there @@ -2124,7 +2124,7 @@ keep_going: /* We will come back to here until there is default: appendPQExpBuffer(&conn->errorMessage, libpq_gettext("invalid connection state %d, " - "probably indicative of memory corruption\n"), + "probably indicative of memory corruption\n"), conn->status); goto error_return; } @@ -3266,6 +3266,7 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage) return status; next_file: + /* * This could be used by any application so we can't use the binary * location to find our config files. @@ -3284,7 +3285,7 @@ last_file: if (!group_found) { printfPQExpBuffer(errorMessage, - libpq_gettext("definition of service \"%s\" not found\n"), service); + libpq_gettext("definition of service \"%s\" not found\n"), service); return 3; } @@ -3297,7 +3298,7 @@ parseServiceFile(const char *serviceFile, PQconninfoOption *options, PQExpBuffer errorMessage, bool *group_found) -{ +{ int linenr = 0, i; FILE *f; @@ -3320,7 +3321,7 @@ parseServiceFile(const char *serviceFile, { fclose(f); printfPQExpBuffer(errorMessage, - libpq_gettext("line %d too long in service file \"%s\"\n"), + libpq_gettext("line %d too long in service file \"%s\"\n"), linenr, serviceFile); return 2; @@ -3359,8 +3360,7 @@ parseServiceFile(const char *serviceFile, if (*group_found) { /* - * Finally, we are in the right group and can parse - * the line + * Finally, we are in the right group and can parse the line */ char *key, *val; @@ -3745,20 +3745,20 @@ conninfo_array_parse(const char **keywords, const char **values, PQExpBuffer errorMessage, bool use_defaults, int expand_dbname) { - char *tmp; - PQconninfoOption *options; - PQconninfoOption *str_options = NULL; - PQconninfoOption *option; - int i = 0; + char *tmp; + PQconninfoOption *options; + PQconninfoOption *str_options = NULL; + PQconninfoOption *option; + int i = 0; /* - * If expand_dbname is non-zero, check keyword "dbname" - * to see if val is actually a conninfo string + * If expand_dbname is non-zero, check keyword "dbname" to see if val is + * actually a conninfo string */ - while(expand_dbname && keywords[i]) + while (expand_dbname && keywords[i]) { const char *pname = keywords[i]; - const char *pvalue = values[i]; + const char *pvalue = values[i]; /* first find "dbname" if any */ if (strcmp(pname, "dbname") == 0) @@ -3767,10 +3767,9 @@ conninfo_array_parse(const char **keywords, const char **values, if (pvalue && strchr(pvalue, '=')) { /* - * Must be a conninfo string, so parse it, but do not - * use defaults here -- those get picked up later. - * We only want to override for those parameters actually - * passed. + * Must be a conninfo string, so parse it, but do not use + * defaults here -- those get picked up later. We only want to + * override for those parameters actually passed. */ str_options = conninfo_parse(pvalue, errorMessage, false); if (str_options == NULL) @@ -3793,10 +3792,10 @@ conninfo_array_parse(const char **keywords, const char **values, i = 0; /* Parse the keywords/values arrays */ - while(keywords[i]) + while (keywords[i]) { const char *pname = keywords[i]; - const char *pvalue = values[i]; + const char *pvalue = values[i]; if (pvalue != NULL) { @@ -3811,7 +3810,7 @@ conninfo_array_parse(const char **keywords, const char **values, if (option->keyword == NULL) { printfPQExpBuffer(errorMessage, - libpq_gettext("invalid connection option \"%s\"\n"), + libpq_gettext("invalid connection option \"%s\"\n"), pname); PQconninfoFree(options); return NULL; @@ -3819,8 +3818,8 @@ conninfo_array_parse(const char **keywords, const char **values, /* * If we are on the dbname parameter, and we have a parsed - * conninfo string, copy those parameters across, overriding - * any existing previous settings + * conninfo string, copy those parameters across, overriding any + * existing previous settings */ if (strcmp(pname, "dbname") == 0 && str_options) { diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index bded5aedd9..b20587f0e4 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.210 2010/02/17 04:19:41 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.211 2010/02/26 02:01:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -3070,13 +3070,13 @@ static char * PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident) { const char *s; - char *result; - char *rp; - int num_quotes = 0; /* single or double, depending on as_ident */ - int num_backslashes = 0; - int input_len; - int result_size; - char quote_char = as_ident ? '"' : '\''; + char *result; + char *rp; + int num_quotes = 0; /* single or double, depending on as_ident */ + int num_backslashes = 0; + int input_len; + int result_size; + char quote_char = as_ident ? '"' : '\''; /* We must have a connection, else fail immediately. */ if (!conn) @@ -3091,7 +3091,7 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident) ++num_backslashes; else if (IS_HIGHBIT_SET(*s)) { - int charlen; + int charlen; /* Slow path for possible multibyte characters */ charlen = pg_encoding_mblen(conn->client_encoding, s); @@ -3111,7 +3111,7 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident) /* Allocate output buffer. */ input_len = s - str; - result_size = input_len + num_quotes + 3; /* two quotes, plus a NUL */ + result_size = input_len + num_quotes + 3; /* two quotes, plus a NUL */ if (!as_ident && num_backslashes > 0) result_size += num_backslashes + 2; result = rp = (char *) malloc(result_size); @@ -3125,7 +3125,7 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident) /* * If we are escaping a literal that contains backslashes, we use the * escape string syntax so that the result is correct under either value - * of standard_conforming_strings. We also emit a leading space in this + * of standard_conforming_strings. We also emit a leading space in this * case, to guard against the possibility that the result might be * interpolated immediately following an identifier. */ @@ -3143,8 +3143,8 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident) * * We've already verified that the input string is well-formed in the * current encoding. If it contains no quotes and, in the case of - * literal-escaping, no backslashes, then we can just copy it directly - * to the output buffer, adding the necessary quotes. + * literal-escaping, no backslashes, then we can just copy it directly to + * the output buffer, adding the necessary quotes. * * If not, we must rescan the input and process each character * individually. @@ -3167,13 +3167,14 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident) *rp++ = *s; else { - int i = pg_encoding_mblen(conn->client_encoding, s); + int i = pg_encoding_mblen(conn->client_encoding, s); + while (1) { *rp++ = *s; if (--i == 0) break; - ++s; /* for loop will provide the final increment */ + ++s; /* for loop will provide the final increment */ } } } @@ -3391,9 +3392,9 @@ PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen) if (strtext[0] == '\\' && strtext[1] == 'x') { const unsigned char *s; - unsigned char *p; + unsigned char *p; - buflen = (strtextlen - 2)/2; + buflen = (strtextlen - 2) / 2; /* Avoid unportable malloc(0) */ buffer = (unsigned char *) malloc(buflen > 0 ? buflen : 1); if (buffer == NULL) @@ -3403,8 +3404,8 @@ PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen) p = buffer; while (*s) { - char v1, - v2; + char v1, + v2; /* * Bad input is silently ignored. Note that this includes @@ -3422,52 +3423,52 @@ PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen) } else { - /* - * Length of input is max length of output, but add one to avoid - * unportable malloc(0) if input is zero-length. - */ - buffer = (unsigned char *) malloc(strtextlen + 1); - if (buffer == NULL) - return NULL; + /* + * Length of input is max length of output, but add one to avoid + * unportable malloc(0) if input is zero-length. + */ + buffer = (unsigned char *) malloc(strtextlen + 1); + if (buffer == NULL) + return NULL; - for (i = j = 0; i < strtextlen;) - { - switch (strtext[i]) + for (i = j = 0; i < strtextlen;) { - case '\\': - i++; - if (strtext[i] == '\\') - buffer[j++] = strtext[i++]; - else - { - if ((ISFIRSTOCTDIGIT(strtext[i])) && - (ISOCTDIGIT(strtext[i + 1])) && - (ISOCTDIGIT(strtext[i + 2]))) + switch (strtext[i]) + { + case '\\': + i++; + if (strtext[i] == '\\') + buffer[j++] = strtext[i++]; + else { - int byte; - - byte = OCTVAL(strtext[i++]); - byte = (byte <<3) +OCTVAL(strtext[i++]); - byte = (byte <<3) +OCTVAL(strtext[i++]); - buffer[j++] = byte; + if ((ISFIRSTOCTDIGIT(strtext[i])) && + (ISOCTDIGIT(strtext[i + 1])) && + (ISOCTDIGIT(strtext[i + 2]))) + { + int byte; + + byte = OCTVAL(strtext[i++]); + byte = (byte <<3) +OCTVAL(strtext[i++]); + byte = (byte <<3) +OCTVAL(strtext[i++]); + buffer[j++] = byte; + } } - } - /* - * Note: if we see '\' followed by something that isn't a - * recognized escape sequence, we loop around having done - * nothing except advance i. Therefore the something will be - * emitted as ordinary data on the next cycle. Corner case: - * '\' at end of string will just be discarded. - */ - break; + /* + * Note: if we see '\' followed by something that isn't a + * recognized escape sequence, we loop around having done + * nothing except advance i. Therefore the something will + * be emitted as ordinary data on the next cycle. Corner + * case: '\' at end of string will just be discarded. + */ + break; - default: - buffer[j++] = strtext[i++]; - break; + default: + buffer[j++] = strtext[i++]; + break; + } } - } - buflen = j; /* buflen is the length of the dequoted data */ + buflen = j; /* buflen is the length of the dequoted data */ } /* Shrink the buffer to be no larger than necessary */ diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index 25511bea1d..9ffcfff679 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.131 2010/01/02 16:58:12 momjian Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.132 2010/02/26 02:01:33 momjian Exp $ * * NOTES * @@ -159,8 +159,7 @@ struct sigpipe_info pq_reset_sigpipe(&(spinfo).oldsigmask, (spinfo).sigpipe_pending, \ (spinfo).got_epipe); \ } while (0) - -#else /* !ENABLE_THREAD_SAFETY */ +#else /* !ENABLE_THREAD_SAFETY */ #define DECLARE_SIGPIPE_INFO(spinfo) pqsigfunc spinfo = NULL @@ -177,17 +176,14 @@ struct sigpipe_info if (!SIGPIPE_MASKED(conn)) \ pqsignal(SIGPIPE, spinfo); \ } while (0) - -#endif /* ENABLE_THREAD_SAFETY */ - -#else /* WIN32 */ +#endif /* ENABLE_THREAD_SAFETY */ +#else /* WIN32 */ #define DECLARE_SIGPIPE_INFO(spinfo) #define DISABLE_SIGPIPE(conn, spinfo, failaction) #define REMEMBER_EPIPE(spinfo, cond) #define RESTORE_SIGPIPE(conn, spinfo) - -#endif /* WIN32 */ +#endif /* WIN32 */ /* ------------------------------------------------------------ */ /* Procedures common to all secure sessions */ @@ -318,6 +314,7 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len) if (conn->ssl) { int err; + DECLARE_SIGPIPE_INFO(spinfo); /* SSL_read can write to the socket, so we need to disable SIGPIPE */ @@ -401,6 +398,7 @@ ssize_t pqsecure_write(PGconn *conn, const void *ptr, size_t len) { ssize_t n; + DECLARE_SIGPIPE_INFO(spinfo); #ifdef USE_SSL @@ -473,15 +471,14 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len) else #endif { - int flags = 0; + int flags = 0; #ifdef MSG_NOSIGNAL if (conn->sigpipe_flag) flags |= MSG_NOSIGNAL; retry_masked: - -#endif /* MSG_NOSIGNAL */ +#endif /* MSG_NOSIGNAL */ DISABLE_SIGPIPE(conn, spinfo, return -1); @@ -501,7 +498,7 @@ retry_masked: flags = 0; goto retry_masked; } -#endif /* MSG_NOSIGNAL */ +#endif /* MSG_NOSIGNAL */ REMEMBER_EPIPE(spinfo, SOCK_ERRNO == EPIPE); } @@ -764,7 +761,7 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) char *err = SSLerrmessage(); printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("could not initialize SSL engine \"%s\": %s\n"), + libpq_gettext("could not initialize SSL engine \"%s\": %s\n"), engine_str, err); SSLerrfree(err); ENGINE_free(conn->engine); @@ -1268,8 +1265,8 @@ open_client_SSL(PGconn *conn) conn->peer_dn[sizeof(conn->peer_dn) - 1] = '\0'; r = X509_NAME_get_text_by_NID(X509_get_subject_name(conn->peer), - NID_commonName, conn->peer_cn, SM_USER); - conn->peer_cn[SM_USER] = '\0'; /* buffer is SM_USER+1 chars! */ + NID_commonName, conn->peer_cn, SM_USER); + conn->peer_cn[SM_USER] = '\0'; /* buffer is SM_USER+1 chars! */ if (r == -1) { /* Unable to get the CN, set it to blank so it can't be used */ @@ -1278,8 +1275,8 @@ open_client_SSL(PGconn *conn) else { /* - * Reject embedded NULLs in certificate common name to prevent attacks like - * CVE-2009-4034. + * Reject embedded NULLs in certificate common name to prevent attacks + * like CVE-2009-4034. */ if (r != strlen(conn->peer_cn)) { diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index c2698fe257..f32b2d3d5b 100644 --- a/src/interfaces/libpq/libpq-fe.h +++ b/src/interfaces/libpq/libpq-fe.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.151 2010/02/05 03:09:05 joe Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.152 2010/02/26 02:01:33 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -227,13 +227,13 @@ typedef struct pgresAttDesc /* Asynchronous (non-blocking) */ extern PGconn *PQconnectStart(const char *conninfo); extern PGconn *PQconnectStartParams(const char **keywords, - const char **values, int expand_dbname); + const char **values, int expand_dbname); extern PostgresPollingStatusType PQconnectPoll(PGconn *conn); /* Synchronous (blocking) */ extern PGconn *PQconnectdb(const char *conninfo); extern PGconn *PQconnectdbParams(const char **keywords, - const char **values, int expand_dbname); + const char **values, int expand_dbname); extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName, diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h index b19e526634..56ee13dbf6 100644 --- a/src/interfaces/libpq/libpq-int.h +++ b/src/interfaces/libpq/libpq-int.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.148 2010/01/15 09:19:10 heikki Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.149 2010/02/26 02:01:33 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -80,8 +80,7 @@ typedef struct #if (SSLEAY_VERSION_NUMBER >= 0x00907000L) && !defined(OPENSSL_NO_ENGINE) #define USE_SSL_ENGINE #endif - -#endif /* USE_SSL */ +#endif /* USE_SSL */ /* * POSTGRES backend dependent Constants. @@ -397,10 +396,10 @@ struct pg_conn #ifdef USE_SSL_ENGINE ENGINE *engine; /* SSL engine, if any */ #else - void *engine; /* dummy field to keep struct the same - if OpenSSL version changes */ + void *engine; /* dummy field to keep struct the same if + * OpenSSL version changes */ #endif -#endif /* USE_SSL */ +#endif /* USE_SSL */ #ifdef ENABLE_GSS gss_ctx_id_t gctx; /* GSS context */ |
