git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/2] Use packet_reader instead of packet_read_line

From
Masaya Suzuki <masayasuzuki@google.com>
Date
Jan 8, 2019, 23:27 UTC
Message-ID
<CAJB1erXk8xTCw0McdD-J=kz3s4fnpmhEEUBdzgTbMgQ-ry0wLw@mail.gmail.com>
In-Reply-To
<20190107223324.GB54613@google.com>
On Mon, Jan 7, 2019 at 2:33 PM Josh Steadmon <steadmon@google.com> wrote:
Show 49 quoted lines
>
> On 2018.12.29 13:19, Masaya Suzuki wrote:
> > By using and sharing a packet_reader while handling a Git pack protocol
> > request, the same reader option is used throughout the code. This makes
> > it easy to set a reader option to the request parsing code.
> >
> > Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
> > ---
> >  builtin/archive.c      | 19 ++++++-------
> >  builtin/receive-pack.c | 60 +++++++++++++++++++++--------------------
> >  fetch-pack.c           | 61 +++++++++++++++++++++++-------------------
> >  remote-curl.c          | 22 ++++++++++-----
> >  send-pack.c            | 37 ++++++++++++-------------
> >  upload-pack.c          | 38 +++++++++++++-------------
> >  6 files changed, 129 insertions(+), 108 deletions(-)
> >
> > diff --git a/builtin/archive.c b/builtin/archive.c
> > index d2455237c..2fe1f05ca 100644
> > --- a/builtin/archive.c
> > +++ b/builtin/archive.c
> > @@ -27,10 +27,10 @@ static int run_remote_archiver(int argc, const char **argv,
> >                              const char *remote, const char *exec,
> >                              const char *name_hint)
> >  {
> > -     char *buf;
> >       int fd[2], i, rv;
> >       struct transport *transport;
> >       struct remote *_remote;
> > +     struct packet_reader reader;
> >
> >       _remote = remote_get(remote);
> >       if (!_remote->url[0])
> > @@ -53,18 +53,19 @@ static int run_remote_archiver(int argc, const char **argv,
> >               packet_write_fmt(fd[1], "argument %s\n", argv[i]);
> >       packet_flush(fd[1]);
> >
> > -     buf = packet_read_line(fd[0], NULL);
> > -     if (!buf)
> > +     packet_reader_init(&reader, fd[0], NULL, 0, PACKET_READ_CHOMP_NEWLINE);
> > +
> > +     if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
>
> packet_read_line() can also return NULL if the packet is zero-length, so
> you may want to add a "|| reader.pktlen <= 0" to the condition here (and
> in other places where we were checking that packet_read_line() != NULL)
> to make sure the behavior doesn't change. See discussion on my previous
> attempt[1] to refactor this in builtin/archive.c.
>
> [1]: https://public-inbox.org/git/20180912053519.31085-1-steadmon@google.com/

That is interesting. In Documentation/technical/protocol-common.txt, it says "Implementations SHOULD NOT send an empty pkt-line ("0004").". The existing code won't distinguish "0000" and "0004", while "0004" is actually not a valid pkt-line. I'll make this patch with no behavior change, but I think we can make that behavior change to stop accepting 0004 as 0000, and remove the pktlen checks.

Previous: Josh SteadmonNext: Masaya Suzuki
Message 5 of 13 in “Accept error packets in any context”
  1. 0/2 Accept error packets in any contextMasaya Suzuki, Dec 29, 2018
  2. 1/2 Use packet_reader instead of packet_read_lineMasaya Suzuki, Dec 29, 2018
  3. Jonathan TanJan 7, 2019
  4. Josh SteadmonJan 7, 2019
  5. Masaya SuzukiJan 8, 2019
  6. 2/2 pack-protocol.txt: accept error packets in any contextMasaya Suzuki, Dec 29, 2018
  7. Jonathan TanJan 7, 2019
  8. Josh SteadmonJan 7, 2019
  9. Junio C HamanoJan 3, 2019
  10. Masaya SuzukiJan 4, 2019
  11. Jonathan NiederJan 15, 2019
  12. Jonathan NiederJan 15, 2019
  13. Junio C HamanoJan 15, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.