From patchwork Sat Aug 24 22:10:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11113155 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 232891399 for ; Sat, 24 Aug 2019 22:10:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F3A5720870 for ; Sat, 24 Aug 2019 22:10:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CNQV84H0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728098AbfHXWKr (ORCPT ); Sat, 24 Aug 2019 18:10:47 -0400 Received: from mail-wm1-f49.google.com ([209.85.128.49]:34530 "EHLO mail-wm1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727740AbfHXWKr (ORCPT ); Sat, 24 Aug 2019 18:10:47 -0400 Received: by mail-wm1-f49.google.com with SMTP id e8so11681596wme.1 for ; Sat, 24 Aug 2019 15:10:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=pLLFXCGv5668Am31WrlF04FVVcPLJfKWwB7/EgXET1E=; b=CNQV84H0rkXiZe/qnK/2DRvDjFTeMYGyOZMeT1KAgZn03eB+7EP0w3G5tXJ5TxLyZo 9oXTtXL3lzD7e2WZT7rIXFvCSjMrFU2nWNVg6pxCyxtmSTBHVVTso8q5H+TSR+oNQ+CK Gx1bZzfWbzPu23nkF50BJcmET7Zuhq7EQ4HeHh5xQpTfRciR7mnTSByFktZ/21OHghxq iNqyiChEMi43Y1ObDE8sz7+eVmrVUwpylgysB2jPL77zB8yhdDDA9zIze+ge0KRqmch2 P15Wq/ismveeLhPUoFbcqGJdgSqjhSSjMiskMUIz33/QKzp3nYBuZY4kXVrJzD4K+x1q 90Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=pLLFXCGv5668Am31WrlF04FVVcPLJfKWwB7/EgXET1E=; b=AWA5tDSzh0izFh3tfR7dfjAiFEyIprNzMRGLEf4fnprmja5vr6FP2eUfEubeH1LE0A +PNYu5SPo8sPRne30Tskb2Vl/H9IG4W9CDwrlt00V5DO40fPQk0syIj45pwqlxVVVJZF 6IomBDagzaNdYgnrsGmFXviCsL20ivRiHkcIe9c3k5n6tK6Zc1PoOO6RwAOqAwK9xPDY f2UPKzZ1eFeNBPSxcjGhHY1XoX7TJ1AG/0ujZtxUUjftLs4wU4cfwX3zSoLALMCg4MNr v5QfqrXANlcUutMORTtbClF45CrZGfzazFLm+RjrqS+MbvULqnEoxVajdP6Kgj4WpHDe OLEQ== X-Gm-Message-State: APjAAAUIPizl1pF/BBGtpt3FusCDCZlQVBKUPkijxDba5jYqsxKkvEsE X3nGYi54qZuATGyZlf4qSu5m36Kp X-Google-Smtp-Source: APXvYqzqXOe3TU+d8ZtE8p3e1XfiSvMKpH3zudH/ien+Ep8J/me2yf8qrL7vzwu4JkUc1TjZl7D4aA== X-Received: by 2002:a7b:c8c1:: with SMTP id f1mr11667894wml.87.1566684645282; Sat, 24 Aug 2019 15:10:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f10sm7130672wrm.31.2019.08.24.15.10.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Aug 2019 15:10:44 -0700 (PDT) Date: Sat, 24 Aug 2019 15:10:44 -0700 (PDT) X-Google-Original-Date: Sat, 24 Aug 2019 22:10:41 GMT Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 1/3] setup_git_directory(): handle UNC paths correctly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin The first offset in a UNC path is not the host name, but the folder name after that. This fixes https://github.com/git-for-windows/git/issues/1181 Signed-off-by: Johannes Schindelin --- setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.c b/setup.c index ca9e8a949e..a803b3ade3 100644 --- a/setup.c +++ b/setup.c @@ -906,7 +906,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT); struct string_list ceiling_dirs = STRING_LIST_INIT_DUP; const char *gitdirenv; - int ceil_offset = -1, min_offset = has_dos_drive_prefix(dir->buf) ? 3 : 1; + int ceil_offset = -1, min_offset = offset_1st_component(dir->buf); dev_t current_device = 0; int one_filesystem = 1; From patchwork Sat Aug 24 22:10:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11113157 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 4E6DF1813 for ; Sat, 24 Aug 2019 22:10:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B2C020870 for ; Sat, 24 Aug 2019 22:10:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hjwnyq4A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728135AbfHXWKt (ORCPT ); Sat, 24 Aug 2019 18:10:49 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55515 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727954AbfHXWKr (ORCPT ); Sat, 24 Aug 2019 18:10:47 -0400 Received: by mail-wm1-f68.google.com with SMTP id f72so12015092wmf.5 for ; Sat, 24 Aug 2019 15:10:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=HnGSI0wllQLc9UBBCmuSWO2u8+DV7Duylo8NXHAbGpU=; b=hjwnyq4A+ZEJ8IVCrqmjs8V/eQ6QDAx58CplJPWIBd5Eh7Y052wbBv3lQhxSPbgvYK RbSjH7ttEhgrYKgtMcE5mdy2fcxEePW6wwDSYY6curt12YqxpSciq+QwOP3/jx0b2JL4 gUtkY7B5Tix6MDH4eIy+AafbRDi+vQ92CPGd9wy9lZydB2bbGb4QPdVPb2eRqnujr4+S koy1Ul0nXit2ZsD+deGmMDN3ATQ9+guui8FwXTNzLUIz5osX0lc5E/ePLCbZFzGCXm0i uvrm+01v0GhyOFCEkvnuwkL9diXsIwX9JgXu6i1kSNMJjBrltSXO8QIAVXwt3dyn8KGN Bo4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=HnGSI0wllQLc9UBBCmuSWO2u8+DV7Duylo8NXHAbGpU=; b=qIZmR4OBnHlicuOPpGHQn2JzXxFqqLYr4Z3Pcy5yF/W+MOa2cBSN+cy9y1zvb8BSyI 0jg6PbNr3Xge7LJ74aqSwJNQIKp8xR/vsV7YDYMInnmk6kATJ/SLlckTe2OaIFiIPrZe 5RaBN7Gq90ys5ywl4kbabwTrZbfKqi8NRyjEoeEGhyKRuB8tTJNe//axseOSqC09YmVV JnqR0S/P3eHbiKu4gFNlrBVF8UsKd9jk8rZ1dgCM+Acurcp7tDD4ywK+6wTO3w1dnwji xKH3bVjM4lRwfe/OmNt8tarUpPWZ9MZ+12BLOlUqDJ00FFCJevZBZK565TSJ7I9qW/Ya 1jgw== X-Gm-Message-State: APjAAAUzUHQzZ233FxTd2t+h3sKc+G7nuL3JZFJy8SEUvbwIYVfTlcYh QohGxuKHXV1Vd+Mjky0CWH+6GmZc X-Google-Smtp-Source: APXvYqwwJeHj1WhUtILzyPIDfRQTSlh7Mhounf2p5Vtfewv/nonVCoUhRyIiSeqYxptxX92zOq2ASw== X-Received: by 2002:a1c:200a:: with SMTP id g10mr11848206wmg.160.1566684645932; Sat, 24 Aug 2019 15:10:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j10sm13382144wrd.26.2019.08.24.15.10.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Aug 2019 15:10:45 -0700 (PDT) Date: Sat, 24 Aug 2019 15:10:45 -0700 (PDT) X-Google-Original-Date: Sat, 24 Aug 2019 22:10:42 GMT Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 2/3] Fix .git/ discovery at the root of UNC shares Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin A very common assumption in Git's source code base is that offset_1st_component() returns either 0 for relative paths, or 1 for absolute paths that start with a slash. In other words, the return value is either 0 or points just after the dir separator. This assumption is not fulfilled when calling offset_1st_component() e.g. on UNC paths on Windows, e.g. "//my-server/my-share". In this case, offset_1st_component() returns the length of the entire string (which is correct, because stripping the last "component" would not result in a valid directory), yet the return value still does not point just after a dir separator. This assumption is most prominently seen in the setup_git_directory_gently_1() function, where we want to append a ".git" component and simply assume that there is already a dir separator. In the UNC example given above, this assumption is incorrect. As a consequence, Git will fail to handle a worktree at the top of a UNC share correctly. Let's fix this by adding a dir separator specifically for that case: we found that there is no first component in the path and it does not end in a dir separator? Then add it. This fixes https://github.com/git-for-windows/git/issues/1320 Signed-off-by: Johannes Schindelin --- setup.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/setup.c b/setup.c index a803b3ade3..3d24de15dd 100644 --- a/setup.c +++ b/setup.c @@ -934,6 +934,12 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, if (ceil_offset < 0) ceil_offset = min_offset - 2; + if (min_offset && min_offset == dir->len && + !is_dir_sep(dir->buf[min_offset - 1])) { + strbuf_addch(dir, '/'); + min_offset++; + } + /* * Test in the following order (relative to the dir): * - .git (file containing "gitdir: ") From patchwork Sat Aug 24 22:10:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11113159 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 7C20914F7 for ; Sat, 24 Aug 2019 22:10:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 567DC20870 for ; Sat, 24 Aug 2019 22:10:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f/ybRwNl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728176AbfHXWKt (ORCPT ); Sat, 24 Aug 2019 18:10:49 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42292 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727690AbfHXWKs (ORCPT ); Sat, 24 Aug 2019 18:10:48 -0400 Received: by mail-wr1-f68.google.com with SMTP id b16so11776680wrq.9 for ; Sat, 24 Aug 2019 15:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=cs8KRpvTpzJm9vZ5IHyTbW87I/269ebb020JNe76mzA=; b=f/ybRwNlv4gxh8pkz3xERqeshdQNTzc48dxlx7UXuPBJ/npHfTM6HfyeEqsHi/suVD GujClNfUMpYixnFu06uzDYEXoH4zwveMpm/IMCWTs4QWpay249sypQeKWctlYFfbQ35G dgwTPrOY+84O098/bbxq0hCG/urK/+8p6gj15sNz25T65J/9/4rn5lKNhiCVqVC7Ahic UhgHya4bwI62SlpQA/n4KWN6G/brCiV1JgXM0GUrCFSzbN3VOOVZ0h3raXcIWDoJbz3H DaBM7JytX5Lluu9uSBwylysfpH7lWPNF6XBphx3/7LSN1L/3i8C+P95nAL9EkKvvN7mk VkNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=cs8KRpvTpzJm9vZ5IHyTbW87I/269ebb020JNe76mzA=; b=rzknJ+EsavxoTCf+8lhiPQlJv2yXXnKvPXSpH1OP3o1LT/p399W5VB/k0yHp+yDvs7 gihwuAI1IkZa/BI/q+1usmehIeXeu0JRn9SOcooIu7aG8FqkoJ0c++snMWBn/yEK7y8s WAnhnQFGV7eDeEkb3LWxUe2ATBQ7PmMbC1rTMcPJOtF3eUyXS9nSv0iqQPuNN9XbZuOk vbeCq2xn2mqaxvMHSwNCGQ7SrMDeMKMi/pFFnD4gM1b2DoFDYrUppHVLK6Yfkvy8aFNq 8VFfRCkXCUALIZVbSI7Ezk3kgPNIm+90ZaBBlM0LrZmFSu/DsQT2yWnoc63HORpwW6M2 0xXg== X-Gm-Message-State: APjAAAUV5oAZBJzGTBrW+EKQ2tRs+jrVjSD1DfngnoOlew6eAbQ+t+vE 8Jz8ruZuumGQNPdfXOrg8j/w9NyC X-Google-Smtp-Source: APXvYqxGzAKpA2f2jsCFfuocSyMx0lhA7xo4sT+JlShV5ie6lYlCb+dx355YQpdi6Att18EMQdFiYw== X-Received: by 2002:adf:8364:: with SMTP id 91mr12952526wrd.13.1566684646638; Sat, 24 Aug 2019 15:10:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e13sm5754114wmh.44.2019.08.24.15.10.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Aug 2019 15:10:46 -0700 (PDT) Date: Sat, 24 Aug 2019 15:10:46 -0700 (PDT) X-Google-Original-Date: Sat, 24 Aug 2019 22:10:43 GMT Message-Id: <80b5535dc096a6ce0efac5aa4adf7a933fc22062.1566684643.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 3/3] setup_git_directory(): handle UNC root paths correctly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin When working in the root directory of a file share (this is only possible in Git Bash and Powershell, but not in CMD), the current directory is reported without a trailing slash. This is different from Unix and standard Windows directories: both / and C:\ are reported with a trailing slash as current directories. If a Git worktree is located there, Git is not quite prepared for that: while it does manage to find the .git directory/file, it returns as length of the top-level directory's path *one more* than the length of the current directory, and setup_git_directory_gently() would then return an undefined string as prefix. In practice, this undefined string usually points to NUL bytes, and does not cause much harm. Under rare circumstances that are really involved to reproduce (and not reliably so), the reported prefix could be a suffix string of Git's exec path, though. A careful analysis determined that this bug is unlikely to be exploitable, therefore we mark this as a regular bug fix. Signed-off-by: Johannes Schindelin --- setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.c b/setup.c index 3d24de15dd..c8c6bf3f49 100644 --- a/setup.c +++ b/setup.c @@ -784,7 +784,7 @@ static const char *setup_discovered_git_dir(const char *gitdir, set_git_dir(gitdir); inside_git_dir = 0; inside_work_tree = 1; - if (offset == cwd->len) + if (offset >= cwd->len) return NULL; /* Make "offset" point past the '/' (already the case for root dirs) */