git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Filipe Cabecinhas <filcab@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX
Date: Tue, 09 Apr 2013 15:50:42 -0700	[thread overview]
Message-ID: <7v4nffpbct.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <CAEDE852zw9EhmnVaWb_oa_BX_d_--TZoTcs1kgkMPHooM_E6Cw@mail.gmail.com> (Filipe Cabecinhas's message of "Tue, 9 Apr 2013 15:31:31 -0700")

Filipe Cabecinhas <filcab@gmail.com> writes:

>
> Testing with dd bs=INT_MAX+1 count=1 also gets me an “Invalid
> argument” error, while bs=INT_MAX will do what's expected.
>
> I have a preliminary patch that fixes it, but it may not be the
> preferred way. The code is not ifdef'ed out and I'm doing the fix in
> write_in_full(), while it may be preferred to do the fix in xwrite().
>
> A radar bug has been submitted to Apple about this, but I think git
> could tolerate the bug while it isn't fixed, by working around it.
>
> Thank you,
>
>   Filipe
>
> diff --git a/wrapper.c b/wrapper.c
> index bac59d2..474d760 100644
> --- a/wrapper.c
> +++ b/wrapper.c
> @@ -187,7 +187,12 @@ ssize_t write_in_full(int fd, const void *buf, size_t count)
>  	ssize_t total = 0;
>  
>  	while (count > 0) {
> -		ssize_t written = xwrite(fd, p, count);
> +		ssize_t written = 0;
> +        if (count >= INT_MAX)
> +			written = xwrite(fd, p, INT_MAX-1);
> +        else
> +			written = xwrite(fd, p, count);

I think it is better to fix it in much lower level of the stack, as
other codepaths would call write(2), either thru xwrite() or
directly.

Ideally the fix should go to the lowest level, i.e. the write(2).  I
do not care if it is done in the kernel or in the libc wrapping
code; the above does not belong to our code (in an ideal world, that
is).

Otherwise you would have to patch everything in /usr/bin, no?

But you do not live in an ideal world and neither do we.  I think
the least ugly way may be to add compat/clipped-write.c that
implements a loop like the above in a helper function:

	ssize_t clipped_write(int, const void *, size_t);

and have a

	#ifdef NEED_CLIPPED_WRITE
	#define write(x,y,z) clipped_write((x),(y),(z))
        #endif

in git-compat-util.h, or something.  Makefile needs to get adjusted
to link with compat/clipped-write.o when NEED_CLIPPED_WRITE is
defined as well.

  reply	other threads:[~2013-04-09 22:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 22:31 write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX Filipe Cabecinhas
2013-04-09 22:50 ` Junio C Hamano [this message]
2013-05-09 22:58   ` Filipe Cabecinhas
2013-05-10  2:28     ` Junio C Hamano
2013-05-10 22:24       ` Filipe Cabecinhas
2013-05-10 23:05         ` Junio C Hamano
2013-05-10 23:10           ` Junio C Hamano
2013-05-10 23:13           ` Filipe Cabecinhas
2013-05-10 23:19             ` Filipe Cabecinhas
2013-05-10 23:36               ` Junio C Hamano
2013-11-20 10:15           ` Erik Faye-Lund
2013-11-20 13:03             ` Torsten Bögershausen

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=7v4nffpbct.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=filcab@gmail.com \
    --cc=git@vger.kernel.org \
    /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).