From patchwork Sun Apr 19 11:00:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 11497287 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5AE1174A for ; Sun, 19 Apr 2020 11:00:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE41D2223D for ; Sun, 19 Apr 2020 11:00:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LfZaZH4d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725953AbgDSLAw (ORCPT ); Sun, 19 Apr 2020 07:00:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725914AbgDSLAv (ORCPT ); Sun, 19 Apr 2020 07:00:51 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7775C061A0C for ; Sun, 19 Apr 2020 04:00:51 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id nu11so3154742pjb.1 for ; Sun, 19 Apr 2020 04:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u7i9JEcHGbBDQq5uZ2gh7RUXZ1tzWS0caOTUlX5WiNI=; b=LfZaZH4d046bkcUTekvWTeu3PMQ20OKuP/qBZ+I/tvkdpI3wxilp8TOf8jqCe5YTYt 9I1rjVWy48UjFzpPFz9eJuzjXeQOASCKak7PVYDEe0Dx18ipb91oxGaecdx9yP6dTC+v ZB2FLaLRwjyOOeOBr5DsL6Jgeg4dP5wt5h1dTQy/niux3SB+j6o651LY1WpeCXK5dtCM B3TCpiBQHzxEY6aryL1Cm4dhiO1+p6XIiGRQvx3xvQ9odflxtOJu6aApWQmCGZU8OGmS jxmuQgYl9Zm4OUL40bQdqRb8UAdKDvEVRMR3Ybx7aNA11vZK1eePuO5hPGtS6SryleVM UBRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u7i9JEcHGbBDQq5uZ2gh7RUXZ1tzWS0caOTUlX5WiNI=; b=V25gP1AUo1eMdw4ejyc7QBBmyfisyMolDiguXMb6zZ+R+UHxRqRZ/Y+AdJmXLc0vqn w3V6mD9OPnBvj9pGQel0JFZFM7D9+iccgLdr9O13Xwg4F97jP3It2fGYLiatnZej7w1K JpTIW94mdk8rvz7XDGPzXaJUKqRex+pfu7djOW08zrtP42F6nq2gIY3Yq57nQ7XnT1KL xY6m6Hz8esULy7AVH7cwYrAseLgF7hzNrIwUvo5xmkd5VgkZ1sglsotKJ4PviScqOH5l zIkBkYzGqMBZN+Xh7T4AUfE83ZCsPCPHzYjHwF9KEiIBiSsD2watjVC2TprqlquqqyPm C73Q== X-Gm-Message-State: AGi0PuZZnb5A+PGPkrdu2jedgYK3y2bD3D3hGnnGwz8LxzSMO8zDcGlc cHa/PJgENeTcUs82PzHKEyRaPUc4 X-Google-Smtp-Source: APiQypInAwMMQZNVjb0DTomORPpQHVbAHuCsuB7Ud72Z0vuYWzXCVbikOxrlotGyPS+orgQYMXhcnA== X-Received: by 2002:a17:90b:3547:: with SMTP id lt7mr14058654pjb.96.1587294051095; Sun, 19 Apr 2020 04:00:51 -0700 (PDT) Received: from localhost.localdomain ([2402:800:6374:5380:b9e1:93e1:68db:b9f6]) by smtp.gmail.com with ESMTPSA id b20sm361692pff.8.2020.04.19.04.00.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Apr 2020 04:00:50 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH v2 1/3] t4254: merge 2 steps of a single test Date: Sun, 19 Apr 2020 18:00:40 +0700 Message-Id: X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb In-Reply-To: References: <20200418035449.9450-1-congdanhqx@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org While we are at it, make sure we run a clean up after testing. In a later patch, we will test for more corrupted patch. Signed-off-by: Đoàn Trần Công Danh --- t/t4254-am-corrupt.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/t/t4254-am-corrupt.sh b/t/t4254-am-corrupt.sh index fd3bdbfe2c..ddd35498db 100755 --- a/t/t4254-am-corrupt.sh +++ b/t/t4254-am-corrupt.sh @@ -25,10 +25,8 @@ test_expect_success setup ' # fatal: unable to write file '(null)' mode 100644: Bad address # Also, it had the unwanted side-effect of deleting f. test_expect_success 'try to apply corrupted patch' ' - test_must_fail git -c advice.amWorkDir=false am bad-patch.diff 2>actual -' - -test_expect_success 'compare diagnostic; ensure file is still here' ' + test_when_finished "git am --abort" && + test_must_fail git -c advice.amWorkDir=false am bad-patch.diff 2>actual && echo "error: git diff header lacks filename information (line 4)" >expected && test_path_is_file f && test_i18ncmp expected actual From patchwork Sun Apr 19 11:00:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 11497291 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B399A18C6 for ; Sun, 19 Apr 2020 11:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BF6222202 for ; Sun, 19 Apr 2020 11:01:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XYuGJ/Dq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725990AbgDSLA4 (ORCPT ); Sun, 19 Apr 2020 07:00:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725914AbgDSLAx (ORCPT ); Sun, 19 Apr 2020 07:00:53 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91B19C061A0C for ; Sun, 19 Apr 2020 04:00:53 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id w11so3564690pga.12 for ; Sun, 19 Apr 2020 04:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/iIC+RfNtM2nBfaunyyEkosnjXnZ1WJMSW2uGFkbE24=; b=XYuGJ/DqgKpNod+6S+/a6SNQmjx8ObzV/21yEfq8N5xao3z5+RExpj9a6NwaQWz3el inX9SqxtWSWSngZ5z2gcgABgnDTbFu6qRj8qCZzuacDnIH2/ghjaQW2nZQJ+BLkbgK4/ IVpOnjZs7r0imx5Kaf6tKZbtpyk8tbN5Av3Qn8kZMIGmF2VPr06vcP+ILjAJPyLXHkqO WE3+JuYOu8iKXNYXDuL9VUYZcg5nV7FkzFaYlCPmz/eamU/c4OlHI1iaRkwIZXshFKK9 ubHVOA/7lzIb/SlLjN1tUfmCJdr2Xgy61UZvz3ZWoEq0nrq0uZL9G2Etxe8MZSW2cOzn ZgOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/iIC+RfNtM2nBfaunyyEkosnjXnZ1WJMSW2uGFkbE24=; b=rGIARqv57chAzhk8lnfQruuxySjSmp7/QNPxAqyklsug8r41Hp61ehYg6GMAA9S7Ds QZoYwYhLil4OwxiK02XFRFqiCLtTFtp+9K1lLQcK4ry0/gjPCUu50isddHLmYh5QT4jg tUxIHZwR5UlFQTCvS9ATV4oNQ63hy26RLvnm3D1ncQR4yV2QQAvRTNHUsKfgEuwAevnk q9yhY3oKL54BblfkYLwUV8Z1eucQ2k/UCPUIbdECZoP3JpZo4aMgn8JrXP4R1pEEeQFD jyqq2CRz6aDTTJDqnYmFyP5dbi/gBA2LsCawtB5KbmcNQH+wd/DOLO2A/w1OxqWPRHQl CXxA== X-Gm-Message-State: AGi0PuYg1wxQPCee959M1Qbzq+1ze2o4emRDa1xzRz023haTS3TdJ/zY gV+XPSGrJmE54HZdQpsrpKhAlu/p X-Google-Smtp-Source: APiQypLkvEl1zZRJHVpm1nCIvFvxs8cJF5XaSQUfhbeaSl6aHhsrz6awSnaBsv2mJpF0qlH21+lvjQ== X-Received: by 2002:a63:1d4:: with SMTP id 203mr11124868pgb.74.1587294052782; Sun, 19 Apr 2020 04:00:52 -0700 (PDT) Received: from localhost.localdomain ([2402:800:6374:5380:b9e1:93e1:68db:b9f6]) by smtp.gmail.com with ESMTPSA id b20sm361692pff.8.2020.04.19.04.00.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Apr 2020 04:00:52 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH v2 2/3] mailinfo.c::convert_to_utf8: reuse strlen info Date: Sun, 19 Apr 2020 18:00:41 +0700 Message-Id: X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb In-Reply-To: References: <20200418035449.9450-1-congdanhqx@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We're passing buffer from strbuf to reencode_string, which will call strlen(3) on that buffer, and discard the length of newly created buffer. Then, we compute the length of the return buffer to attach to strbuf. During this process, we introduce a discrimination between mail originally written in utf-8 and other encoding. * if the email was written in utf-8, we leave it as is. If there is a NUL character in that line, we complains loudly: error: a NUL byte in commit log message not allowed. * if the email was written in other encoding, we truncate the data as the NUL character in that line, then we used the truncated line for the metadata. We can do better by reusing all the available information, and call the underlying lower level function that will be called indirectly by reencode_string. By doing this, we will also postpone the NUL character processing to the commit step, which will complains about the faulty metadata. Signed-off-by: Đoàn Trần Công Danh --- mailinfo.c | 6 ++++-- t/t4254-am-corrupt.sh | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/mailinfo.c b/mailinfo.c index 742fa376ab..0e9911df6d 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -447,19 +447,21 @@ static int convert_to_utf8(struct mailinfo *mi, struct strbuf *line, const char *charset) { char *out; + size_t out_len; if (!mi->metainfo_charset || !charset || !*charset) return 0; if (same_encoding(mi->metainfo_charset, charset)) return 0; - out = reencode_string(line->buf, mi->metainfo_charset, charset); + out = reencode_string_len(line->buf, line->len, + mi->metainfo_charset, charset, &out_len); if (!out) { mi->input_error = -1; return error("cannot convert from %s to %s", charset, mi->metainfo_charset); } - strbuf_attach(line, out, strlen(out), strlen(out)); + strbuf_attach(line, out, out_len, out_len); return 0; } diff --git a/t/t4254-am-corrupt.sh b/t/t4254-am-corrupt.sh index ddd35498db..98cda32d0a 100755 --- a/t/t4254-am-corrupt.sh +++ b/t/t4254-am-corrupt.sh @@ -3,6 +3,36 @@ test_description='git am with corrupt input' . ./test-lib.sh +write_nul_patch() { + space=' ' + qNUL= + case "$1" in + subject) qNUL='=00' ;; + esac + cat <<-EOF + From ec7364544f690c560304f5a5de9428ea3b978b26 Mon Sep 17 00:00:00 2001 + From: A U Thor + Date: Sun, 19 Apr 2020 13:42:07 +0700 + Subject: [PATCH] =?ISO-8859-1?q?=C4=CB${qNUL}=D1=CF=D6?= + MIME-Version: 1.0 + Content-Type: text/plain; charset=ISO-8859-1 + Content-Transfer-Encoding: 8bit + + EOF + if test "$1" = body + then + printf "%s\0%s\n" abc def + fi + cat <<-\EOF + --- + diff --git a/afile b/afile + new file mode 100644 + index 0000000000..e69de29bb2 + --$space + 2.26.1 + EOF +} + test_expect_success setup ' # Note the missing "+++" line: cat >bad-patch.diff <<-\EOF && @@ -32,4 +62,18 @@ test_expect_success 'try to apply corrupted patch' ' test_i18ncmp expected actual ' +test_expect_success "NUL in commit message's body" ' + test_when_finished "git am --abort" && + write_nul_patch body >body.patch && + test_must_fail git am body.patch 2>err && + grep "a NUL byte in commit log message not allowed" err +' + +test_expect_failure "NUL in commit message's header" ' + test_when_finished "git am --abort" && + write_nul_patch subject >subject.patch && + test_must_fail git am subject.patch 2>err && + grep "a NUL byte in Subject is not allowed" err +' + test_done From patchwork Sun Apr 19 11:00:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 11497289 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97A1017EA for ; Sun, 19 Apr 2020 11:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F34A22202 for ; Sun, 19 Apr 2020 11:01:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uDPenPEs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726011AbgDSLA4 (ORCPT ); Sun, 19 Apr 2020 07:00:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725964AbgDSLAz (ORCPT ); Sun, 19 Apr 2020 07:00:55 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E80FCC061A0F for ; Sun, 19 Apr 2020 04:00:54 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id b8so3491890pfp.8 for ; Sun, 19 Apr 2020 04:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2VUP80jFzAnCg9aWY0sUi+iE1GIn/o4YKWuenijr2sg=; b=uDPenPEseGIahn0rI6KfxVuvN3n4fwBt/1eJZDeoDwVAqh9+CuFBPbo/Ep69C2dgh9 /ZW2h5ou3klFqAt5xFF7oIXBqutWQp0LdQYmSe+o0RstR0zmRCNgNBGeqT1IEsJRNquo LqDYNgxKYNmucKrEFYjxjfLYexTQcnvBadRrKy0Ms/p5a9YYG4SQ8ckIJ2Smq1SQZ4If 1MwhLx5sYchmtK7hR/ATwbRFhnh48ryELgT6NqTVKS7BE0iavbMf1CJqmAkLDSYIMZBU E7xPcSGSVex+gVDQdJiMu6SyEf7WZCg4Kr8/4e9Ht2KsucdCiq25BaVtQ/GZeQaOCYX5 /GkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2VUP80jFzAnCg9aWY0sUi+iE1GIn/o4YKWuenijr2sg=; b=piHpqU3FaD9CcbA/pbpbR6C99U28QHdbA3uMkHQDpdFWzNcPU6/YAHp4eNk7YRgjUH PvAl/MxO6s585GtjeesWmZin4Pt22Hiq/kGqFkzI/BE3GyMPZUAJrcDpDgF+zzlbIulq AGNSUEs20i3L07jHgLGNfsBIzMEMbfBMHxDHUvBTZaGsHFG6FpUgLnKYE3TSW/jd6uS7 /AyKmGSd22j49eUP0jF4T+lQl6p7QHzhTHIbyGoItx+ECiaZZ8t6tvjWFrzLUXYcNx4K zDOneU6IgUB3C2KE7pvAvYFHtztSduuTp0WDyAL4ESw8JB0H0xNM7ain6EL/0/PQ/x4R 4d7w== X-Gm-Message-State: AGi0PuYvtmW4GIbHMBHr161p1cmNDxefGpwP5TQRS2aIRrakhLLGT/jx TPqo9udhWWUyK51bRMWE+oLeAN6/ X-Google-Smtp-Source: APiQypJEniIe+sR8ocfYla2CgsWAMcnhqJvMqYCFNxZVI1BxyLWYav5mD+SJQOovq/gJuWz8Gth1bw== X-Received: by 2002:a63:2c07:: with SMTP id s7mr11203413pgs.230.1587294054338; Sun, 19 Apr 2020 04:00:54 -0700 (PDT) Received: from localhost.localdomain ([2402:800:6374:5380:b9e1:93e1:68db:b9f6]) by smtp.gmail.com with ESMTPSA id b20sm361692pff.8.2020.04.19.04.00.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Apr 2020 04:00:53 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH v2 3/3] mailinfo: disallow NUL character in mail's header Date: Sun, 19 Apr 2020 18:00:42 +0700 Message-Id: X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb In-Reply-To: References: <20200418035449.9450-1-congdanhqx@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Đoàn Trần Công Danh --- mailinfo.c | 5 +++++ t/t4254-am-corrupt.sh | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mailinfo.c b/mailinfo.c index 0e9911df6d..c31991e621 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1138,6 +1138,11 @@ static void handle_info(struct mailinfo *mi) else continue; + if (memchr(hdr->buf, '\0', hdr->len)) { + error("a NUL byte in %s is not allowed.", header[i]); + mi->input_error = -1; + } + if (!strcmp(header[i], "Subject")) { if (!mi->keep_subject) { cleanup_subject(mi, hdr); diff --git a/t/t4254-am-corrupt.sh b/t/t4254-am-corrupt.sh index 98cda32d0a..d9d1ac6c7d 100755 --- a/t/t4254-am-corrupt.sh +++ b/t/t4254-am-corrupt.sh @@ -69,9 +69,11 @@ test_expect_success "NUL in commit message's body" ' grep "a NUL byte in commit log message not allowed" err ' -test_expect_failure "NUL in commit message's header" ' +test_expect_success "NUL in commit message's header" ' test_when_finished "git am --abort" && write_nul_patch subject >subject.patch && + test_must_fail git mailinfo msg patch err && + grep "a NUL byte in Subject is not allowed" err && test_must_fail git am subject.patch 2>err && grep "a NUL byte in Subject is not allowed" err '