From a4fa68edc043e1cb9b8acf36bdcfec7068c9dd29 Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Wed, 2 Mar 2022 19:52:20 +0000 Subject: 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(-) (limited to 'usr.sbin') 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, -- cgit v1.2.3