From patchwork Fri Jan 24 12:21:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13949332 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDCB52B9BC for ; Fri, 24 Jan 2025 12:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721350; cv=none; b=D6Q9QP0ZAD9qidvvsim43HqlxHDfUMObxO2FJ2cqLxeRwjMyxEGWkATR0j3CcI2Fji2R72NejuxODdY/3jRU9JOe3Rims7OGUrNaeB/fMA+njHDi+CV9UQJI5kt8NVchmdOE/+Ezt9mLxah9AnEz0ecISfbB0MGY0ldtXl5RdI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721350; c=relaxed/simple; bh=C/Q2I9a8u+8/L3BDCN2Q200YkzuMkxLp+rtXy+6qgSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EZkF55a/9bIKipdRQvme/oMn1QUYctRZsViZfj4dKpApFWJikz/urlOjQaw7wi5DT2n9UkxFlDKGcDxnCTsdHhVr2hJmnjLLZXDXW9eUELD9r6nCiQFupHSYMR/g37qR9zorOiizSm8rSyq6qdTxZyy9AhLcrlB0CsyzTLzUN5Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ea7zaJkY; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ea7zaJkY" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2ee709715d9so2988731a91.3 for ; Fri, 24 Jan 2025 04:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737721348; x=1738326148; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kcxdWLahw0fIxmQoWB1haQp77SFUjIc3H0mwVlUx5go=; b=ea7zaJkYHBHBDwXBNcRa6xzdZS31H86KCCeqyX2LrZdPz9tpjQdKUK+tB6KvD4/Bo/ vzTaxaWtaimp/67BFKkGyrNtZqjfo8wVM0+IYwWpHuJsYOz91vQv/qng7pyUgBaTogWY oeq4JrD/YWPFB3nT2b3O01qNhU4y5u7VmnttTjJnUjC9bj3UJZ4sWeYQfEYHx0nBsXgA jdnDJVv4D3LODkZPxhhYYlQsFY3T4Yswxh5gF17KxVRTDb/o19PTX5VsBCdzenYqEiLa bPM9HPrnFlTmS4anLhIk9SI/hJmeW7zcCokRztOiQXW4H/H6wBrbJQDEIRfx2iBNt9cn ux5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737721348; x=1738326148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kcxdWLahw0fIxmQoWB1haQp77SFUjIc3H0mwVlUx5go=; b=sm3HBJu/LAvbwHLT1XTs9uyLAr9/mloFq5rSq2xKhhcfkeLZKCe3IrAxMYhgG8vyp7 rNssWO+ssegvLVX0ti6/+q4QOce12ppLl3DmzlNMMFy/Uf3dTqrx4hIvBnX/cwjlLGjS sIRCs8UC1e67W9pGtWaqQrNlrQo8VPJzpDlduwZmcFTmhrPZSDmo/Z/NJhsIpv65xf/3 NhtnX3F1ayfnNshHziAjCg21ezNCW/n4Yf6Juu4gCOusScfAoLBRD0p9PaZV5tuP1qxq PJ0V5oF+tRzvKgiFitXMs6D5SgdmYARJjDAXaXHMmcTezXC8jFbTYy9DXY4Awlq5M8jN vVtA== X-Gm-Message-State: AOJu0YzJUwhj7vQeTqYCWfqQFNIkkfcli4WXu+l9KMPLwswJ1hS5T6rq Iy0PiO2XqUUumtYYPOz/DENDpOUVG8R5+NyawR6m7J7OjgnwSH6lglWzvvH9nqU= X-Gm-Gg: ASbGncvVSxhzyXXT0mXKfqDMXYfVR/4gxRtsMPMNYcxaL4TDZXAojN18Y1zrpXQxVeR R/Q5dtEv8V85kXZfe3ed/FVIlzsq8CRoTlZOD+U5eKLQSv7IYW+T7Sj20aH/ocxN1cW0V71B2Yt H073nxOgxZNZJ89a3yqEW/JIjbzkaweDvxYf8eAy5WLgZ75WpqXbHcCEaA3/g8v65S0nLV6DJax ScULApbqv2bei5yq+8UgrKviafLqjYTOUntsa0XBJIXaYCkcI90IpwgvWg1w542+XkpvvDXdPOC dTVxnfip/s9tNYQtjENFUAGqfG7XfQ== X-Google-Smtp-Source: AGHT+IGCgRIGrmhMvui7DHHMozjoERjZ+eBX0KmFxn114yrcwk5JOrtqiB3VgrqvF63P6KHoYCBsKQ== X-Received: by 2002:a17:90b:2803:b0:2f6:d266:f45e with SMTP id 98e67ed59e1d1-2f782c4bd8fmr44943454a91.2.1737721347811; Fri, 24 Jan 2025 04:22:27 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7ffb1dc56sm1685056a91.49.2025.01.24.04.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 04:22:27 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v3 1/6] version: replace manual ASCII checks with isprint() for clarity Date: Fri, 24 Jan 2025 17:51:36 +0530 Message-ID: <20250124122217.250925-2-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250124122217.250925-1-usmanakinyemi202@gmail.com> References: <20250117104639.65608-1-usmanakinyemi202@gmail.com> <20250124122217.250925-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since the isprint() function checks for printable characters, let's replace the existing hardcoded ASCII checks with it. However, since the original checks also handled spaces, we need to account for spaces explicitly in the new check. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- version.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/version.c b/version.c index 4d763ab48d..6cfbb8ca56 100644 --- a/version.c +++ b/version.c @@ -2,6 +2,7 @@ #include "version.h" #include "version-def.h" #include "strbuf.h" +#include "sane-ctype.h" const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; @@ -29,7 +30,7 @@ const char *git_user_agent_sanitized(void) strbuf_addstr(&buf, git_user_agent()); strbuf_trim(&buf); for (size_t i = 0; i < buf.len; i++) { - if (buf.buf[i] <= 32 || buf.buf[i] >= 127) + if (!isprint(buf.buf[i]) || buf.buf[i] == ' ') buf.buf[i] = '.'; } agent = buf.buf; From patchwork Fri Jan 24 12:21:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13949333 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC0042B9BC for ; Fri, 24 Jan 2025 12:22:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721354; cv=none; b=g3EJO/GCRlHfbz3ZZkQ9PH4NesUkNnWYkrUPVD2ayhpEKo65guDNz2KBedbhKzjfXzE4bed5cUr8pvDvQt759pdQvrXLRxbrwsDo1FYUdYLgoyxzS4RfRA+/NeIAluRaylM+xS2SNWQmo+e0awbgGWD6EUg2JkqLt4ly28bMhZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721354; c=relaxed/simple; bh=eJZCiA3SfT4ew0r7R3XPDXFgIMz4tB6YNA1/3s4GWDs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NhEejcKEhrd6eMUPNTTpzTIGV3A4Z1isTxAgy1pEYh2PzDZr/pmEXn8a0E/abV3Yr36d2JSxzAvL7q4gjiFINyBhRSRXzW48Ua3R0PIb+f71DOqEmucY8qx4WPWweQK0iPNJ//1GwZqdnLYNgOVGfENy8EUbsMJxcvX7p+v/WRY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BX/0jRQJ; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BX/0jRQJ" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2f43d17b0e3so3820288a91.0 for ; Fri, 24 Jan 2025 04:22:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737721352; x=1738326152; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v7lnvd9Iws+Yv4PNiwqYjxa2/7Y2vhqfLzesyN2VZ+U=; b=BX/0jRQJEfTC75afUNjhJNP2MlnJKdHDIbzquFZbht7ItAPctszG2GEsf/Gj7OMUos J5Nf8pxed4W1ZXcIxNFuoa+3/wUfujqnf++vTuI74WwzARKXMuH+fZ3rAmOGXCiiMgkz J+syqXyqC0yqQO90aPkYFLtZ6z5Ffd9tndHil/PcgeNN/2mIcUiB6ejONUt/HrNtS0Kz GghNDU1TsZJFnDBMLro9uNRdOLRObMTmJDH55lPWCveOjSxHlqX3I0qYECbWxXDq9l0B zMwsl8inAWH5Q2fVJN55lSdKkuc5EgVqoitmNBQ7dHh5rKowAX7X8SGhtcLTR7TVYYwb zCrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737721352; x=1738326152; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v7lnvd9Iws+Yv4PNiwqYjxa2/7Y2vhqfLzesyN2VZ+U=; b=oFiZn+6tiW9c3wctBOcsAop2mb/7aG6eYgcvsXaFlXKtdHEfWjkGKwBpg6VWaxfJP2 j4EGXQw/wwxKPvdYDmhUEj+kOP7cdck60b0ZUodbq9IzVy2Ez5rYpPgbogh0BVfxt4rq LGV5LyjkqR40JsdZ2mRJjqlUXICVW+kmXhHW9lmKJdQ1CNxb2eOEzYqm5FYFYKzG938d J5+1/QLn/XJGmusGAOciOgNCr1OmZ5HyNirfv3Glz/e2JiDsv/fGpnLaESVu87SkJSnW qJwmgSqV8/h1Bzik/i5IwsARSHyyEddP9ElcKtI5vHJa3QrOB6Dm+6kR6qOnmh+0r0dF mDdg== X-Gm-Message-State: AOJu0YzVPu0QF7zVR0x3C0fuCpCQmLax8e3pl0aRtYHNB/evFnZhcYIq xqRGwZp7IseSMn5ceHcf+iRtElmrX1wf0Wf343Wm2HDo6qJVd5caRfwesDcOd+k= X-Gm-Gg: ASbGncv7qzrYiooLv5fJIwcZvwa/1M2UfyRoV7i5Rdq7ikkamkQLRbQtcYJySShPVjn PFZpxme5NqU+FU3NIGdW4VoHttlL+8l0DpPwtlckgyMp6oAefqeLA5/xmQJFvkFoU9iDwR9E06n YibADXPsOzmEDEs2ha5tTq7WvLLneDMDlx+8UgL5dd566FLNfwv2rcNJ2AkqY9nAOd4EYDOaYlj raN75S1oX8peeDGR9WKKaSmOhMz0rcENGu/LV/Nn9oGQ+2BfrxOb9DF3rBTQWkw6igN6/pSQvkf D9iGY6r7RO6KEN+2DTsFd+CwMoN4og== X-Google-Smtp-Source: AGHT+IFKREMj29xZPiRC0vlBoQA04Pl/JQKt2xfpUglikl3ADsykF3aDl00kG0LJmCHlOdahwwxN6w== X-Received: by 2002:a17:90b:2c83:b0:2f2:a664:df20 with SMTP id 98e67ed59e1d1-2f782c6750cmr48188958a91.7.1737721351824; Fri, 24 Jan 2025 04:22:31 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7ffb1dc56sm1685056a91.49.2025.01.24.04.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 04:22:31 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v3 2/6] version: refactor redact_non_printables() Date: Fri, 24 Jan 2025 17:51:37 +0530 Message-ID: <20250124122217.250925-3-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250124122217.250925-1-usmanakinyemi202@gmail.com> References: <20250117104639.65608-1-usmanakinyemi202@gmail.com> <20250124122217.250925-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The git_user_agent_sanitized() function performs some sanitizing to avoid special characters being sent over the line and possibly messing up with the protocol or with the parsing on the other side. Let's extract this sanitizing into a new redact_non_printables() function, as we will want to reuse it in a following patch. For now the new redact_non_printables() function is still static as it's only needed locally. While at it, let's use strbuf_detach() to explicitly detach the string contained by the 'buf' strbuf. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- version.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/version.c b/version.c index 6cfbb8ca56..60df71fd0e 100644 --- a/version.c +++ b/version.c @@ -7,6 +7,19 @@ const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; +/* + * Trim and replace each character with ascii code below 32 or above + * 127 (included) using a dot '.' character. + */ +static void redact_non_printables(struct strbuf *buf) +{ + strbuf_trim(buf); + for (size_t i = 0; i < buf->len; i++) { + if (!isprint(buf->buf[i]) || buf->buf[i] == ' ') + buf->buf[i] = '.'; + } +} + const char *git_user_agent(void) { static const char *agent = NULL; @@ -28,12 +41,8 @@ const char *git_user_agent_sanitized(void) struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, git_user_agent()); - strbuf_trim(&buf); - for (size_t i = 0; i < buf.len; i++) { - if (!isprint(buf.buf[i]) || buf.buf[i] == ' ') - buf.buf[i] = '.'; - } - agent = buf.buf; + redact_non_printables(&buf); + agent = strbuf_detach(&buf, NULL); } return agent; From patchwork Fri Jan 24 12:21:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13949334 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7D512B9BC for ; Fri, 24 Jan 2025 12:22:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721358; cv=none; b=f5gqtYljixKCIOEtrbS0qhw+Nsw+quaZ/V6Kk9q5SkFZCzqIYN/Cl4xR+QTkm7JYd2yk/pqAHmJLaDKCupzslewFit86jLVG3GSqUl60UljHW3tnqudOMV00TD/AkILBI7b1cvMfK/tBbVbeDSax0izQ4vVLigXRb7u4QCC7lys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721358; c=relaxed/simple; bh=nG+qvdg4zuJA/fdlNbXmCUGkknIbiKdjV3AFe6URszU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FGqyAPaIib+RwQpSJhPSw3Q1/PPGEyYGXmv1ctqAoGZI0IDx4D2nGiWLEE5Um8unPds+yTUune0WKK3Y++yUC31A6o9jjJLfJ8ROc5QrN7YzMfCD9N7a190P7HJZSLs/qHVftVb2XVPN7Vl2cA4lTOtmQeter7/dVgUjnKx38y0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G+HyUb52; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G+HyUb52" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2ee51f8c47dso2993965a91.1 for ; Fri, 24 Jan 2025 04:22:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737721356; x=1738326156; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=szEYN8zQnG0gcSCUnmFPnsB3EmNA3yUNBw/rUjb9PM4=; b=G+HyUb52wV/ML7Xd0X8FuoCtyryD70OS+BEAomcQNgt6HNqODqe0L1+LwdMOyRsp8A wQfKOwbE/gEzypGzHLFsn0fCAkbHOjTCzk1+5IU82ncgnKBywO4z40fNtTQZdnXGneEr DsT1sasyqe9R84MBhp74fPoJ3gWvkpvf7VMp91JP3Fxg1RobIymLBqGyOvTV+gGwFBxv 5NMOapHO8ObUtpdlQymZtnT95RUldRMxLmmT/lZMKpXRHmiGzF06GnQlBr3ZWQ2wKIqc qX+kMrRy0fwYowcu/31sd1b/2IsLxhtEwm2VcaJHl0sNrJWGuexDEIL2I0EGtrXWE8sb /l8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737721356; x=1738326156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=szEYN8zQnG0gcSCUnmFPnsB3EmNA3yUNBw/rUjb9PM4=; b=gIvWVJwuC8pCnjYQWd35ZjTwKoyanBK/7/4mIdxAaGy/wJm4eHTW0fNZUQgb20Gaip i8BJDN+aR8/rCAYK4mIQzM4TlSvkrdOx8OvLp1kHoF3866fxPBSC0mNznlyOAXZhmKuJ WB+HFWxFK2Dm7QH5akCAZerOi7HTrz47TLbnH0JKVBclpyGegtaY1JKMlMGB0B0G9oTM GkEZt9oT5+ZUH0d3GtZoBMt9RNwZRxIzYMHw8VyC4eDOZmVLhaugVPDCSVsEyTOIfx8q lD0MykmJkSLXW79RPq2armkqPv62CET5naI6zb1P5j6lPHYfB12L4Natbsi9DMQOKzEi RZBA== X-Gm-Message-State: AOJu0Yznn+KuzQegqDcTic9vN9dcrT8atymeg8LtFNMRPrCg+mZGyxw2 VRW3kWJEOJ5sepFZFtAiXwaJh364KU08dLE4nEJqnbZJ/ryosQ3H0uzD+XPDr6M= X-Gm-Gg: ASbGncu62v+RE1uqAR3BOV7BK+MVsrdVjeagob47yYed45OoLekgAGLww0zGopp6dDe 5cWJHgKirdb+NGIddhQGTUvKD/aaqJX8olECtZc2mXUUcYRXR3WgeSn6vBGdvr+6m4V+7bH8HeW 6fmlLm/M8H8MEFdR38XTwiXDJVXEU3i9uzAYqkAWflgFMdBGF5SNYOEcQ0uuPuyS7EMF/iguntG sEs4Yk5d6nG58vworcDjfYe/qjKvvgTgaLrPV+kTh0fS0SEkozObEJs5TaM6QN2rDcdYxqQvRDq ib03t/sPSR2yn3y6j1jB5+W5sUJjww== X-Google-Smtp-Source: AGHT+IFgti9GL++v18Vuu5aSMXNX5Q+w15RTp21Q322vV8b77QrKdcyY4Wfn3GaDW0zxCZHGS/9tuw== X-Received: by 2002:a17:90b:524b:b0:2ee:a583:e616 with SMTP id 98e67ed59e1d1-2f782c8fd41mr45239351a91.9.1737721355736; Fri, 24 Jan 2025 04:22:35 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7ffb1dc56sm1685056a91.49.2025.01.24.04.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 04:22:35 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v3 3/6] version: refactor get_uname_info() Date: Fri, 24 Jan 2025 17:51:38 +0530 Message-ID: <20250124122217.250925-4-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250124122217.250925-1-usmanakinyemi202@gmail.com> References: <20250117104639.65608-1-usmanakinyemi202@gmail.com> <20250124122217.250925-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some code from "builtin/bugreport.c" uses uname(2) to get system information. Let's refactor this code into a new get_uname_info() function, so that we can reuse it in a following commit. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/bugreport.c | 13 ++----------- version.c | 20 ++++++++++++++++++++ version.h | 7 +++++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 7c2df035c9..5e13d532a8 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -12,10 +12,10 @@ #include "diagnose.h" #include "object-file.h" #include "setup.h" +#include "version.h" static void get_system_info(struct strbuf *sys_info) { - struct utsname uname_info; char *shell = NULL; /* get git version from native cmd */ @@ -24,16 +24,7 @@ static void get_system_info(struct strbuf *sys_info) /* system call for other version info */ strbuf_addstr(sys_info, "uname: "); - if (uname(&uname_info)) - strbuf_addf(sys_info, _("uname() failed with error '%s' (%d)\n"), - strerror(errno), - errno); - else - strbuf_addf(sys_info, "%s %s %s %s\n", - uname_info.sysname, - uname_info.release, - uname_info.version, - uname_info.machine); + get_uname_info(sys_info); strbuf_addstr(sys_info, _("compiler info: ")); get_compiler_info(sys_info); diff --git a/version.c b/version.c index 60df71fd0e..3ec8b8243d 100644 --- a/version.c +++ b/version.c @@ -3,6 +3,7 @@ #include "version-def.h" #include "strbuf.h" #include "sane-ctype.h" +#include "gettext.h" const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; @@ -47,3 +48,22 @@ const char *git_user_agent_sanitized(void) return agent; } + +int get_uname_info(struct strbuf *buf) +{ + struct utsname uname_info; + + if (uname(&uname_info)) { + strbuf_addf(buf, _("uname() failed with error '%s' (%d)\n"), + strerror(errno), + errno); + return -1; + } + + strbuf_addf(buf, "%s %s %s %s\n", + uname_info.sysname, + uname_info.release, + uname_info.version, + uname_info.machine); + return 0; +} diff --git a/version.h b/version.h index 7c62e80577..afe3dbbab7 100644 --- a/version.h +++ b/version.h @@ -7,4 +7,11 @@ extern const char git_built_from_commit_string[]; const char *git_user_agent(void); const char *git_user_agent_sanitized(void); +/* + Try to get information about the system using uname(2). + Return -1 and put an error message into 'buf' in case of uname() + error. Return 0 and put uname info into 'buf' otherwise. +*/ +int get_uname_info(struct strbuf *buf); + #endif /* VERSION_H */ From patchwork Fri Jan 24 12:21:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13949335 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CE1F2B9BC for ; Fri, 24 Jan 2025 12:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721362; cv=none; b=oZmJOJUOWPxgIf0UBZIZEqSSf/4fMBjjNy9lbP/046SR+btjiErChrK7mCPzzd/ckEcfAMbfe6hNRyxN1DiL5IEd1GWBvywSUQL2xtne+Bpf9QlrSVVcOJIL25ahU+F19T/DpbvcQolr1kci48f7ZyZao9A1Kz+jfyWZZ57j/1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721362; c=relaxed/simple; bh=zI2kW4kSYFc2wf0pQpoOSH3r4W8g0Sk+jGtKTOVb5Zo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i3Co6FcIZ2d/ltGHcQsQAjeGJEY+kI2s3vc8PAbGEUsy6WUGWKrFRTrsHNQ6SjXwDSLzZEHND9apmO1axbqhvUtmP2uRgGAkDAoE2aJaGOCYFM6l5J6ueuYaimsAHfLtq8BZNtctsDSttEiTlScvlOOevc3V3OzaqGXvX9+KR6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mL7EqA7A; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mL7EqA7A" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2ee8e8e29f6so2907288a91.0 for ; Fri, 24 Jan 2025 04:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737721360; x=1738326160; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gpGzGxY7oS9vaBZmel27t8qPVdpHHnYzoe18NAokJLQ=; b=mL7EqA7A/pfWScXtpS+/OgxyfNd+5APxqtpQ9sPP/7K+ihiDjguZTc4nE7VxLwIrZz 2jan04oqt8dPLwpb6GoK79THwjZtLlQ4y7xteW8e6i0eeVTb5ueM+idJh6qKcIw4YcRG CcIwhyIYYpCpQVpnBn5dK0FgWCac6zWLqaQrT6wKgXU8RsK8ppar1tezrYB0v+P6ZoXm GN6Iv9Z7A4YCOKQjMu45AzDIEys68/mmgAfdl+xI9B89D0jz+Bk7yLp6RmD5s1IDf5E6 nVHcDxGHe2Y04tJJnY65EHR3xIgr/6qeg40LArtR74iRLdghYDC5ojxkXn+64fyba3/4 UlVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737721360; x=1738326160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gpGzGxY7oS9vaBZmel27t8qPVdpHHnYzoe18NAokJLQ=; b=DjRJQJvYNgW9yO657XWPeAMQKQrnivNz7JOtAZ6O3ZfsOYh7TriNM8Uex09W9y5qp0 2utvVov5NUaX3ltzDi2IGBC+QG0+JNEq1Ey2OA5sxpQFIwp6EGkK7WNcbzKdv+gaoh4K +EaHLAaizqSmIYT1BenLlnxfUuMwWItkY4AEN7B0KasUifM/NibLw4OhCa8QOqy5QW+8 A7gqpHd2vUoUJ9BIBCNzqtHFDvzGD3SAKjz42/l3OjCQTGPvCoOZYWlaPamIskiG6VAW GNEJoNY/p6WTCpAopWLjh3tyvLWbsjwlXijU6cnZ3iObKHJQJAQJT4HYJPK/wVVOmQtG aujg== X-Gm-Message-State: AOJu0YzNv553QyxvVdFaYBbcP3HpInUq1X4jnYRdA0Y0N4pEbu8rDhp6 ybvrxvmG/99m9MoMtRfHfsTth78aOxgcN4g9xE8FaVOsZ5qKRRFY3+mYkIeFi2M= X-Gm-Gg: ASbGncv5vi7gb0mv18ctqbhA2I6qRu6/6P65D9mNYyF9vDpEHMs6r53Gb/zuZQJNTVx 6A7XC+USUKbe7Gksztr9UkljRRs9swnXlyOfr78Xaz3auixVdESft0jELBJ0qPTgYQ0ZmctAYf9 o3jDhAa6PjRSUx/czIBgKE/3mxKATLUo/AeMgQK17pbmipnnBVczb6GHIAB7N+bGH+Cs6IZqrUn 4nrneHxUDOGZd8wSug7GpXdm5cFVS0YQYEBXeArVImAEgYlsCvmC/TpSMtsgXspGrc3dRu/Xp96 or8u/ox94tuRlktudI1aDo+MsowIc9c4w84aXRYl X-Google-Smtp-Source: AGHT+IFvLzIcS89ADVEIU9YH0NVdBQLtYKmvXIZpezNvstgwk1l9wSZ0/H0PAfdTuTv9YQIvGh54PQ== X-Received: by 2002:a17:90b:4c06:b0:2f2:a796:26b with SMTP id 98e67ed59e1d1-2f782c65719mr39084495a91.1.1737721359624; Fri, 24 Jan 2025 04:22:39 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7ffb1dc56sm1685056a91.49.2025.01.24.04.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 04:22:39 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v3 4/6] version: extend get_uname_info() to hide system details Date: Fri, 24 Jan 2025 17:51:39 +0530 Message-ID: <20250124122217.250925-5-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250124122217.250925-1-usmanakinyemi202@gmail.com> References: <20250117104639.65608-1-usmanakinyemi202@gmail.com> <20250124122217.250925-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, get_uname_info() function provides the full OS information. In a following commit, we will need it to provide only the OS name. Let's extend it to accept a "full" flag that makes it switch between providing full OS information and providing only the OS name. We may need to refactor this function in the future if an `osVersion.format` is added. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/bugreport.c | 2 +- version.c | 16 +++++++++------- version.h | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 5e13d532a8..e3288a86c8 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -24,7 +24,7 @@ static void get_system_info(struct strbuf *sys_info) /* system call for other version info */ strbuf_addstr(sys_info, "uname: "); - get_uname_info(sys_info); + get_uname_info(sys_info, 1); strbuf_addstr(sys_info, _("compiler info: ")); get_compiler_info(sys_info); diff --git a/version.c b/version.c index 3ec8b8243d..d95221a72a 100644 --- a/version.c +++ b/version.c @@ -49,7 +49,7 @@ const char *git_user_agent_sanitized(void) return agent; } -int get_uname_info(struct strbuf *buf) +int get_uname_info(struct strbuf *buf, unsigned int full) { struct utsname uname_info; @@ -59,11 +59,13 @@ int get_uname_info(struct strbuf *buf) errno); return -1; } - - strbuf_addf(buf, "%s %s %s %s\n", - uname_info.sysname, - uname_info.release, - uname_info.version, - uname_info.machine); + if (full) + strbuf_addf(buf, "%s %s %s %s\n", + uname_info.sysname, + uname_info.release, + uname_info.version, + uname_info.machine); + else + strbuf_addf(buf, "%s\n", uname_info.sysname); return 0; } diff --git a/version.h b/version.h index afe3dbbab7..5eb586c0bd 100644 --- a/version.h +++ b/version.h @@ -12,6 +12,6 @@ const char *git_user_agent_sanitized(void); Return -1 and put an error message into 'buf' in case of uname() error. Return 0 and put uname info into 'buf' otherwise. */ -int get_uname_info(struct strbuf *buf); +int get_uname_info(struct strbuf *buf, unsigned int full); #endif /* VERSION_H */ From patchwork Fri Jan 24 12:21:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13949336 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BC0821C16B for ; Fri, 24 Jan 2025 12:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721366; cv=none; b=ZXkC31PHhzXsdWDH2WUz8fBMqpVSLtyAasCvQorjnCyDQqKHKYo3i7bMs1cNibADpBO7YFLj89Ojwfr5lH7SMHnLpEc5Cb6bbGN4s1ecQeBcNrqgsxmvej5c39o+514Ye5vVbnS5wQxV4ZCGx2Rcbqm9ZYZZJjnF9bf5s1wz7IQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721366; c=relaxed/simple; bh=zRS732PVY28DhGLlZNkxyAGaGfpuf+y/r0q3gyo8S1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kVecVW5Nx+b4IjPdFCRLxDyZfB4NjsZChP1fqnhXWVxBO/lI+KDBYeWZS7B9fFrFd93qXMIt7/QMglTWWkDbeKn6TI9tTDO9TzCWZyhkOqiPA3U6XFh33eDvrB/HVRW1rhrhZkQ7k6kDh6WxOW+jCJY42kx+yUNvUG4QhrHuxPw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LJlpCZbR; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LJlpCZbR" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2ee8aa26415so3657799a91.1 for ; Fri, 24 Jan 2025 04:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737721363; x=1738326163; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0KGvJcJNDa0j7iQjZZ2ooP1DPcHkTZ3keVk2fmUa7PI=; b=LJlpCZbRiCkHGKSdRYcSX2y4tRJIqy8RGUCEhhMAJqYVMKB+7KvLXHq/Zow8kQsZlS UFj3gPKLH0JXkxGkgRItF4CWDUQVsdSz85ZaIBysMIR7+zr8JvTWArD2kItwZgTJWgM/ VbC+Pk6lSYmHBGOg1oN19gUAIZ5JqsJH8Vs5x6GOT7LW6bhdomIsBg1zqzEJcRiNf4EA YzUQe1eq7qC1GleAHusCDGbGA6Z413y9I/1h+W/Eyf/cKnlTYFci2Ox14Uh3euiuQEXr CQl/KyQf7NpqH6JrYd77w6MvO+w7tqw3nKNHxu7kNy3CsAfxjxoQ75ypXEHEjUBYxRnT 7R+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737721363; x=1738326163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0KGvJcJNDa0j7iQjZZ2ooP1DPcHkTZ3keVk2fmUa7PI=; b=MdabCwpuE+eesfSAyev7JIFGUS14Fy45jJbtGpre/Ud4nBEfqBA0705qDsEd499TSp 8YoGEe7DQhmd9Tg7COYkRD7ISx4x8L2DTLsX/yNudDFq25RMajOICgZaRIAIcxWy3hnh edE2I4P5FjJrVy1/dV+GyZsmyJWUtKBewdR1M9C6yASuVLyaQzjhHn0NnbrMQiwXwUfo ajfd3PR3yQVCeNv3cpPqEunDVNzE5LH41pCdY4rjBAHcWtVR6b0IeyxRN1IyaaHaf3Ja uwMgCcYrZJEREtpaXdMq4tY9XaB6XJTLMRkRdPPLSyal8YI8rbVrZ0eXvaVTe3fxFOuW K6hA== X-Gm-Message-State: AOJu0Yz8AqboMUXxA6TK9rsQmNKTUZ6r1niy9q2XveqgQ0YgyAAedatr Jm5s7VtlTTJMMwKQwYsgRWRw99SGbL9uGrr0bLmxpOnN0iXroTh9s9oA5En7iDY= X-Gm-Gg: ASbGncvCacnKBVznQ7SQyLrL8iVtLHUMkNLdYsaow0LQvaMj5Uq81hk0KUBCGv3TWCp yhAx+JP+1L0D1VCB0h9/opBGaMe5e/pPAmJwyrgvkbz/WOvD0MZFCUb1dks/uYgSN7NGHYoHedy WUKEsjWLC/8Mkq9CAbo4Egz7hBw3sJo1Eai1N7UQM/yTmJSqaVZolGEH4Wmc3eYbn/NANNODOsa azq8/MjzGR21KGHH0MP1gq/cubKbMDUh1KAS1jVba1DA97bfFVvkuCnLm7JwfEcZHeQYyuQzvBw nJaITkg/JAvrSbCZVnJBLT6QkRsBtg== X-Google-Smtp-Source: AGHT+IGJhJLf0QZ8+5cSiHKw+g/FXagN2b77GOPRazRfmcG2Dh7pOMQ8asu720gkuBdDMBZzR7GjEA== X-Received: by 2002:a17:90b:38d0:b0:2ee:d35c:3996 with SMTP id 98e67ed59e1d1-2f782d972f5mr42773258a91.31.1737721363604; Fri, 24 Jan 2025 04:22:43 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7ffb1dc56sm1685056a91.49.2025.01.24.04.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 04:22:43 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v3 5/6] t5701: add setup test to remove side-effect dependency Date: Fri, 24 Jan 2025 17:51:40 +0530 Message-ID: <20250124122217.250925-6-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250124122217.250925-1-usmanakinyemi202@gmail.com> References: <20250117104639.65608-1-usmanakinyemi202@gmail.com> <20250124122217.250925-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, the "test capability advertisement" test creates some files with expected content which are used by other tests below it. To remove that side-effect from this test, let's split up part of it into a "setup"-type test which creates the files with expected content which gets reused by multiple tests. This will be useful in a following commit. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- t/t5701-git-serve.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index de904c1655..9394235fa0 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -7,22 +7,28 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh -test_expect_success 'test capability advertisement' ' +test_expect_success 'setup to generate files with expected content' ' + printf "agent=git/%s\n" "$(git version | cut -d" " -f3)" >agent_and_osversion && + test_oid_cache <<-EOF && wrong_algo sha1:sha256 wrong_algo sha256:sha1 EOF + cat >expect.base <<-EOF && version 2 - agent=git/$(git version | cut -d" " -f3) + $(cat agent_and_osversion) ls-refs=unborn fetch=shallow wait-for-done server-option object-format=$(test_oid algo) EOF - cat >expect.trailer <<-EOF && + cat >expect.trailer <<-EOF 0000 EOF +' + +test_expect_success 'test capability advertisement' ' cat expect.base expect.trailer >expect && GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ From patchwork Fri Jan 24 12:21:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13949337 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D010A21B18B for ; Fri, 24 Jan 2025 12:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721370; cv=none; b=Qceco3MK7wtKq2jLfCqQsyNICcfgArk5u+NDkxiw/MP6zzYgyV7fODciw14bqUYzRLiwzsEHnYbcixY+dx3vqpKkPqHOwPDqOPpe8Bb6CA8lSAPx+C+VRrJifylqsqY5DrRxS3WUMazDP8DYD7+WEVNEkk0/PePG/LlEsLrMc+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737721370; c=relaxed/simple; bh=XDzP5FUTHWcW9VdhuboD9tkdIe3EIlJJFBQ/2AMpNwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uwUdI97aXMY5+oNrgjMkyQxiCIcjtpZRZE8f2MBL7A/qbiuPybDb3w0NZHAStSTp8NAV4QICxpWdeoUAEF3aGSH1IdcY2iAayDvJ0RDNJ8XE4xWgYiBEO1lq8vj/XoPr/xPhod7tomRzAwJ4IEhQxqFBbN3FtXW0DinGddAbubE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b/TMJdLZ; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b/TMJdLZ" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2ef8c012913so2844728a91.3 for ; Fri, 24 Jan 2025 04:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737721368; x=1738326168; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u0RGhRZj7ahTqaxMDHxR33RmBZ+Rn4bY4D0TfaAF3YM=; b=b/TMJdLZDPirCdAR1VhrPRY68Yu4JFcp6DqUuay3TtLx8J/hJ3o9BZ8YVZ7vs3CmQt nGZf4e/P3TpmVZXrK6CRgwn5OUwN3xEHBuEpLPitMc5av6hGtU67upXH/9U/AWpyAjkT +7evy2ed2Vo9fxy0XM9zuZA4u2xVvIIr1OGxuABHWO1NUyCdcbj3xvBN5QvZYA08IGdl zP/qHWqtXNU4dz2qeW0cAAPEeGL6xFBeNjZeaqZn/9A8QyIHcz+PhsxBDfH7I+YqOPN3 I261juiKooQJX8WDpJNLteLhZ+j29mDXWnqpQd3RNp1226gjec0ZlCkm+eN29vves7SC oNJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737721368; x=1738326168; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u0RGhRZj7ahTqaxMDHxR33RmBZ+Rn4bY4D0TfaAF3YM=; b=NkNR2+W85PUdT4UCh2g06/1HUyy1i73Didjx5fISKskOtXpjKsWz241Djy5SB57Q9d /MREFnAQPfNPnXDLRaTBa1Xvg0tEExbOcjhes/bfNL2eQOolAJU4zBy7AEVD8vmJKpBu PMelWI56Pr5yWYvSzJndihpTMGRAVNspaadUu8EwCLNDJSLDiX459TyITgcJq5fr36tq FJrxX8N7fSnBuqVBIGYn75WmjB81GlPrfdmR9knVYDM0lVLEtd8VqVKyvVUWLYH9JuSW 3I83HsPLLV6CAxrn41d6aEQGLJBDS23uS/LZPL8UHvr1ghqG3VLsHRM/wLErjFeD5gVq eEsw== X-Gm-Message-State: AOJu0YzLuGbYHK7sL57irPB75vSkorgqhGADKibKtTadg4QKXHwjxyW0 tx/6GqlWKRN5wGi3l6K95WCSDQXWXOrkRmqZ9ycP9UlIBHBXNm+5DEk5DqE80TM= X-Gm-Gg: ASbGncsU7p+f+MjqUMHPUbNkRf1Tvai2cAO39rW//6kGcmaRGzBg65AUrLzy3WNODmy QXubrA+S91StmIeJywihqHBAcQC1clg0MwmnUYdDR05HKkrXilj7q2F1NYUyv6Uu9r/mC4Yyu45 3n23WW2aiFxamvJfXzm+XwGYEbMtTP9em5qlUHZZcOEnvXyPg9nvk+e5uhUDjt4nfGk+E9WzAxd Od3Oz0Ka5/45jmzhx093SjV7rLOeLnjw1bSdxTzO9ITn7oiVN8wmvnwved0Fmjwl4YqwL3jqXgE YXvDWxHmncjtjgdFcIAhS9fc1gjwMw== X-Google-Smtp-Source: AGHT+IHH9iMp5RB2ftMPGSjS5/+eqST7JB0MheopLQjS6mqi7okFPksuqbQG4qT3+6ddqCMHm3iclA== X-Received: by 2002:a17:90b:5249:b0:2ee:9d57:243 with SMTP id 98e67ed59e1d1-2f782c4c9f0mr38749421a91.1.1737721367641; Fri, 24 Jan 2025 04:22:47 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7ffb1dc56sm1685056a91.49.2025.01.24.04.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 04:22:47 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v3 6/6] connect: advertise OS version Date: Fri, 24 Jan 2025 17:51:41 +0530 Message-ID: <20250124122217.250925-7-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250124122217.250925-1-usmanakinyemi202@gmail.com> References: <20250117104639.65608-1-usmanakinyemi202@gmail.com> <20250124122217.250925-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As some issues that can happen with a Git client can be operating system specific, it can be useful for a server to know which OS a client is using. In the same way it can be useful for a client to know which OS a server is using. Let's introduce a new protocol (`os-version`) allowing Git clients and servers to exchange operating system information. Having the `os-version` protocol capability separately from other protocol capabilities like `agent` is beneficial in ways like: - It provides a clear separation between Git versioning and OS-specific, concerns making troubleshooting and environment analysis more modular. - It ensures we do not disrupt people's scripts that collect statistics from other protocol capabilities like `agent`. - It offers flexibility for possible future extensibility, allowing us to add additional system-level details without modifying existing `agent` parsing logic. - It provides better control over privacy and security by allowing selective exposure of OS information. Add the `transfer.advertiseOSVersion` config option to address privacy concerns. It defaults to `true` and can be changed to `false`. When enabled, this option makes clients and servers send each other the OS name (e.g., "Linux" or "Windows"). The information is retrieved using the 'sysname' field of the `uname(2)` system call or its equivalent. However, there are differences between `uname(1)` (command-line utility) and `uname(2)` (system call) outputs on Windows. These discrepancies complicate testing on Windows platforms. For example: - `uname(1)` output: MINGW64_NT-10.0-20348.3.4.10-87d57229.x86_64\ .2024-02-14.20:17.UTC.x86_64 - `uname(2)` output: Windows.10.0.20348 On Windows, uname(2) is not actually system-supplied but is instead already faked up by Git itself. We could have overcome the test issue on Windows by implementing a new `uname` subcommand in `test-tool` using uname(2), but except uname(2), which would be tested against itself, there would be nothing platform specific, so it's just simpler to disable the tests on Windows. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- Documentation/config/transfer.txt | 7 +++++++ Documentation/gitprotocol-v2.txt | 17 +++++++++++++++++ connect.c | 3 +++ serve.c | 14 ++++++++++++++ t/t5555-http-smart-common.sh | 10 +++++++++- t/t5701-git-serve.sh | 22 +++++++++++++++++++--- t/test-lib-functions.sh | 8 ++++++++ version.c | 29 +++++++++++++++++++++++++++++ version.h | 15 +++++++++++++++ 9 files changed, 121 insertions(+), 4 deletions(-) diff --git a/Documentation/config/transfer.txt b/Documentation/config/transfer.txt index f1ce50f4a6..016eb27430 100644 --- a/Documentation/config/transfer.txt +++ b/Documentation/config/transfer.txt @@ -125,3 +125,10 @@ transfer.bundleURI:: transfer.advertiseObjectInfo:: When `true`, the `object-info` capability is advertised by servers. Defaults to false. + +transfer.advertiseOSVersion:: + When set to `true` on the server, the server will advertise its + `os-version` capability to the client. On the client side, if set + to `true`, it will advertise its `os-version` capability to the + server only if the server also advertises its `os-version` capability. + Defaults to true. diff --git a/Documentation/gitprotocol-v2.txt b/Documentation/gitprotocol-v2.txt index 1652fef3ae..62f7ae3423 100644 --- a/Documentation/gitprotocol-v2.txt +++ b/Documentation/gitprotocol-v2.txt @@ -190,6 +190,23 @@ printable ASCII characters except space (i.e., the byte range 32 < x < and debugging purposes, and MUST NOT be used to programmatically assume the presence or absence of particular features. +os-version +~~~~~~~~~~ + +In the same way as the `agent` capability above, the server can +advertise the `os-version` capability to notify the client the +kind of operating system it is running on. The client may optionally +send its own `os-version` capability, to notify the server the kind +of operating system it is also running on in its request to the server +(but it MUST NOT do so if the server did not advertise the os-version +capability). The value of this capability may consist of ASCII printable +characters(from 33 to 126 inclusive) and are typically made from the +result of `uname -s`(OS name e.g Linux). The os-version capability can +be disabled entirely by setting the `transfer.advertiseOSVersion` config +option to `false`. The `os-version` strings are purely informative for +statistics and debugging purposes, and MUST NOT be used to +programmatically assume the presence or absence of particular features. + ls-refs ~~~~~~~ diff --git a/connect.c b/connect.c index 10fad43e98..6d5792b63c 100644 --- a/connect.c +++ b/connect.c @@ -492,6 +492,9 @@ static void send_capabilities(int fd_out, struct packet_reader *reader) if (server_supports_v2("agent")) packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized()); + if (server_supports_v2("os-version") && advertise_os_version(the_repository)) + packet_write_fmt(fd_out, "os-version=%s", os_version_sanitized()); + if (server_feature_v2("object-format", &hash_name)) { int hash_algo = hash_algo_by_name(hash_name); if (hash_algo == GIT_HASH_UNKNOWN) diff --git a/serve.c b/serve.c index c8694e3751..5b0d54ae9a 100644 --- a/serve.c +++ b/serve.c @@ -31,6 +31,16 @@ static int agent_advertise(struct repository *r UNUSED, return 1; } +static int os_version_advertise(struct repository *r, + struct strbuf *value) +{ + if (!advertise_os_version(r)) + return 0; + if (value) + strbuf_addstr(value, os_version_sanitized()); + return 1; +} + static int object_format_advertise(struct repository *r, struct strbuf *value) { @@ -123,6 +133,10 @@ static struct protocol_capability capabilities[] = { .name = "agent", .advertise = agent_advertise, }, + { + .name = "os-version", + .advertise = os_version_advertise, + }, { .name = "ls-refs", .advertise = ls_refs_advertise, diff --git a/t/t5555-http-smart-common.sh b/t/t5555-http-smart-common.sh index e47ea1ad10..b1af37a4a2 100755 --- a/t/t5555-http-smart-common.sh +++ b/t/t5555-http-smart-common.sh @@ -123,9 +123,17 @@ test_expect_success 'git receive-pack --advertise-refs: v1' ' ' test_expect_success 'git upload-pack --advertise-refs: v2' ' + printf "agent=FAKE\n" >agent_and_osversion && + if test_have_prereq WINDOWS + then + git config transfer.advertiseOSVersion false + else + printf "os-version=%s\n" $(uname -s | test_redact_non_printables) >>agent_and_osversion + fi && + cat >expect <<-EOF && version 2 - agent=FAKE + $(cat agent_and_osversion) ls-refs=unborn fetch=shallow wait-for-done server-option diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index 9394235fa0..2616132b95 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -23,13 +23,29 @@ test_expect_success 'setup to generate files with expected content' ' server-option object-format=$(test_oid algo) EOF - cat >expect.trailer <<-EOF + cat >expect.trailer <<-EOF && 0000 EOF + + if test_have_prereq WINDOWS + then + git config transfer.advertiseOSVersion false + else + printf "os-version=%s\n" $(uname -s | test_redact_non_printables) >>agent_and_osversion + fi && + + cat >expect_osversion.base <<-EOF + version 2 + $(cat agent_and_osversion) + ls-refs=unborn + fetch=shallow wait-for-done + server-option + object-format=$(test_oid algo) + EOF ' test_expect_success 'test capability advertisement' ' - cat expect.base expect.trailer >expect && + cat expect_osversion.base expect.trailer >expect && GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ --advertise-capabilities >out && @@ -357,7 +373,7 @@ test_expect_success 'test capability advertisement with uploadpack.advertiseBund cat >expect.extra <<-EOF && bundle-uri EOF - cat expect.base \ + cat expect_osversion.base \ expect.extra \ expect.trailer >expect && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 78e054ab50..3465904323 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -2007,3 +2007,11 @@ test_trailing_hash () { test-tool hexdump | sed "s/ //g" } + +# Trim and replace each character with ascii code below 32 or above +# 127 (included) using a dot '.' character. +# Octal intervals \001-\040 and \177-\377 +# correspond to decimal intervals 1-32 and 127-255 +test_redact_non_printables () { + tr -d "\n\r" | tr "[\001-\040][\177-\377]" "." +} diff --git a/version.c b/version.c index d95221a72a..083154a6cb 100644 --- a/version.c +++ b/version.c @@ -4,6 +4,7 @@ #include "strbuf.h" #include "sane-ctype.h" #include "gettext.h" +#include "config.h" const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; @@ -69,3 +70,31 @@ int get_uname_info(struct strbuf *buf, unsigned int full) strbuf_addf(buf, "%s\n", uname_info.sysname); return 0; } + +const char *os_version_sanitized(void) +{ + static const char *os = NULL; + + if (!os) { + struct strbuf buf = STRBUF_INIT; + + get_uname_info(&buf, 0); + /* Sanitize the os information immediately */ + redact_non_printables(&buf); + os = strbuf_detach(&buf, NULL); + } + + return os; +} + +int advertise_os_version(struct repository *r) +{ + static int transfer_advertise_os_version = -1; + + if (transfer_advertise_os_version == -1) { + repo_config_get_bool(r, "transfer.advertiseosversion", &transfer_advertise_os_version); + /* enabled by default */ + transfer_advertise_os_version = !!transfer_advertise_os_version; + } + return transfer_advertise_os_version; +} diff --git a/version.h b/version.h index 5eb586c0bd..300ee73df5 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,8 @@ #ifndef VERSION_H #define VERSION_H +struct repository; + extern const char git_version_string[]; extern const char git_built_from_commit_string[]; @@ -14,4 +16,17 @@ const char *git_user_agent_sanitized(void); */ int get_uname_info(struct strbuf *buf, unsigned int full); +/* + Retrieve, sanitize and cache system information for subsequent + calls. Return a pointer to the sanitized system information + string. +*/ +const char *os_version_sanitized(void); + +/* + Retrieve and cache whether os-version capability is enabled. + Return 1 if enabled, 0 if disabled. +*/ +int advertise_os_version(struct repository *r); + #endif /* VERSION_H */