From patchwork Tue Oct 22 22:08:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13846232 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 5A09B1CCB50 for ; Tue, 22 Oct 2024 22:09:02 +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=1729634944; cv=none; b=Q4AH2oTVg4bYuMr7fwNsVrS2NCsuvZgMIKue93K83OKmyTUX5MAAHgoWkw0toq0ca0XIOmcqNlCU642xZi5/Iz6vAkK7pzCGJOrAo6o4igXz2hOzg2zGYxt/Bh2fn7Cm8hnHhNw11ICxWYD3m1fBvTsOzA2VZYMs2uymPu0a5I4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729634944; c=relaxed/simple; bh=deKq+A9LnK+oqwjEPHhGiFvL8WASgJwQOit1fL5TJwA=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=dPnmAoH2XrnYPTqhr/ZaEk4V6g6B82jWR49O6VdiFIMkLRfDxvV0WikyRSyZcJ1vYDuKDNoUd8qcQGwfW6AfzzW2u2xQ+OniJ0XayoPbdSB02rs+6FdJpn+Qtp0QTsdNi5ET2OmduAbIXpqS0nabqnFdFPIOsO+j//nsgjxZdBI= 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=gkXCNZf6; 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="gkXCNZf6" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a99f629a7aaso47406266b.1 for ; Tue, 22 Oct 2024 15:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729634940; x=1730239740; 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=gkXCNZf6GYD7mxPM14vEAnle2u3wF9eJUnktLDVPK7gkdkLNcykC+Jrcl/o79JBthX OWqziCGJHr2hFqvuONaG0jQ1pBRSnawOrD8LY4N0ulDPkj9/ib/yhfJt9DQPnNYYs5/p Jp3rJ0QlZC2JL6gcElNt4BjDibQnxyK8xxivPRJbRLgVdHEKJyGJEnAXmxI7jhd0vIDH hRif/Bemxjkc1Is4BgZ6mvAppO92fel72pHWILc4bniBpoJiH6JzfXzGzUqsGHYCzuHj e1lfQZttESpMTdz6AWe24fV2zb52RuDq1xEU2uhvDPoKF3Df4t3QI+ryqG7efWONLc0z bJJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729634940; x=1730239740; 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=M/XeZBZ/cmirV+e4Pfw0O5r/ymQJMAA2Ll9BaILI8HZcfOI+zdTwYIwUJAUZB0p6Tc 0/Gl4V8KRdmDhhCVaIK5jXyQPlGF+ymXV4WmRmQwFIidGFWtIUpS/sHQWnxIXBSQwXkt Rl8n7HXb+Mleyh1/k/OlQsPY/FBUHF0+Frov1AKdU0Jf8w4cv0FSXsTXdAeyplbf6WDB MAxJdoU4kF7SkyZahJqpG1ekMsTmFWAkfFBi/hubGy0CWVNk87EoyjSQlXK58CK1/8KE cgYOYXQ55cJdL3r1Mr32X/DofhKYI0Q49PyRGu4fDGDuk9oug8ZvZi5zj/rgz5BQ3y54 1pYA== X-Gm-Message-State: AOJu0YzTBBYM9fOgIG9iZC6zrRsgF7OsAIUOMbqzXUWU/Iswu2WupkYE 8TZIP6SUQsnXGZGm2W6FJDOHgkW30eKFnXmYwt3F3QlDUu709DNd4jivUA== X-Google-Smtp-Source: AGHT+IHoBtiIdgpe+XFheADSxgd63nN7tbXuquEcJIlL9dYB4VgQYOtMDvS7R472n7+0TawRLfrpTQ== X-Received: by 2002:a17:907:1c20:b0:a9a:762a:d71 with SMTP id a640c23a62f3a-a9aaa4f4eb5mr434257966b.4.1729634940031; Tue, 22 Oct 2024 15:09:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a915993basm389724766b.203.2024.10.22.15.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 15:08:59 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 22 Oct 2024 22:08:55 +0000 Subject: [PATCH v4 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 , 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 Tue Oct 22 22:08:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13846233 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.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 096D71CCB59 for ; Tue, 22 Oct 2024 22:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729634944; cv=none; b=WMiiNCPUI7RrWQwZO94D1MaBYw43Bk1s2YEqEdQB7bljC/4VzMF6zCdW2irx0MGMH/5/zDwY1Qs4HWHSzBAEB3q9V/bzZI8napkOAh71cOma90COA+DcNvcdTQPyFpEeXE2/UQAPWT8KUicENwgvkwAjfGGt0xdy2m3633EEFy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729634944; c=relaxed/simple; bh=5GzF9PCgCy1dVVZT3Al79NQtBgiC3194rw0GgjPbASo=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=KdtkaIB7MI4qSyH0/a0mX1GTfWtz7pox5OeQ9HW9aQE21KOX/tQKLX/AoCSln7xdtPQLKXq12QR1PfUfUYB8JqApmAEzno5ENK8+IPEEEu1j+chjn6muOJraGQaN8FOXkFjax7SfFCV+hiG3TzWeT1nZ55Q8cXyNC65HbtKr7X4= 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=ge6S/sUK; arc=none smtp.client-ip=209.85.218.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="ge6S/sUK" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a9a0cee600aso768190166b.1 for ; Tue, 22 Oct 2024 15:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729634941; x=1730239741; 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=ge6S/sUKx5f61q9USBs/D5wpPzlSXV5kc5GQtsQhqt/3Zt5x0kuAq7xPiQstjdf+0O 4UBQBazXpAFMwmiFG33+2m1Tpf9HnprhuReSJZ+Ay8iRPrHXmBP1HtJOZ+aIDfS7IOgA H66yNz72hyu/GTCo9ucH/5uAHlUvkcO/uL5Hlxk+LtPpMh1xpnEnSZ+EGnjawXgiGmM9 8I0NfD5TOcnxrt5PgQWBbsJDnCEOhykpAetHCNeRuN1s2Ll3qgdxG+PUXGAHxIGiX+VS VWE26M+bjEcQm3tlG4YkGP3KtJ5AbO7Fl5PiCyaabb44bo9I/1fRawjO7hMb1whikMGp 1tRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729634941; x=1730239741; 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=H4sCzzEuVIKs60qqbLJwuQDRGC+o3RG+CTY6B4RWVSJIG1CsWxUigPiNvRLO8+8wAq QruqlT4U9HNZzxgvRTmGUmIMh5/WOVbts9rdX8JkbxDKRPFNFwjPyjvpLnNw+SQlD0u0 abvY+pgVfglEz0v5oXgGDMFLhdyo1f+9z7R/zH4HP2rFjxu99ldWhu4vd11PKRmZGfWY 7/vVUj+wE26QGjaZzp86QGZDLsOPAw/XYyMVptbjI6RfC38AKntHe+1XtqVlq311VbcL oxbUYkbUGho8HurZG4oga59mXq5m+mUlEw/2vHkxPGXhVaxmFwTzkCZJaxJRuhJhIAaY H8dA== X-Gm-Message-State: AOJu0Yxl/0JGRmLMmHkYJkP1RxOJi60uFeCMG4AkDrzKNUD2PntuoT9Y 0mvWn+Wm2Z82hD22l06Rstyn9uLVcljm3maaDNa3lxnmBEEeuZgeJE1v9A== X-Google-Smtp-Source: AGHT+IEC6ROVdOlIidGWh1bTMuALOttR3lcN9NStHwPcdvgyjA62xvIBruc7L9BR/73LU+MBPj2YOw== X-Received: by 2002:a17:907:2daa:b0:a9a:c03:ebc8 with SMTP id a640c23a62f3a-a9abf8c9f88mr35811666b.37.1729634940662; Tue, 22 Oct 2024 15:09:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91370e49sm390597066b.117.2024.10.22.15.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 15:09:00 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 22 Oct 2024 22:08:56 +0000 Subject: [PATCH v4 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 , 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 Tue Oct 22 22:08:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13846234 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 B7EE51CCEFA for ; Tue, 22 Oct 2024 22:09:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729634945; cv=none; b=t8q/0ra3UE+Fa2v0KBzkxyr50nLZkXUQHRYRONeZykFosmMiyc08C+FMbyVeD70dsL8J3E0JYj/2cuPhq05sbYWLRlJHLtoeOAlCV7rlRVdCFz15+dsEQ8crzbjPg+j9TeJ7mYYvqDvBfX1oM3S73iNuxNZJ/kFuspWNe+nT+p4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729634945; c=relaxed/simple; bh=37eIvsVESLXLyoI6O5Hzp3/HE8UXk+PVlwfWePSa1M0=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=NJNby0QdkUIfLmp11lMqlWjVtynrA1zFBWMxdrwl9ndCxNRzAmw694+rNjkeAPBTd6Q7kOiM62UyrmCM4wrfmyVfIa0DpBM2SeNtEsCDP21H4rYj+tqcUKD01AC/Mu1ePjCBz9XCM3OxO5Bfo6Gy0lk8L+cZ+c5UHEJNpreXl4g= 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=RszENaeC; arc=none smtp.client-ip=209.85.167.47 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="RszENaeC" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-53a007743e7so7495087e87.1 for ; Tue, 22 Oct 2024 15:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729634942; x=1730239742; 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=ljjAwwc49VPeSHdsjTz8xOsjWNLz4b6qMHM1WZ0Hi1s=; b=RszENaeCYROEuScTfrNgoVKm/ivcAtFMRfrqPGeTznDvtEiYwsfLxkjny2Ml2jglUx HZ/OHLwk7owANkdtGpQW4PcflrxtjY7lmeDZMua9y40yiqW+nB4kJTrKSftBO/p55rMI 7LxlOTknhd27nKA6KBewPo4+Tq6rUlQCYmPDZ7MNHzAMkE2iiTjqKu9LWS5L1/TeL53J UAGE5qIvYloxpOSlI0J6sxshyRdm2056BJ1O9UhzSDvqAko6E8gR5kc8h5ffs1o5FmKn YAwOIzxDq1AiXwPyUj9ADDi27+8F1WkFum8od7DlxBV+WL37hbTUvzwD86R+vYEoMORc czhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729634942; x=1730239742; 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=ljjAwwc49VPeSHdsjTz8xOsjWNLz4b6qMHM1WZ0Hi1s=; b=OmmWqtFVw8cvTUo2WYQTxHu2W/PigQ+pxkzqmWG8HPNF2uDFUkUNDRn1k0glMTOX0+ 8Uv18Z0SfBhO9eJA38CgaLVOI+NvZ1DDjYXWeepCnWyDxTU1xWEKIDKRQ0NDrCv8dZ99 fpbUBcNb21H2JisMqMLBnU8qsM2pmzKDZDWXph3YInJJlE48r88koCzkoWT9CAkx7mzf L12FquOoMH2tZkncqsi/vHaetEHS9Rp9QUPsRfgmfOV9c6xCiuRmF7BEwOr3y4A1+jz3 z+fNJ3bYekYmzYgiksIYYrQJHnIQSxkT8fzvo5XmP5BCp7sHkKa887PqGJC54XfJgHDC ICCg== X-Gm-Message-State: AOJu0Ywi8/cY4pDLXRDQxhAW5qherLQ+2KUJfi44R6MJMFQl4IeoaBHJ ZILW8SkBSG66KfXy56q4x175zg8Puc99wF8Dr91ErkRy9uhVpc2Z5hBerQ== X-Google-Smtp-Source: AGHT+IETmBdEiZ0T7VJGTnTQ9T9ZkU2W9OuB8PuaXM7v44A/buiVO8/ITJwycjtpn77zf0e8T+Mgsg== X-Received: by 2002:a05:6512:2306:b0:539:f7de:df84 with SMTP id 2adb3069b0e04-53b1a30d360mr172500e87.10.1729634941393; Tue, 22 Oct 2024 15:09:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c72581sm3604290a12.86.2024.10.22.15.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 15:09:01 -0700 (PDT) Message-Id: <8982dca646db72f903bd4c20416d6118da1c210c.1729634938.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 22 Oct 2024 22:08:57 +0000 Subject: [PATCH v4 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 , 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..8214df128e5 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;