Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-11-10 01:06:29 +0300
committerJunio C Hamano <gitster@pobox.com>2020-11-10 01:06:29 +0300
commitcaf3ca7786a1f16215f1caedbbf075ba7ff61c96 (patch)
tree90fbf6512a5944f65036ed5d1af3518d81bca440 /sideband.c
parent6a44c9c0d05839d6402c84a80acd0c2525f3a85e (diff)
parentaf22a63c3995e4113963aa756c580bb111d99176 (diff)
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 anomalies
Diffstat (limited to 'sideband.c')
-rw-r--r--sideband.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/sideband.c b/sideband.c
index a5405b9aaa..6f9e026732 100644
--- a/sideband.c
+++ b/sideband.c
@@ -3,6 +3,7 @@
#include "config.h"
#include "sideband.h"
#include "help.h"
+#include "pkt-line.h"
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 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,
struct strbuf *scratch,
enum sideband_type *sideband_type)
@@ -130,17 +132,30 @@ int demultiplex_sideband(const char *me, char *buf, int len,
suffix = DUMB_SUFFIX;
}
- if (len == 0) {
- *sideband_type = SIDEBAND_FLUSH;
- goto cleanup;
- }
- if (len < 1) {
+ if (status == PACKET_READ_EOF) {
strbuf_addf(scratch,
- "%s%s: protocol error: no band designator",
+ "%s%s: unexpected disconnect while reading sideband packet",
scratch->len ? "\n" : "", me);
*sideband_type = SIDEBAND_PROTOCOL_ERROR;
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;
buf[len] = '\0';
len--;