Merge branch 'jk/sideband-more-error-checking'
The code to detect premature EOF in the sideband demultiplexer has been cleaned up. * jk/sideband-more-error-checking: sideband: diagnose more sideband anomaliesmaint
commit
caf3ca7786
14
pkt-line.c
14
pkt-line.c
|
@ -461,9 +461,11 @@ int recv_sideband(const char *me, int in_stream, int out)
|
||||||
enum sideband_type sideband_type;
|
enum sideband_type sideband_type;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
len = packet_read(in_stream, NULL, NULL, buf, LARGE_PACKET_MAX,
|
int status = packet_read_with_status(in_stream, NULL, NULL,
|
||||||
0);
|
buf, LARGE_PACKET_MAX,
|
||||||
if (!demultiplex_sideband(me, buf, len, 0, &scratch,
|
&len,
|
||||||
|
PACKET_READ_GENTLE_ON_EOF);
|
||||||
|
if (!demultiplex_sideband(me, status, buf, len, 0, &scratch,
|
||||||
&sideband_type))
|
&sideband_type))
|
||||||
continue;
|
continue;
|
||||||
switch (sideband_type) {
|
switch (sideband_type) {
|
||||||
|
@ -520,9 +522,9 @@ enum packet_read_status packet_reader_read(struct packet_reader *reader)
|
||||||
reader->options);
|
reader->options);
|
||||||
if (!reader->use_sideband)
|
if (!reader->use_sideband)
|
||||||
break;
|
break;
|
||||||
if (demultiplex_sideband(reader->me, reader->buffer,
|
if (demultiplex_sideband(reader->me, reader->status,
|
||||||
reader->pktlen, 1, &scratch,
|
reader->buffer, reader->pktlen, 1,
|
||||||
&sideband_type))
|
&scratch, &sideband_type))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
sideband.c
29
sideband.c
|
@ -3,6 +3,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "sideband.h"
|
#include "sideband.h"
|
||||||
#include "help.h"
|
#include "help.h"
|
||||||
|
#include "pkt-line.h"
|
||||||
|
|
||||||
struct keyword_entry {
|
struct keyword_entry {
|
||||||
/*
|
/*
|
||||||
|
@ -114,7 +115,8 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
|
||||||
#define ANSI_SUFFIX "\033[K"
|
#define ANSI_SUFFIX "\033[K"
|
||||||
#define DUMB_SUFFIX " "
|
#define DUMB_SUFFIX " "
|
||||||
|
|
||||||
int demultiplex_sideband(const char *me, char *buf, int len,
|
int demultiplex_sideband(const char *me, int status,
|
||||||
|
char *buf, int len,
|
||||||
int die_on_error,
|
int die_on_error,
|
||||||
struct strbuf *scratch,
|
struct strbuf *scratch,
|
||||||
enum sideband_type *sideband_type)
|
enum sideband_type *sideband_type)
|
||||||
|
@ -130,17 +132,30 @@ int demultiplex_sideband(const char *me, char *buf, int len,
|
||||||
suffix = DUMB_SUFFIX;
|
suffix = DUMB_SUFFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 0) {
|
if (status == PACKET_READ_EOF) {
|
||||||
*sideband_type = SIDEBAND_FLUSH;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (len < 1) {
|
|
||||||
strbuf_addf(scratch,
|
strbuf_addf(scratch,
|
||||||
"%s%s: protocol error: no band designator",
|
"%s%s: unexpected disconnect while reading sideband packet",
|
||||||
scratch->len ? "\n" : "", me);
|
scratch->len ? "\n" : "", me);
|
||||||
*sideband_type = SIDEBAND_PROTOCOL_ERROR;
|
*sideband_type = SIDEBAND_PROTOCOL_ERROR;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (len < 0)
|
||||||
|
BUG("negative length on non-eof packet read");
|
||||||
|
|
||||||
|
if (len == 0) {
|
||||||
|
if (status == PACKET_READ_NORMAL) {
|
||||||
|
strbuf_addf(scratch,
|
||||||
|
"%s%s: protocol error: missing sideband designator",
|
||||||
|
scratch->len ? "\n" : "", me);
|
||||||
|
*sideband_type = SIDEBAND_PROTOCOL_ERROR;
|
||||||
|
} else {
|
||||||
|
/* covers flush, delim, etc */
|
||||||
|
*sideband_type = SIDEBAND_FLUSH;
|
||||||
|
}
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
band = buf[0] & 0xff;
|
band = buf[0] & 0xff;
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
len--;
|
len--;
|
||||||
|
|
|
@ -18,8 +18,12 @@ enum sideband_type {
|
||||||
*
|
*
|
||||||
* scratch must be a struct strbuf allocated by the caller. It is used to store
|
* scratch must be a struct strbuf allocated by the caller. It is used to store
|
||||||
* progress messages split across multiple packets.
|
* progress messages split across multiple packets.
|
||||||
|
*
|
||||||
|
* The "status" parameter is a pkt-line response as returned by
|
||||||
|
* packet_read_with_status() (e.g., PACKET_READ_NORMAL).
|
||||||
*/
|
*/
|
||||||
int demultiplex_sideband(const char *me, char *buf, int len,
|
int demultiplex_sideband(const char *me, int status,
|
||||||
|
char *buf, int len,
|
||||||
int die_on_error,
|
int die_on_error,
|
||||||
struct strbuf *scratch,
|
struct strbuf *scratch,
|
||||||
enum sideband_type *sideband_type);
|
enum sideband_type *sideband_type);
|
||||||
|
|
|
@ -40,4 +40,16 @@ test_expect_success 'incomplete sideband messages are reassembled' '
|
||||||
grep "Hello, world" err
|
grep "Hello, world" err
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'eof on sideband message is reported' '
|
||||||
|
printf 1234 >input &&
|
||||||
|
test-tool pkt-line receive-sideband <input 2>err &&
|
||||||
|
test_i18ngrep "unexpected disconnect" err
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'missing sideband designator is reported' '
|
||||||
|
printf 0004 >input &&
|
||||||
|
test-tool pkt-line receive-sideband <input 2>err &&
|
||||||
|
test_i18ngrep "missing sideband" err
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue