Commit 74b75899 authored by Marko Mikulicic's avatar Marko Mikulicic Committed by Cesanta Bot

Make cc3200 sprintf workaround smaller

in light of the root cause discovered by rojer
and addressed in cesanta/dev#5882 for the http connection code path.

PUBLISHED_FROM=aea563150a0411cbe3fdc6f7911529f3136cc76f
parent 240eca0b
......@@ -8791,7 +8791,6 @@ void mg_send_websocket_handshake3(struct mg_connection *nc, const char *path,
const char *extra_headers, const char *user,
const char *pass) {
struct mbuf auth;
const char *authstr = "";
char key[25];
uint32_t nonce[4];
nonce[0] = mg_ws_random_mask();
......@@ -8803,25 +8802,22 @@ void mg_send_websocket_handshake3(struct mg_connection *nc, const char *path,
mbuf_init(&auth, 0);
if (user != NULL) {
mg_basic_auth_header(user, pass, &auth);
}
/*
* cc3200 libc is broken: it doesn't like zero length to be passed to %.*s
* i.e. sprintf("f%.*so", (int)0, ""), yields `f\0o`.
* Thus we ensure the header fragment is null terminated and use `%s` below.
* NOTE: the (auth.buf == NULL ? "" : auth.buf) is because cc3200 libc is
* broken: it doesn't like zero length to be passed to %.*s
* i.e. sprintf("f%.*so", (int)0, NULL), yields `f\0o`.
* because it handles NULL specially (and incorrectly).
*/
mbuf_append(&auth, "", 1);
authstr = auth.buf;
}
mg_printf(nc,
"GET %s HTTP/1.1\r\n"
"Upgrade: websocket\r\n"
"Connection: Upgrade\r\n"
"%s"
"%.*s"
"Sec-WebSocket-Version: 13\r\n"
"Sec-WebSocket-Key: %s\r\n",
path, authstr, key);
path, (int) auth.len, (auth.buf == NULL ? "" : auth.buf), key);
/* TODO(mkm): take default hostname from http proto data if host == NULL */
if (host != MG_WS_NO_HOST_HEADER_MAGIC) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment