X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshzlib.c;h=c69edfb81f9a09648baa67c5cf909b3e83aaabcc;hb=481ebd232e07a644b4ef5d6f1d13edc58a194971;hp=cc2872405d38ef26fa933d5ccbc48b59eafa01c4;hpb=767778cf1b621367be5087d47b68af7e97194adb;p=PuTTY.git diff --git a/sshzlib.c b/sshzlib.c index cc287240..c69edfb8 100644 --- a/sshzlib.c +++ b/sshzlib.c @@ -38,6 +38,7 @@ */ #include +#include #include #ifdef ZLIB_STANDALONE @@ -204,9 +205,16 @@ static void lz77_compress(struct LZ77Context *ctx, struct Match defermatch, matches[MAXMATCH]; int deferchr; + assert(st->npending <= HASHCHARS); + /* * Add any pending characters from last time to the window. (We * might not be able to.) + * + * This leaves st->pending empty in the usual case (when len >= + * HASHCHARS); otherwise it leaves st->pending empty enough that + * adding all the remaining 'len' characters will not push it past + * HASHCHARS in size. */ for (i = 0; i < st->npending; i++) { unsigned char foo[HASHCHARS]; @@ -333,6 +341,7 @@ static void lz77_compress(struct LZ77Context *ctx, if (len >= HASHCHARS) { lz77_advance(st, *data, lz77_hash(data)); } else { + assert(st->npending < HASHCHARS); st->pending[st->npending++] = *data; } data++; @@ -1225,6 +1234,8 @@ int zlib_decompress_block(void *handle, unsigned char *block, int len, goto finished; if (code == -2) goto decode_error; + if (code >= 30) /* dist symbols 30 and 31 are invalid */ + goto decode_error; dctx->state = GOTDISTSYM; dctx->sym = code; break; @@ -1371,6 +1382,7 @@ int main(int argc, char **argv) const struct ssh_compress ssh_zlib = { "zlib", + "zlib@openssh.com", /* delayed version */ zlib_compress_init, zlib_compress_cleanup, zlib_compress_block,