NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/44539: opencrypto DEFLATE compression output is not correctly terminated



The following reply was made to PR kern/44539; it has been noted by GNATS.

From: Matthias Drochner <M.Drochner%fz-juelich.de@localhost>
To: gnats-bugs%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Cc: 
Subject: Re: kern/44539: opencrypto DEFLATE compression output is not 
 correctly terminated
Date: Wed, 9 Feb 2011 20:02:12 +0100

 --==_Exmh_83353830120
 Content-Type: text/plain; charset="us-ascii"
 Content-Transfer-Encoding: quoted-printable
 
 
 Here is the test program. It compresses some data using opencrypto
 and decompresses it with userland zlib.
 It fails with current sources and succeeds after the patch in the PR
 is applied.
 (needs eg. "sysctl -w kern.cryptodevallowsoft=3D0" for permission)
 
 
 ---------------------------------------------------------------------------=
 ---------------------
 ---------------------------------------------------------------------------=
 ---------------------
 Forschungszentrum Juelich GmbH
 52425 Juelich
 Sitz der Gesellschaft: Juelich
 Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
 Vorsitzender des Aufsichtsrats: MinDirig Dr. Karl Eugen Huthmacher
 Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
 Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
 Prof. Dr. Sebastian M. Schmidt
 ---------------------------------------------------------------------------=
 ---------------------
 ---------------------------------------------------------------------------=
 ---------------------
 
 --==_Exmh_83353830120
 Content-Type: text/plain; name="comptest_zlib.c"; charset="us-ascii"
 Content-Description: comptest_zlib.c
 Content-Disposition: attachment; filename="comptest_zlib.c"
 
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
 #include <crypto/cryptodev.h>
 #include <string.h>
 #include <err.h>
 #include <zlib.h>
 
 char text[10000] = {0};
 
 int
 main()
 {
        int fd, res;
        struct session_op cs;
        struct crypt_op co1;
        unsigned char buf1[10000], buf2[10000];
        z_stream z;
 
        fd = open("/dev/crypto", O_RDWR, 0);
        if (fd < 0)
                err(1, "open");
        memset(&cs, 0, sizeof(cs));
        cs.comp_alg = CRYPTO_DEFLATE_COMP;
        res = ioctl(fd, CIOCGSESSION, &cs);
        if (res < 0)
                err(1, "CIOCGSESSION");
 
        memset(&co1, 0, sizeof(co1));
        co1.ses = cs.ses;
        co1.op = COP_COMP;
        co1.len = sizeof(text);
        co1.src = text;
        co1.dst = buf1;
        co1.dst_len = sizeof(buf1);
        res = ioctl(fd, CIOCCRYPT, &co1);
        if (res < 0)
                err(1, "CIOCCRYPT");
 
        memset(&z, 0, sizeof(z));
        z.next_in = buf1;
        z.avail_in = co1.dst_len;
        z.zalloc = Z_NULL;
        z.zfree = Z_NULL;
        z.opaque = 0;
        z.next_out = buf2;
        z.avail_out = sizeof(buf2);
        res = inflateInit2(&z, -15);
        if (res != Z_OK)
                errx(1, "inflateInit: %d", res);
        do {
                res = inflate(&z, Z_SYNC_FLUSH);
        } while (res == Z_OK);
        if (res != Z_STREAM_END)
                errx(1, "inflate: %d", res);
        if (z.total_out != sizeof(text))
                errx(1, "decomp len %lu", z.total_out);
        if (memcmp(buf2, text, sizeof(text)))
                errx(1, "decomp data mismatch");
        return 0;
 }
 
 --==_Exmh_83353830120--
 


Home | Main Index | Thread Index | Old Index