From 4814035b62346ead523fc018230e7bd8f01170d6 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 12 Jan 2023 11:47:48 +0100 Subject: [PATCH] Fix echo Makefile bug --- Makefile | 2 +- src/lib/proxy.c | 4 +++- src/worker/proxy_handler.c | 2 +- src/worker/request_handler.c | 8 ++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7bf026b..a13c051 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ bin/res/%.o: bin/res/%.txt bin/res/%.txt: res/%.* cp $^ $@ - echo -ne "\x00" >> $@ + /bin/echo -ne "\x00" >> $@ bin/sesimos: bin/server.o bin/logger.o bin/cache_handler.o bin/async.o bin/workers.o \ bin/worker/request_handler.o bin/worker/tcp_acceptor.o \ diff --git a/src/lib/proxy.c b/src/lib/proxy.c index 624bd72..905577c 100644 --- a/src/lib/proxy.c +++ b/src/lib/proxy.c @@ -671,7 +671,9 @@ int proxy_send(proxy_ctx_t *proxy, sock *client, unsigned long len_to_send, int } int proxy_dump(proxy_ctx_t *proxy, char *buf, long len) { - sock_recv(&proxy->proxy, buf, len, 0); + long ret = sock_recv(&proxy->proxy, buf, len, 0); + if (ret == -1) return -1; + buf[ret] = 0; return 0; } diff --git a/src/worker/proxy_handler.c b/src/worker/proxy_handler.c index 5984f10..6c75dab 100644 --- a/src/worker/proxy_handler.c +++ b/src/worker/proxy_handler.c @@ -89,7 +89,7 @@ static int proxy_handler_1(client_ctx_t *ctx) { (content_length_f != NULL && strstarts(content_type, "text/html")))) { long content_len = (!streq(ctx->req.method, "HEAD") && content_length_f != NULL) ? strtol(content_length_f, NULL, 10) : 0; - if (content_len <= sizeof(ctx->msg_content) - 1) { + if (content_len < sizeof(ctx->msg_content)) { if (status->status != 101) { status->status = res->status->code; status->origin = res->status->code >= 400 ? SERVER : NONE; diff --git a/src/worker/request_handler.c b/src/worker/request_handler.c index e3568fb..d6c1481 100644 --- a/src/worker/request_handler.c +++ b/src/worker/request_handler.c @@ -300,10 +300,10 @@ int respond(client_ctx_t *ctx) { ctx->msg_buf_ptr = malloc(4096); ctx->msg_buf = ctx->msg_buf_ptr; snprintf(msg_pre_buf_1, sizeof(msg_pre_buf_1), http_info->doc, - res->status->code, res->status->msg, http_msg != NULL ? http_msg->msg : "", err_msg[0] != 0 ? err_msg : ""); - ctx->content_length = snprintf(ctx->msg_buf, 4096, http_default_doc, res->status->code, - res->status->msg, msg_pre_buf_1, http_info->mode, http_info->icon, http_info->color, ctx->req_host, - proxy_doc, ctx->msg_content[0] != 0 ? ctx->msg_content : "", SERVER_STR_HTML); + res->status->code, res->status->msg, http_msg != NULL ? http_msg->msg : "", err_msg); + ctx->content_length = snprintf(ctx->msg_buf, 4096, http_default_doc, res->status->code, res->status->msg, + msg_pre_buf_1, http_info->mode, http_info->icon, http_info->color, + ctx->req_host, proxy_doc, ctx->msg_content, SERVER_STR_HTML); } if (ctx->content_length >= 0) { sprintf(buf0, "%li", ctx->content_length);