From c267706eca051be44d29f5f7667086eaa485887a Mon Sep 17 00:00:00 2001 From: tb Date: Wed, 2 Mar 2022 19:52:19 +0000 Subject: [PATCH] Simplify .gz handling a bit Combine strlcpy + strlcat into a single snprintf and remove a few unnecessary parentheses. ok deraadt millert --- usr.sbin/httpd/server_file.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/usr.sbin/httpd/server_file.c b/usr.sbin/httpd/server_file.c index f86d3bb3b35..0027056db0d 100644 --- a/usr.sbin/httpd/server_file.c +++ b/usr.sbin/httpd/server_file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server_file.c,v 1.71 2022/02/27 20:30:30 bluhm Exp $ */ +/* $OpenBSD: server_file.c,v 1.72 2022/03/02 19:52:19 tb Exp $ */ /* * Copyright (c) 2006 - 2017 Reyk Floeter @@ -253,14 +253,11 @@ server_file_request(struct httpd *env, struct client *clt, char *path, if (r != NULL && strstr(r->kv_value, "gzip") != NULL) { /* append ".gz" to path and check existence */ - if (strlcpy(gzpath, path, sizeof(gzpath)) >= - sizeof(gzpath) || - strlcat(gzpath, ".gz", sizeof(gzpath)) >= - sizeof(gzpath)) + ret = snprintf(gzpath, sizeof(gzpath), "%s.gz", path); + if (ret < 0 || (size_t)ret >= sizeof(gzpath)) goto abort; - - if ((access(gzpath, R_OK) == 0) && - (stat(gzpath, &gzst) == 0)) { + if (access(gzpath, R_OK) == 0 && + stat(gzpath, &gzst) == 0) { path = gzpath; st = &gzst; kv_add(&resp->http_headers, -- 2.20.1