summaryrefslogtreecommitdiffstats
path: root/crypto/http
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-06-21 08:55:50 +0200
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-11-17 15:48:34 +0100
commit2ff286c26c29b69b02ca99656d26d2f8cfd54682 (patch)
tree71a01c51c47d0dd9528ff14357615d71420ba5a1 /crypto/http
parenta6838c8d52087f2b0494bbab8486e10944aff7f7 (diff)
Add and use HAS_PREFIX() and CHECK_AND_SKIP_PREFIX() for checking if string has literal prefix
Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15847)
Diffstat (limited to 'crypto/http')
-rw-r--r--crypto/http/http_client.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/crypto/http/http_client.c b/crypto/http/http_client.c
index bb80836cd1..9d66d7b75b 100644
--- a/crypto/http/http_client.c
+++ b/crypto/http/http_client.c
@@ -23,7 +23,6 @@
#include "internal/sockets.h"
#include "internal/cryptlib.h" /* for ossl_assert() */
-#define HAS_PREFIX(str, prefix) (strncmp(str, prefix, sizeof(prefix) - 1) == 0)
#define HTTP_PREFIX "HTTP/"
#define HTTP_VERSION_PATT "1." /* allow 1.x */
#define HTTP_VERSION_STR_LEN sizeof(HTTP_VERSION_PATT) /* == strlen("1.0") */
@@ -377,10 +376,10 @@ static int parse_http_line1(char *line, int *found_keep_alive)
int i, retcode;
char *code, *reason, *end;
- if (!HAS_PREFIX(line, HTTP_PREFIX_VERSION))
+ if (!CHECK_AND_SKIP_PREFIX(line, HTTP_PREFIX_VERSION))
goto err;
/* above HTTP 1.0, connection persistence is the default */
- *found_keep_alive = line[strlen(HTTP_PREFIX_VERSION)] > '0';
+ *found_keep_alive = *line > '0';
/* Skip to first whitespace (past protocol info) */
for (code = line; *code != '\0' && !ossl_isspace(*code); code++)
@@ -1297,15 +1296,15 @@ int OSSL_HTTP_proxy_connect(BIO *bio, const char *server, const char *port,
continue;
/* Check for HTTP/1.x */
- if (!HAS_PREFIX(mbuf, HTTP_PREFIX) != 0) {
+ mbufp = mbuf;
+ if (!HAS_PREFIX(mbufp, HTTP_PREFIX)) {
ERR_raise(ERR_LIB_HTTP, HTTP_R_HEADER_PARSE_ERROR);
BIO_printf(bio_err, "%s: HTTP CONNECT failed, non-HTTP response\n",
prog);
/* Wrong protocol, not even HTTP, so stop reading headers */
goto end;
}
- mbufp = mbuf + strlen(HTTP_PREFIX);
- if (!HAS_PREFIX(mbufp, HTTP_VERSION_PATT) != 0) {
+ if (!HAS_PREFIX(mbufp, HTTP_VERSION_PATT)) {
ERR_raise(ERR_LIB_HTTP, HTTP_R_RECEIVED_WRONG_HTTP_VERSION);
BIO_printf(bio_err,
"%s: HTTP CONNECT failed, bad HTTP version %.*s\n",