From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id BEB603840C03 for ; Tue, 16 Jun 2020 22:26:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BEB603840C03 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mark@klomp.org Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 86AA4317FC16; Wed, 17 Jun 2020 00:25:59 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 2C34C402412D; Wed, 17 Jun 2020 00:25:58 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH 08/10] debuginfod: Make sure suffix can place zero terminator when copying filename Date: Wed, 17 Jun 2020 00:25:37 +0200 Message-Id: <20200616222539.29109-8-mark@klomp.org> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200616222539.29109-1-mark@klomp.org> References: <20200616222539.29109-1-mark@klomp.org> X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jun 2020 22:26:03 -0000 We need to make sure that we can always place a zero terminator at the end of suffix when we are copying the filename. So add one more char to the suffix array. And make sure that we can always add an extra escape character when we need to escape the current character. Signed-off-by: Mark Wielaard --- debuginfod/ChangeLog | 5 +++++ debuginfod/debuginfod-client.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 66511a3f..9ff2e111 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,8 @@ +2020-06-16 Mark Wielaard + + * debuginfod-client.c (debuginfod_query_server): Increase suffix + array and prepare having to escape 1 character with 2. + 2020-06-16 Mark Wielaard * debuginfod-client.c (debuginfod_clean_cache): Handle failing diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 0cfc6dfc..e9c2ca83 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -474,7 +474,7 @@ debuginfod_query_server (debuginfod_client *c, char *target_cache_dir = NULL; char *target_cache_path = NULL; char *target_cache_tmppath = NULL; - char suffix[PATH_MAX]; + char suffix[PATH_MAX + 1]; /* +1 for zero terminator. */ char build_id_bytes[MAX_BUILD_ID_BYTES * 2 + 1]; int rc; @@ -511,7 +511,7 @@ debuginfod_query_server (debuginfod_client *c, /* copy the filename to suffix, s,/,#,g */ unsigned q = 0; - for (unsigned fi=0; q < PATH_MAX-1; fi++) + for (unsigned fi=0; q < PATH_MAX-2; fi++) /* -2, escape is 2 chars. */ switch (filename[fi]) { case '\0': -- 2.18.4