comparison common-kex.c @ 1365:9aa6cd66b51d fuzz

zlib can use m_malloc/m_free too
author Matt Johnston <matt@ucc.asn.au>
date Mon, 22 May 2017 22:09:26 +0800
parents 6b89eb92f872
children 798854f62430
comparison
equal deleted inserted replaced
1364:17104db7928c 1365:9aa6cd66b51d
389 return ses.keys->recv.algo_comp == DROPBEAR_COMP_ZLIB 389 return ses.keys->recv.algo_comp == DROPBEAR_COMP_ZLIB
390 || (ses.authstate.authdone 390 || (ses.authstate.authdone
391 && ses.keys->recv.algo_comp == DROPBEAR_COMP_ZLIB_DELAY); 391 && ses.keys->recv.algo_comp == DROPBEAR_COMP_ZLIB_DELAY);
392 } 392 }
393 393
394 static void* dropbear_zalloc(void* UNUSED(opaque), uInt items, uInt size) {
395 return m_calloc(items, size);
396 }
397
398 static void dropbear_zfree(void* UNUSED(opaque), void* ptr) {
399 m_free(ptr);
400 }
401
394 /* Set up new zlib compression streams, close the old ones. Only 402 /* Set up new zlib compression streams, close the old ones. Only
395 * called from gen_new_keys() */ 403 * called from gen_new_keys() */
396 static void gen_new_zstream_recv() { 404 static void gen_new_zstream_recv() {
397 405
398 /* create new zstreams */ 406 /* create new zstreams */
399 if (ses.newkeys->recv.algo_comp == DROPBEAR_COMP_ZLIB 407 if (ses.newkeys->recv.algo_comp == DROPBEAR_COMP_ZLIB
400 || ses.newkeys->recv.algo_comp == DROPBEAR_COMP_ZLIB_DELAY) { 408 || ses.newkeys->recv.algo_comp == DROPBEAR_COMP_ZLIB_DELAY) {
401 ses.newkeys->recv.zstream = (z_streamp)m_malloc(sizeof(z_stream)); 409 ses.newkeys->recv.zstream = (z_streamp)m_malloc(sizeof(z_stream));
402 ses.newkeys->recv.zstream->zalloc = Z_NULL; 410 ses.newkeys->recv.zstream->zalloc = dropbear_zalloc;
403 ses.newkeys->recv.zstream->zfree = Z_NULL; 411 ses.newkeys->recv.zstream->zfree = dropbear_zfree;
404 412
405 if (inflateInit(ses.newkeys->recv.zstream) != Z_OK) { 413 if (inflateInit(ses.newkeys->recv.zstream) != Z_OK) {
406 m_free(ses.newkeys->recv.zstream);
407 dropbear_exit("zlib error"); 414 dropbear_exit("zlib error");
408 } 415 }
409 } else { 416 } else {
410 ses.newkeys->recv.zstream = NULL; 417 ses.newkeys->recv.zstream = NULL;
411 } 418 }
422 static void gen_new_zstream_trans() { 429 static void gen_new_zstream_trans() {
423 430
424 if (ses.newkeys->trans.algo_comp == DROPBEAR_COMP_ZLIB 431 if (ses.newkeys->trans.algo_comp == DROPBEAR_COMP_ZLIB
425 || ses.newkeys->trans.algo_comp == DROPBEAR_COMP_ZLIB_DELAY) { 432 || ses.newkeys->trans.algo_comp == DROPBEAR_COMP_ZLIB_DELAY) {
426 ses.newkeys->trans.zstream = (z_streamp)m_malloc(sizeof(z_stream)); 433 ses.newkeys->trans.zstream = (z_streamp)m_malloc(sizeof(z_stream));
427 ses.newkeys->trans.zstream->zalloc = Z_NULL; 434 ses.newkeys->trans.zstream->zalloc = dropbear_zalloc;
428 ses.newkeys->trans.zstream->zfree = Z_NULL; 435 ses.newkeys->trans.zstream->zfree = dropbear_zfree;
429 436
430 if (deflateInit2(ses.newkeys->trans.zstream, Z_DEFAULT_COMPRESSION, 437 if (deflateInit2(ses.newkeys->trans.zstream, Z_DEFAULT_COMPRESSION,
431 Z_DEFLATED, DROPBEAR_ZLIB_WINDOW_BITS, 438 Z_DEFLATED, DROPBEAR_ZLIB_WINDOW_BITS,
432 DROPBEAR_ZLIB_MEM_LEVEL, Z_DEFAULT_STRATEGY) 439 DROPBEAR_ZLIB_MEM_LEVEL, Z_DEFAULT_STRATEGY)
433 != Z_OK) { 440 != Z_OK) {