git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Mohit Marathe via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Mohit Marathe <mohitmarathe@proton.me>
Subject: [PATCH v6 0/2] Replace atoi() with strtoi_with_tail()
Date: Sun, 04 Feb 2024 05:48:36 +0000	[thread overview]
Message-ID: <pull.1646.v6.git.1707025718.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1646.v5.git.1706416952.gitgitgadget@gmail.com>

Hello,

This patch series replaces atoi() with an updated version of strtol_i()
called strtoi_with_tail (Credits: Junio C Hamano). The reasoning behind this
is to improve error handling by not allowing non-numerical characters in the
hunk header (which might happen in case of a corrupt patch, although
rarely).

There is still a change to be made, as Junio says: "A corrupt patch may be
getting a nonsense patch-ID with the current code and hopefully is not
matching other patches that are not corrupt, but with such a change, a
corrupt patch may not be getting any patch-ID and a loop that computes
patch-ID for many files and try to match them up might need to be rewritten
to take the new failure case into account." I'm not sure where this change
needs to me made (maybe get_one_patchid()?). It would be great if anyone
could point me to the correct place.

Thanks, Mohit Marathe

Mohit Marathe (2):
  git-compat-util: add strtoi_with_tail()
  patch-id: replace `atoi()` with `strtoi_with_tail`

 builtin/patch-id.c | 12 ++++++++----
 git-compat-util.h  | 18 ++++++++++++++----
 2 files changed, 22 insertions(+), 8 deletions(-)


base-commit: 2a540e432fe5dff3cfa9d3bf7ca56db2ad12ebb9
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1646%2Fmohit-marathe%2Fupdate-strtol_i-v6
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1646/mohit-marathe/update-strtol_i-v6
Pull-Request: https://github.com/gitgitgadget/git/pull/1646

Range-diff vs v5:

 1:  f09b0838f04 ! 1:  98e516a7be7 git-compat-util: add strtoi_with_tail()
     @@ Commit message
          Signed-off-by: Mohit Marathe <mohitmarathe@proton.me>
      
       ## git-compat-util.h ##
     -@@ git-compat-util.h: static inline int strtol_i(char const *s, int base, int *result)
     +@@ git-compat-util.h: static inline int strtoul_ui(char const *s, int base, unsigned int *result)
       	return 0;
       }
       
     +-static inline int strtol_i(char const *s, int base, int *result)
      +#define strtol_i(s,b,r) strtoi_with_tail((s), (b), (r), NULL)
      +static inline int strtoi_with_tail(char const *s, int base, int *result, char **endp)
     -+{
     -+	long ul;
     + {
     + 	long ul;
     +-	char *p;
      +	char *dummy = NULL;
     -+
     + 
      +	if (!endp)
      +		endp = &dummy;
     -+	errno = 0;
     + 	errno = 0;
     +-	ul = strtol(s, &p, base);
     +-	if (errno || *p || p == s || (int) ul != ul)
      +	ul = strtol(s, endp, base);
      +	if (errno ||
      +	    /*
     @@ git-compat-util.h: static inline int strtol_i(char const *s, int base, int *resu
      +	     */
      +	   (dummy && *dummy) ||
      +	    *endp == s || (int) ul != ul)
     -+		return -1;
     -+	*result = ul;
     -+	return 0;
     -+}
     -+
     - void git_stable_qsort(void *base, size_t nmemb, size_t size,
     - 		      int(*compar)(const void *, const void *));
     - #ifdef INTERNAL_QSORT
     + 		return -1;
     + 	*result = ul;
     + 	return 0;
 2:  ee8f4ae991d = 2:  858d6f94e79 patch-id: replace `atoi()` with `strtoi_with_tail`

-- 
gitgitgadget


  parent reply	other threads:[~2024-02-04  5:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22  8:51 [PATCH 0/2] Replace atoi() with strtol_i2() Mohit Marathe via GitGitGadget
2024-01-22  8:51 ` [PATCH 1/2] git-compat-util: add strtol_i2 Mohit Marathe via GitGitGadget
2024-01-22  8:51 ` [PATCH 2/2] patch-id: replace `atoi()` with `strtol_i2()` Mohit Marathe via GitGitGadget
2024-01-22 19:32   ` Junio C Hamano
2024-01-24  4:22     ` Mohit Marathe
2024-01-24  6:32 ` [PATCH v2 0/2] Replace atoi() with strtol_i_updated() Mohit Marathe via GitGitGadget
2024-01-24  6:32   ` [PATCH v2 1/2] git-compat-util: add strtol_i_updated() Mohit Marathe via GitGitGadget
2024-01-24  6:32   ` [PATCH v2 2/2] patch-id: replace `atoi()` with `strtol_i_updated()` Mohit Marathe via GitGitGadget
2024-01-24  6:48   ` [PATCH v3 0/2] Replace atoi() with strtol_i_updated() Mohit Marathe via GitGitGadget
2024-01-24  6:48     ` [PATCH v3 1/2] git-compat-util: add strtol_i_updated() Mohit Marathe via GitGitGadget
2024-01-24  6:48     ` [PATCH v3 2/2] patch-id: replace `atoi()` with `strtol_i_updated()` Mohit Marathe via GitGitGadget
2024-01-24  6:55     ` [PATCH v4 0/2] Replace atoi() with strtol_i_updated() Mohit Marathe via GitGitGadget
2024-01-24  6:55       ` [PATCH v4 1/2] git-compat-util: add strtol_i_updated() Mohit Marathe via GitGitGadget
2024-01-24 20:20         ` Junio C Hamano
2024-01-24  6:55       ` [PATCH v4 2/2] patch-id: replace `atoi()` with `strtol_i_updated()` Mohit Marathe via GitGitGadget
2024-01-24 21:02         ` Junio C Hamano
2024-01-28  4:35           ` Mohit Marathe
2024-01-28  4:42       ` [PATCH v5 0/2] Replace atoi() with strtoi_with_tail() Mohit Marathe via GitGitGadget
2024-01-28  4:42         ` [PATCH v5 1/2] git-compat-util: add strtoi_with_tail() Mohit Marathe via GitGitGadget
2024-01-30  4:40           ` Junio C Hamano
2024-01-28  4:42         ` [PATCH v5 2/2] patch-id: replace `atoi()` with `strtoi_with_tail` Mohit Marathe via GitGitGadget
2024-02-04  5:48         ` Mohit Marathe via GitGitGadget [this message]
2024-02-04  5:48           ` [PATCH v6 1/2] git-compat-util: add strtoi_with_tail() Mohit Marathe via GitGitGadget
2024-02-04  5:48           ` [PATCH v6 2/2] patch-id: replace `atoi()` with `strtoi_with_tail` Mohit Marathe via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1646.v6.git.1707025718.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=mohitmarathe@proton.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).