[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 77/220: quiche: improved error handling and memory
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 77/220: quiche: improved error handling and memory cleanups |
Date: |
Thu, 12 Sep 2019 17:27:17 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit 07828b1c9ddc6483582054f13f5c3162e9b1f04f
Author: Daniel Stenberg <address@hidden>
AuthorDate: Wed Aug 7 08:39:39 2019 +0200
quiche: improved error handling and memory cleanups
---
lib/vquic/quiche.c | 68 ++++++++++++++++++++++++++++++++++++++----------------
lib/vquic/quiche.h | 2 +-
2 files changed, 49 insertions(+), 21 deletions(-)
diff --git a/lib/vquic/quiche.c b/lib/vquic/quiche.c
index 4362ba98c..0df930d31 100644
--- a/lib/vquic/quiche.c
+++ b/lib/vquic/quiche.c
@@ -87,8 +87,12 @@ static int quiche_perform_getsock(const struct connectdata
*conn,
static CURLcode quiche_disconnect(struct connectdata *conn,
bool dead_connection)
{
- (void)conn;
+ struct quicsocket *qs = &conn->quic;
(void)dead_connection;
+ quiche_h3_config_free(qs->h3config);
+ quiche_h3_conn_free(qs->h3c);
+ quiche_config_free(qs->cfg);
+ quiche_conn_free(qs->conn);
return CURLE_OK;
}
@@ -129,11 +133,11 @@ CURLcode Curl_quic_connect(struct connectdata *conn,
curl_socket_t sockfd,
(void)addr;
(void)addrlen;
- infof(conn->data, "Connecting socket %d over QUIC\n", sockfd);
-
qs->cfg = quiche_config_new(QUICHE_PROTOCOL_VERSION);
- if(!qs->cfg)
- return CURLE_FAILED_INIT; /* TODO: better return code */
+ if(!qs->cfg) {
+ failf(conn->data, "can't create quiche config");
+ return CURLE_FAILED_INIT;
+ }
quiche_config_set_idle_timeout(qs->cfg, QUIC_IDLE_TIMEOUT);
quiche_config_set_initial_max_data(qs->cfg, QUIC_MAX_DATA);
@@ -155,12 +159,14 @@ CURLcode Curl_quic_connect(struct connectdata *conn,
curl_socket_t sockfd,
qs->conn = quiche_connect(conn->host.name, (const uint8_t *) qs->scid,
sizeof(qs->scid), qs->cfg);
- if(!qs->conn)
- return CURLE_FAILED_INIT; /* TODO: better return code */
+ if(!qs->conn) {
+ failf(conn->data, "can't create quiche connection");
+ return CURLE_OUT_OF_MEMORY;
+ }
result = flush_egress(conn, sockfd);
if(result)
- return CURLE_FAILED_INIT; /* TODO: better return code */
+ return result;
infof(conn->data, "Sent QUIC client Initial, ALPN: %s\n",
QUICHE_H3_APPLICATION_PROTOCOL + 1);
@@ -225,6 +231,10 @@ static CURLcode process_ingress(struct connectdata *conn,
int sockfd)
return CURLE_OK;
}
+/*
+ * flush_egress drains the buffers and sends off data.
+ * Calls failf() on errors.
+ */
static CURLcode flush_egress(struct connectdata *conn, int sockfd)
{
ssize_t sent;
@@ -236,12 +246,17 @@ static CURLcode flush_egress(struct connectdata *conn,
int sockfd)
if(sent == QUICHE_ERR_DONE)
break;
- if(sent < 0)
+ if(sent < 0) {
+ failf(conn->data, "quiche_conn_send returned %zd\n",
+ sent);
return CURLE_SEND_ERROR;
+ }
sent = send(sockfd, out, sent, 0);
- if(sent < 0)
+ if(sent < 0) {
+ failf(conn->data, "send() returned %zd\n", sent);
return CURLE_SEND_ERROR;
+ }
} while(1);
return CURLE_OK;
@@ -431,17 +446,22 @@ static CURLcode http_request(struct connectdata *conn,
const void *mem,
int64_t stream3_id;
quiche_h3_header *nva = NULL;
struct quicsocket *qs = &conn->quic;
+ CURLcode result = CURLE_OK;
#ifdef DEBUG_HTTP3
quiche_enable_debug_logging(debug_log, NULL);
#endif
- qs->config = quiche_h3_config_new(0, 1024, 0, 0);
- /* TODO: handle failure */
+ qs->h3config = quiche_h3_config_new(0, 1024, 0, 0);
+ if(!qs->h3config)
+ return CURLE_OUT_OF_MEMORY;
/* Create a new HTTP/3 connection on the QUIC connection. */
- qs->h3c = quiche_h3_conn_new_with_transport(qs->conn, qs->config);
- /* TODO: handle failure */
+ qs->h3c = quiche_h3_conn_new_with_transport(qs->conn, qs->h3config);
+ if(!qs->h3c) {
+ result = CURLE_OUT_OF_MEMORY;
+ goto fail;
+ }
/* Calculate number of headers contained in [mem, mem + len). Assumes a
correctly generated HTTP header field block. */
@@ -460,14 +480,18 @@ static CURLcode http_request(struct connectdata *conn,
const void *mem,
more space. */
nheader += 1;
nva = malloc(sizeof(quiche_h3_header) * nheader);
- if(!nva)
- return CURLE_OUT_OF_MEMORY;
+ if(!nva) {
+ result = CURLE_OUT_OF_MEMORY;
+ goto fail;
+ }
/* Extract :method, :path from request line
We do line endings with CRLF so checking for CR is enough */
line_end = memchr(hdbuf, '\r', len);
- if(!line_end)
+ if(!line_end) {
+ result = CURLE_BAD_FUNCTION_ARGUMENT; /* internal error */
goto fail;
+ }
/* Method does not contain spaces */
end = memchr(hdbuf, ' ', line_end - hdbuf);
@@ -615,8 +639,10 @@ static CURLcode http_request(struct connectdata *conn,
const void *mem,
Curl_safefree(nva);
if(stream3_id < 0) {
- H3BUGF(infof(conn->data, "http3_send() send error\n"));
- return CURLE_SEND_ERROR;
+ H3BUGF(infof(conn->data, "quiche_h3_send_request returned %d\n",
+ stream3_id));
+ result = CURLE_SEND_ERROR;
+ goto fail;
}
infof(conn->data, "Using HTTP/3 Stream ID: %x (easy handle %p)\n",
@@ -626,8 +652,10 @@ static CURLcode http_request(struct connectdata *conn,
const void *mem,
return CURLE_OK;
fail:
+ quiche_h3_config_free(qs->h3config);
+ quiche_h3_conn_free(qs->h3c);
free(nva);
- return CURLE_SEND_ERROR;
+ return result;
}
diff --git a/lib/vquic/quiche.h b/lib/vquic/quiche.h
index b09359ac3..c8d1837b5 100644
--- a/lib/vquic/quiche.h
+++ b/lib/vquic/quiche.h
@@ -39,7 +39,7 @@ struct quicsocket {
quiche_config *cfg;
quiche_conn *conn;
quiche_h3_conn *h3c;
- quiche_h3_config *config;
+ quiche_h3_config *h3config;
uint8_t scid[QUICHE_MAX_CONN_ID_LEN];
uint32_t version;
};
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [GNUnet-SVN] [gnurl] 87/220: docs/ALTSVC: remove what works and the experimental explanation, (continued)
- [GNUnet-SVN] [gnurl] 87/220: docs/ALTSVC: remove what works and the experimental explanation, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 102/220: configure: avoid undefined check_for_ca_bundle, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 51/220: md4: Use the Curl_md4it() function for OpenSSL based NTLM, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 56/220: md4: No need to include Curl_md4.h for each TLS library, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 53/220: md4: Move the WinCrypt implementation out of the NTLM code, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 54/220: md4: Move the mbed TLS MD4 implementation out of the NTLM code, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 59/220: altsvc: fix removal of expired cache entry, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 58/220: RELEASE-NOTES: synced, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 69/220: docs/HTTP3: refreshed as it is now in master and HTTP/3 can be tested, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 78/220: quiche: make POSTFIELDS posts work, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 77/220: quiche: improved error handling and memory cleanups,
gnunet <=
- [GNUnet-SVN] [gnurl] 67/220: curl_multi_poll: a sister to curl_multi_wait() that waits more, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 70/220: sasl: Implement SASL authorisation identity via CURLOPT_SASL_AUTHZID, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 71/220: curl: --sasl-authzid added to support CURLOPT_SASL_AUTHZID from the tool, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 99/220: curl_global_init_mem.3: mention it was added in 7.12.0, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 93/220: cleanup: s/curl_debug/curl_dbg_debug in comments and docs, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 94/220: quiche: add SSLKEYLOGFILE support, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 103/220: asyn-thread: issue CURL_POLL_REMOVE before closing socket, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 95/220: http3: make connection reuse work, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 105/220: nghttp3: initial h3 template code added, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 109/220: HTTP3: use ngtcp2's draft-22 branch, gnunet, 2019/09/12