git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] pkt-line: don't check string length in packet_length()
Date: Thu, 6 Jul 2023 07:07:43 +0200	[thread overview]
Message-ID: <a5acfab5-0133-b3d6-3efc-c3f107e78b58@web.de> (raw)
In-Reply-To: <xmqqsfa2uh83.fsf@gitster.g>

Am 06.07.23 um 00:27 schrieb Junio C Hamano:
> hex.h:hex2chr() says "don't run over the end of short strings", but
> as far as I can see it does not check any such thing; find a page of
> memory, whose next page is unmapped, and pointing *s at the last
> byte of that page and calling it will happily run over the end and
> would cause SIGBUS.  The function assumes that such a short string
> is always NUL terminated, which is not a great way to guarantee that
> we do not run over the end of strings.

Yes, hex2chr() works with C strings, i.e. those that end with a NUL
character.  An empty string is just a NUL byte, a string of length 1
is a non-NUL byte and a NUL.  The function reads one byte from the
former and otherwise two bytes -- no overrun.

If a C string loses its NUL, how could you detect its end?

René

  reply	other threads:[~2023-07-06  5:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-01  7:05 [PATCH] pkt-line: don't check string length in packet_length() René Scharfe
2023-07-05  5:56 ` Junio C Hamano
2023-07-05 16:15   ` René Scharfe
2023-07-05 20:33     ` Junio C Hamano
2023-07-05 21:11       ` René Scharfe
2023-07-05 22:27         ` Junio C Hamano
2023-07-06  5:07           ` René Scharfe [this message]
2023-07-07 21:47 ` [PATCH v2] pkt-line: add size parameter to packet_length() René Scharfe

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

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

  git send-email \
    --in-reply-to=a5acfab5-0133-b3d6-3efc-c3f107e78b58@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
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 NNTP newsgroup(s).