[Winpt-commits] r288 - trunk/Src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sat Mar 10 12:02:34 CET 2007
Author: twoaday
Date: 2007-03-10 12:02:33 +0100 (Sat, 10 Mar 2007)
New Revision: 288
Modified:
trunk/Src/ChangeLog
trunk/Src/wptKeyserver.cpp
Log:
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2007-03-10 10:24:36 UTC (rev 287)
+++ trunk/Src/ChangeLog 2007-03-10 11:02:33 UTC (rev 288)
@@ -1,3 +1,9 @@
+2007-03-10 Timo Schulz <twoaday at gmx.net>
+
+ * wptKeyserver.cpp (kserver_recvkey): Use StringBuffer to
+ avoid possible allocation problems.
+ (kserver_seararch_begin): Likewise.
+
2007-03-09 Timo Schulz <twoaday at gmx.net>
* wptClipImportDlg.cpp (print_import_status): Use the fingerprint
Modified: trunk/Src/wptKeyserver.cpp
===================================================================
--- trunk/Src/wptKeyserver.cpp 2007-03-10 10:24:36 UTC (rev 287)
+++ trunk/Src/wptKeyserver.cpp 2007-03-10 11:02:33 UTC (rev 288)
@@ -1,5 +1,5 @@
/* wptKeyserver.cpp - W32 Keyserver Access
- * Copyright (C) 2000-2006 Timo Schulz
+ * Copyright (C) 2000-2007 Timo Schulz
* Copyright (C) 2001 Marco Cunha
*
* This file is part of WinPT.
@@ -13,12 +13,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with WinPT; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -959,10 +954,10 @@
kserver_recvkey (const char *hostname, WORD port, const char *keyid,
char **r_key, size_t *r_keylen)
{
- const char *fmt;
- char *request = NULL;
+ StringBuffer req;
+ const char *reqbuf;
int conn_fd;
- int rc, reqlen;
+ int rc;
if (!port)
port = HKP_PORT;
@@ -971,32 +966,25 @@
if (rc)
goto leave;
- reqlen = strlen (hostname)+32+strlen (keyid)+1;
if (proxy.host && proxy.user && proxy.proto == PROXY_PROTO_HTTP) {
- fmt = "GET http://%s:%d/pks/lookup?op=get&search=%s HTTP/1.0\r\n"
- "Proxy-Authorization: Basic %s\r\n\r\n";
- reqlen =+ strlen (fmt) + strlen (proxy.base64_user)+1;
- request = safe_alloc (reqlen+1);
- _snprintf (request, reqlen, fmt, skip_type_prefix (hostname), port,
- keyid, proxy.base64_user);
+ req = req + "GET http://" + skip_type_prefix (hostname) +
+ ":" + port +
+ "/pks/lookup?op=get&search=" + keyid + " HTTP/1.0\r\n" +
+ "Proxy-Authorization: Basic " + proxy.base64_user + "\r\n\r\n";
}
else if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) {
- fmt = "GET http://%s:%d/pks/lookup?op=get&search=%s HTTP/1.0\r\n\r\n";
- reqlen += strlen (fmt)+1;
- request = safe_alloc (reqlen+1);
- _snprintf (request, reqlen, fmt, skip_type_prefix (hostname),
- port, keyid);
+ req = req + "GET http://" + skip_type_prefix (hostname) +
+ ":" + port + "/pks/lookup?op=get&search=" + keyid +
+ " HTTP/1.0\r\n\r\n";
}
- else {
- fmt = "GET /pks/lookup?op=get&search=%s HTTP/1.0\r\n\r\n";
- reqlen += strlen (fmt)+1;
- request = safe_alloc (reqlen+1);
- _snprintf (request, reqlen, fmt, keyid);
- }
-
- log_debug ("request:\r\n%s\r\n", request);
+ else
+ req = req + "GET /pks/lookup?op=get&search=" + keyid +
+ " HTTP/1.0\r\n\r\n";
- rc = sock_write (conn_fd, request, strlen (request));
+ log_debug ("req:\r\n%s\r\n", req.getBuffer ());
+
+ reqbuf = req.getBuffer ();
+ rc = sock_write (conn_fd, reqbuf, strlen (reqbuf));
if (rc == SOCKET_ERROR) {
rc = WPTERR_WINSOCK_RECVKEY;
goto leave;
@@ -1017,7 +1005,6 @@
leave:
closesocket (conn_fd);
- free_if_alloc (request);
return rc;
}
@@ -1124,12 +1111,13 @@
kserver_search_begin (const char *hostname, WORD port,
const char *pattern, int *conn_fd, size_t *nkeys)
{
- const char *fmt;
- char *request = NULL;
+
+ StringBuffer req;
+ const char *reqbuf;
char *enc_patt = NULL;
char status[128];
int rc, sock_fd;
- int reqlen;
+ int nread;
*conn_fd = 0;
@@ -1138,32 +1126,25 @@
goto leave;
enc_patt = URL_encode (pattern, strlen (pattern), NULL);
- reqlen = strlen (enc_patt) + strlen (hostname) + 32 + 1;
-
if (proxy.host && proxy.user && proxy.proto == PROXY_PROTO_HTTP) {
- fmt = "GET http://%s:%d/pks/lookup?options=mr&op=index&search=%s HTTP/1.0\r\n"
- "Proxy-Authorization: Basic %s\r\n\r\n";
- reqlen += strlen (proxy.base64_user) + strlen (fmt) + 1;
- request = safe_alloc (reqlen+1);
- _snprintf (request, reqlen, fmt, skip_type_prefix (hostname), port,
- enc_patt, proxy.base64_user);
+ req = req + "GET http://" + skip_type_prefix (hostname) + ":" + port +
+ "/pks/lookup?options=mr&op=index&search=" + enc_patt +
+ " HTTP/1.0\r\n"
+ "Proxy-Authorization: Basic " + proxy.base64_user + "\r\n\r\n";
}
else if (proxy.host && proxy.proto == PROXY_PROTO_HTTP) {
- fmt = "GET http://%s:%d/pks/lookup?options=mr&op=index&search=%s HTTP/1.0\r\n\r\n";
- reqlen += strlen (fmt)+1;
- request = safe_alloc (reqlen+1);
- _snprintf (request, reqlen, skip_type_prefix (hostname), port,
- enc_patt);
+ req = req + "GET http://" + skip_type_prefix (hostname) + ":" + port +
+ "/pks/lookup?options=mr&op=index&search=" + enc_patt +
+ " HTTP/1.0\r\n\r\n";
}
else {
- fmt = "GET /pks/lookup?options=mr&op=index&search=%s HTTP/1.0\r\n\r\n";
- reqlen += strlen (fmt)+1;
- request = safe_alloc (reqlen+1);
- _snprintf (request, reqlen, fmt, enc_patt);
+ req = req + "GET /pks/lookup?options=mr&op=index&search=" +
+ enc_patt + " HTTP/1.0\r\n\r\n";
}
-
- log_debug ("kserver_search_begin:\r\n%s\r\n", request);
- if (sock_write (sock_fd, request, strlen (request)) == SOCKET_ERROR) {
+
+ log_debug ("kserver_search_begin:\r\n%s\r\n", req.getBuffer ());
+ reqbuf = req.getBuffer ();
+ if (sock_write (sock_fd, reqbuf, strlen (reqbuf)) == SOCKET_ERROR) {
rc = WPTERR_GENERAL;
goto leave;
}
@@ -1177,7 +1158,7 @@
/* Skip all lines until we reach the "info:" record. */
for (;;) {
- if (sock_getline (sock_fd, status, DIM (status)-1, &reqlen)) {
+ if (sock_getline (sock_fd, status, DIM (status)-1, &nread)) {
log_debug ("kserver_search_begin: retrieving status line failed.\r\n");
closesocket (sock_fd);
sock_fd = 0;
@@ -1193,7 +1174,6 @@
*conn_fd = sock_fd;
leave:
- free_if_alloc (request);
free_if_alloc (enc_patt);
return rc;
}
More information about the Winpt-commits
mailing list