]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - sshzlib.c
Log when -restrict-acl is in use.
[PuTTY.git] / sshzlib.c
index 05fa57722a56810c607260d9e94ebf28ffc4b4b3..ee1bc42d3054b8707ea41ffa04da5719048ec205 100644 (file)
--- a/sshzlib.c
+++ b/sshzlib.c
@@ -205,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];
@@ -334,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++;
@@ -1226,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;
@@ -1356,6 +1366,7 @@ int main(int argc, char **argv)
             sfree(outbuf);
         } else {
             fprintf(stderr, "decoding error\n");
+            fclose(fp);
             return 1;
         }
     }