From patchwork Wed Oct 23 07:40:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13846611 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.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 A931D14A639 for ; Wed, 23 Oct 2024 07:40:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729669227; cv=none; b=mVR0Ga2owuwZwBjkMo9TxYsJJWzYog6wVBiURUO1WCx2PADPiU/fF4fl5tlj7gkKlmS3HUY4++0xd82e32u6WAQOm5RyGpyqVgNdLnybK3LGB6p1sz/ZpmrUXnQkn4ZlfFVGRCHkY3kj7Z0BWy1NiBrbaVtxrfnrCkabQd3rhY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729669227; c=relaxed/simple; bh=deKq+A9LnK+oqwjEPHhGiFvL8WASgJwQOit1fL5TJwA=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=DvaG5yQkLc4bulhJjDeA5AtCUeLwdQDt4s2amIoa39+sKZACWpKij4yiWJDxEICHlvOwtT3TmgtT0HA7K3wzMmEDY2y8ypn3mHuM6SVJXc7BUluXb/7jCN4t6KDih6e5XmN3IeIHt7UKrF3vXwNP9bux3QHGExOlPYMuBIWXs8M= 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=ELKlTTPw; arc=none smtp.client-ip=209.85.218.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="ELKlTTPw" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a9a6acac4c3so776179466b.0 for ; Wed, 23 Oct 2024 00:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729669224; x=1730274024; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=z3kU7eI+PYLSlOBjI4sp2ao+VRlCLuTcWtBPICI1TrI=; b=ELKlTTPw6ckHLVjR0gewBRelFp23/1bg5Y/zPZMfEBzagLIJoX1UqwcTitx5/lfN1l KgmQNKdDNh1Tugr+FAbwE4zB1UfcZ9CW3rhW6om/WLUfZ68WKn90+mnsh7G0D56kS8lW lkVvXAx9RkGcaR7q+GQCG9ZIADvfAbs3oD2muPlAErazQS/Nrt3Yg6I0etUTjlNMcz1c D25aXZJw9psdcSK4pHJDRf/yBh/61DlrQ8zCLQRvbqMGTTyZV2J17HQEyLsKaNr20kFE WrqPbVu6ImuMkKDOyl264UbywCigE+WNmqAtav7Wai9PGo6ce0Wt47NWllfrJKNL8RGs WAvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729669224; x=1730274024; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z3kU7eI+PYLSlOBjI4sp2ao+VRlCLuTcWtBPICI1TrI=; b=d+L6u1QPhnrAmPSNssUq1PGt5D2FeZ4VtI/Eb4/2dxCFe2B/4ZJ88JMP3tLBNvO+XP oBx7SqxAm8CCtw4uLPBJN4phjynGvl6hkFi5pzoCe5KMrjI5NbUxv5QS7bTKOPV8ofwD LG4HF/6IOFB9J7Nj2JpP6VqfQrvk1H4UZ38/RrF7+te7UcHFvfOCRw04IXvhqr8LvYn2 5+KCCtcHb3jDc8cbuvYOgaremmrDc7AhNZm1gjbWuaZSzZARRa6x9Hvb3WQVH7JSrqlt YR1a3qN0u+Wh4ndgYwLLP5YPii2bJ7ZLwPiEACVZh0OwuosT+fxks7OwrRMxqAAjZgBp qIDQ== X-Gm-Message-State: AOJu0YxlOdJOao0Z4Wi0i/TcEWFmwQgD1mzzG0M9XPz+yB7moC51vhYc inLTEjveanNnEvw8QlRSUjLejR9DcdC3UDvg0G4tJdaKgqfXUtR0F5jrjA== X-Google-Smtp-Source: AGHT+IEtQ399TQ4WbGr3IImGZX9lS1zovBudUC6jhjEfTyFMbX77WqMQYHN6XSZgxD3HvqWfp7/YTg== X-Received: by 2002:a17:907:9452:b0:a99:8178:f7ed with SMTP id a640c23a62f3a-a9abf845edcmr156571766b.4.1729669223383; Wed, 23 Oct 2024 00:40:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d6551sm435621666b.39.2024.10.23.00.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 00:40:22 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 23 Oct 2024 07:40:18 +0000 Subject: [PATCH v5 1/3] daemon: replace atoi() with strtoul_ui() and strtol_i() Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Patrick Steinhardt , Usman Akinyemi , Usman Akinyemi From: Usman Akinyemi From: Usman Akinyemi Replace atoi() with strtoul_ui() for --timeout and --init-timeout (non-negative integers) and with strtol_i() for --max-connections (signed integers). This improves error handling and input validation by detecting invalid values and providing clear error messages. Update tests to ensure these arguments are properly validated. Signed-off-by: Usman Akinyemi --- daemon.c | 12 ++++++++---- t/t5570-git-daemon.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/daemon.c b/daemon.c index cb946e3c95f..a40e435c637 100644 --- a/daemon.c +++ b/daemon.c @@ -4,6 +4,7 @@ #include "abspath.h" #include "config.h" #include "environment.h" +#include "gettext.h" #include "path.h" #include "pkt-line.h" #include "protocol.h" @@ -1308,17 +1309,20 @@ int cmd_main(int argc, const char **argv) continue; } if (skip_prefix(arg, "--timeout=", &v)) { - timeout = atoi(v); + if (strtoul_ui(v, 10, &timeout)) + die(_("invalid timeout '%s', expecting a non-negative integer"), v); continue; } if (skip_prefix(arg, "--init-timeout=", &v)) { - init_timeout = atoi(v); + if (strtoul_ui(v, 10, &init_timeout)) + die(_("invalid init-timeout '%s', expecting a non-negative integer"), v); continue; } if (skip_prefix(arg, "--max-connections=", &v)) { - max_connections = atoi(v); + if (strtol_i(v, 10, &max_connections)) + die(_("invalid max-connections '%s', expecting an integer"), v); if (max_connections < 0) - max_connections = 0; /* unlimited */ + max_connections = 0; /* unlimited */ continue; } if (!strcmp(arg, "--strict-paths")) { diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh index c5f08b67996..722ddb8b7fa 100755 --- a/t/t5570-git-daemon.sh +++ b/t/t5570-git-daemon.sh @@ -8,6 +8,32 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-git-daemon.sh + +test_expect_success 'daemon rejects invalid --init-timeout values' ' + for arg in "3a" "-3" + do + test_must_fail git daemon --init-timeout="$arg" 2>actual_error && + test_write_lines "fatal: invalid init-timeout ${SQ}$arg${SQ}, expecting a non-negative integer" >expected && + test_cmp actual_error expected || return 1 + done +' + +test_expect_success 'daemon rejects invalid --timeout values' ' + for arg in "3a" "-3" + do + test_must_fail git daemon --timeout="$arg" 2>actual_error && + test_write_lines "fatal: invalid timeout ${SQ}$arg${SQ}, expecting a non-negative integer" >expected && + test_cmp actual_error expected || return 1 + done +' + +test_expect_success 'daemon rejects invalid --max-connections values' ' + arg='3a' && + test_must_fail git daemon --max-connections=3a 2>actual_error && + test_write_lines "fatal: invalid max-connections ${SQ}$arg${SQ}, expecting an integer" >expected && + test_cmp actual_error expected +' + start_git_daemon check_verbose_connect () { From patchwork Wed Oct 23 07:40:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13846612 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 394C4155324 for ; Wed, 23 Oct 2024 07:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729669228; cv=none; b=LaETJ0AsC3wyZfB3KfTCv1UnzV7kPdPpAnqRP6LO+A7zGXFezv+iD78xvkKz+Fgvq9AAcvDuvO4Y93bTnTJH1HUVgo/SJs9na9O40yI+k4b0AvaT4iXW+J+dZ604UOYmHp5kc1vMdj92zQz/lOwbTJliejkb/Dj+sbdQUQh2AZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729669228; c=relaxed/simple; bh=5GzF9PCgCy1dVVZT3Al79NQtBgiC3194rw0GgjPbASo=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=CxLWxbRX4W37oO9rfJtNBCqu/yMpHeeFlxdrbhMnRS3iIXSYTCFx7INTDt+XWNVcrKKZId0A5pfVaHAq58d9AgKYdh2XMXXPLgBhUWekukaCBftdTC2CMbeCWhUYsLa2IFhGd19872E0SBIVk+ai/9iSphBDh5V59//tjJOGcSc= 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=ccA1be/f; arc=none smtp.client-ip=209.85.208.46 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="ccA1be/f" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5c9404c0d50so6565072a12.3 for ; Wed, 23 Oct 2024 00:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729669225; x=1730274025; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Nj2UQx1KomWHqTK06lThO2xY+it9ugdnkesFNhRwTqQ=; b=ccA1be/f8Iyt/a4VW8rjBkb41KnuPhU04yIs7sXJzuT8RkVEbrewOXqLB5f7zmZuuB 29GU0hFXuxnsHe1pRQUb1c6d2QNLI7icUV3hwwuTNm+0ndCNBK5sroA1lWUCncY8ZSfW yS4UzulSebwSVDlogs8h+4xaoj4l6hIZl1XYz6+dpZ25ql/AoOvsK6gE+JXqwkbBTsN1 attYJ2cFkoRvfg8HcZ4FDhC6ufpvc5UiL/eGONCB3LYQipo+jDZKMj6+rqqCjYD06EDU gJEVBQYfvppbEnABhzjRKoYCkCbB4JVFqDgsgbFudBeN+qzP3cBT2cBZMvlb3I54YO7m XFvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729669225; x=1730274025; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nj2UQx1KomWHqTK06lThO2xY+it9ugdnkesFNhRwTqQ=; b=ny5stMn58x4h0QRdbMym5TrBQBa0JQgp76en2eSG9mo9H/a1gO4BFbwW0pY5KJQcoH YFUYhqko+VnF1dp0kIQuQyf2PYjsRPIJG78tIm4JBMvrQSIj/xYa8mMY8wqIdOSZ1cwS xNtrzgH5Fh5qKFgIavvFCRLu1w3EpGUExf+/grpzvGscVSr66XPzzOP8QmGAnqHzCNFB 80AMf8lR8WQ7cOb4PEW6B3PA8HQ7I78Fq+Sd5DAVYYOZulZVhtj8B4VhdCvl++MOODmd VV6uQ+dRjiideQLILPwkEi3OOWN99t7BQ/5/viGL9gdYfFNmdhaOgBFzS71lY/Iv1MAp r0Dw== X-Gm-Message-State: AOJu0YwGZFGenZiJlbDy+OPqkQtoIQNipmN7SE6cNcoDL6XVRL2qtmZj lPRAA1YmWMohtNTRyWdtngZRhoGHZwKKScP7IpDCafHutZs/tsMjWBXwrg== X-Google-Smtp-Source: AGHT+IGqPqJtd9sV43BPNWh0UHq9b6v3/1sj3fh3E47RnONGgjhLFH+P+pLwOG1rOSKuigVAotSlvA== X-Received: by 2002:a05:6402:1d4f:b0:5ca:14fa:dc87 with SMTP id 4fb4d7f45d1cf-5cb8acee294mr1249689a12.15.1729669224933; Wed, 23 Oct 2024 00:40:24 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c725dfsm4021170a12.81.2024.10.23.00.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 00:40:24 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 23 Oct 2024 07:40:19 +0000 Subject: [PATCH v5 2/3] merge: replace atoi() with strtol_i() for marker size validation Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Patrick Steinhardt , Usman Akinyemi , Usman Akinyemi From: Usman Akinyemi From: Usman Akinyemi Replace atoi() with strtol_i() for parsing conflict-marker-size to improve error handling. Invalid values, such as those containing letters now trigger a clear error message. Update the test to verify invalid input handling. Signed-off-by: Usman Akinyemi --- merge-ll.c | 11 +++++++++-- t/t6406-merge-attr.sh | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/merge-ll.c b/merge-ll.c index 8e63071922b..62fc625552d 100644 --- a/merge-ll.c +++ b/merge-ll.c @@ -15,6 +15,7 @@ #include "merge-ll.h" #include "quote.h" #include "strbuf.h" +#include "gettext.h" struct ll_merge_driver; @@ -427,7 +428,10 @@ enum ll_merge_result ll_merge(mmbuffer_t *result_buf, git_check_attr(istate, path, check); ll_driver_name = check->items[0].value; if (check->items[1].value) { - marker_size = atoi(check->items[1].value); + if (strtol_i(check->items[1].value, 10, &marker_size)) { + marker_size = DEFAULT_CONFLICT_MARKER_SIZE; + warning(_("invalid marker-size '%s', expecting an integer"), check->items[1].value); + } if (marker_size <= 0) marker_size = DEFAULT_CONFLICT_MARKER_SIZE; } @@ -454,7 +458,10 @@ int ll_merge_marker_size(struct index_state *istate, const char *path) check = attr_check_initl("conflict-marker-size", NULL); git_check_attr(istate, path, check); if (check->items[0].value) { - marker_size = atoi(check->items[0].value); + if (strtol_i(check->items[0].value, 10, &marker_size)) { + marker_size = DEFAULT_CONFLICT_MARKER_SIZE; + warning(_("invalid marker-size '%s', expecting an integer"), check->items[0].value); + } if (marker_size <= 0) marker_size = DEFAULT_CONFLICT_MARKER_SIZE; } diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh index 9bf95249347..c2a9cf03808 100755 --- a/t/t6406-merge-attr.sh +++ b/t/t6406-merge-attr.sh @@ -118,6 +118,12 @@ test_expect_success 'retry the merge with longer context' ' grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual ' +test_expect_success 'invalid conflict-marker-size 3a' ' + echo "text conflict-marker-size=3a" >>.gitattributes && + git checkout -m text 2>error && + test_grep "warning: invalid marker-size ${SQ}3a${SQ}, expecting an integer" error +' + test_expect_success 'custom merge backend' ' echo "* merge=union" >.gitattributes && From patchwork Wed Oct 23 07:40:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13846613 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 88056EAC5 for ; Wed, 23 Oct 2024 07:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729669230; cv=none; b=UwUaj47yK6S3FXusotgwvSFMVxt1gQrKM0FNNCRNvQWuS2hRwRGtgxAT1IVnvuhUq13eab4uiAqWi++yTtGthJ0HdXrkh/GF5FRYSGdDN8y2U0OIQ8oeWDT+TqlfZcGdgRMcaTWWauGoVmHCqwmMrXG4nvbWnKg9MqrAdJ4R7F4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729669230; c=relaxed/simple; bh=+m7C0CcNl2NR3KoZZfHWLylLpvi2YgM1K5aK6Fqwk/g=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=u3vq49CntNHeO6ZGADvwdK6EQMAj090/oqRVsBd5T6lOcKJw4963tJKY/wZdurHCQ9/3Jlhph29BzVszx+hPLscnaAnnnwYF1eIhpHYeICik13LJelr8wwK8K2w3KEqxFsok9Ih8xOvDoWJwP086D1yq1PtqYB3OpJ5tv8D3PoU= 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=WFq6qqUj; arc=none smtp.client-ip=209.85.218.43 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="WFq6qqUj" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a9aa8895facso304246666b.2 for ; Wed, 23 Oct 2024 00:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729669226; x=1730274026; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=4Rzv7AnOxuQovJ9pw7+5rvDkRMri4p78w2Bp8gd0vNA=; b=WFq6qqUj4bwGq9xjiAlYYt/pgnVUzdkijhavExNX7F+Yjwwujqz0wP/3d8h8WZf9Bk Jp54Gumf8yI79e6+H+km+Le0doZ+LHZrlon0RgFSrKpp+Aqh24cLGrVt1cQdsR9LZdu1 gQNevNgDO8mnZjIxj5+wm5s3M6IdeH3KjpVwtfc6YZYWbK7rKfHTfhYspgg+GWCJGyV1 p0apY/N3cXFbIq89CiCcbmPkrHj/a0Fht0tdQ8f80Ve8b4dScYUGbFymKXtVK2JgPGR8 fdsodNrh/Ij2HIEZ4iJPtPJaxK+bFIbnT+/E3V/MB0MBR+cnVqbJ6gfKFA7domZEn7Ps sOmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729669226; x=1730274026; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Rzv7AnOxuQovJ9pw7+5rvDkRMri4p78w2Bp8gd0vNA=; b=F9cUPN3QdM7Je5h6f/eL1ZLq/Ml8GmmZhFGAU22+GQATtCL7kXkvqi2Of42CoAVPTj pES1GrOjcwoW5tvQSaw2wD1PFHfoJlPmm60aRyafqNwQvnsFHP91th1Ak+FLmxIdwYlY zZ6zKDipoO8igWM0Ro0ammAuIqmS70/UjNQ3sWX0RT57kRpaPuP70zwYCxnyjtsBoqCP 2XO1Jk8pdFUxuePk1mel987VMtAoIx2uzJNmgd3jce52IWaUnWKMKXv8gW6KjvwEAR5F f15DVnUEnjh+ygLz+AUvF6lFsgrwzxxr8jnQnEtWYJ6iKICHJx5t73hpgdkAx7RCQyoQ /EeA== X-Gm-Message-State: AOJu0Yyb7zj2Tegj4OB/qaVG/WdcKJJZFQwSLDJdWxfXF/07l1bWeup4 2u/ovUo06C03UtoJuz4zt9ecQ1jVVKmevP+jLE4oKyea1cHIPe37eXEH9g== X-Google-Smtp-Source: AGHT+IEvhQiVIWZcLvFNWFOixTDnTiFFW7Jx7c6wXhMA/FAHI1ASgFMR4OhluYaZSo7wvLf/ZzOj/Q== X-Received: by 2002:a17:907:1ca3:b0:a9a:6477:bd03 with SMTP id a640c23a62f3a-a9abf8a5023mr117485766b.38.1729669226344; Wed, 23 Oct 2024 00:40:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d6ef1sm430443366b.38.2024.10.23.00.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 00:40:25 -0700 (PDT) Message-Id: <9b2b2dc8fc890ff55586f890e41e54a5041bce62.1729669221.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 23 Oct 2024 07:40:20 +0000 Subject: [PATCH v5 3/3] imap: replace atoi() with strtol_i() for UIDVALIDITY and UIDNEXT parsing Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Patrick Steinhardt , Usman Akinyemi , Usman Akinyemi From: Usman Akinyemi From: Usman Akinyemi Replace unsafe uses of atoi() with strtol_i() to improve error handling when parsing UIDVALIDITY, UIDNEXT, and APPENDUID in IMAP commands. Invalid values, such as those with letters, now trigger error messages and prevent malformed status responses. I did not add any test for this commit as we do not have any test for git-imap-send(1) at this point. Signed-off-by: Usman Akinyemi --- imap-send.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/imap-send.c b/imap-send.c index ec68a066877..488c06e6139 100644 --- a/imap-send.c +++ b/imap-send.c @@ -668,12 +668,12 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb, return RESP_BAD; } if (!strcmp("UIDVALIDITY", arg)) { - if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg))) { + if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &ctx->uidvalidity) || !ctx->uidvalidity) { fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n"); return RESP_BAD; } } else if (!strcmp("UIDNEXT", arg)) { - if (!(arg = next_arg(&s)) || !(imap->uidnext = atoi(arg))) { + if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &imap->uidnext) || !imap->uidnext) { fprintf(stderr, "IMAP error: malformed NEXTUID status\n"); return RESP_BAD; } @@ -686,8 +686,8 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb, for (; isspace((unsigned char)*p); p++); fprintf(stderr, "*** IMAP ALERT *** %s\n", p); } else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) { - if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg)) || - !(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg))) { + if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &ctx->uidvalidity) || !ctx->uidvalidity || + !(arg = next_arg(&s)) || strtol_i(arg, 10, (int *)cb->ctx) || !cb->ctx) { fprintf(stderr, "IMAP error: malformed APPENDUID status\n"); return RESP_BAD; } @@ -773,7 +773,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd) if (!tcmd) return DRV_OK; } else { - tag = atoi(arg); + if (strtol_i(arg, 10, &tag)) { + fprintf(stderr, "IMAP error: malformed tag %s\n", arg); + return RESP_BAD; + } for (pcmdp = &imap->in_progress; (cmdp = *pcmdp); pcmdp = &cmdp->next) if (cmdp->tag == tag) goto gottag;