From owner-p4-projects@FreeBSD.ORG Mon Mar 11 20:57:14 2013 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 42B06AA0; Mon, 11 Mar 2013 20:57:14 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 00AD4A9E for ; Mon, 11 Mar 2013 20:57:13 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:1900:2254:2068::682:0]) by mx1.freebsd.org (Postfix) with ESMTP id D7AA0CA for ; Mon, 11 Mar 2013 20:57:13 +0000 (UTC) Received: from skunkworks.freebsd.org ([127.0.1.74]) by skunkworks.freebsd.org (8.14.6/8.14.6) with ESMTP id r2BKvD3P058906 for ; Mon, 11 Mar 2013 20:57:13 GMT (envelope-from brooks@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.6/8.14.6/Submit) id r2BKvDgQ058903 for perforce@freebsd.org; Mon, 11 Mar 2013 20:57:13 GMT (envelope-from brooks@freebsd.org) Date: Mon, 11 Mar 2013 20:57:13 GMT Message-Id: <201303112057.r2BKvDgQ058903@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to brooks@freebsd.org using -f From: Brooks Davis Subject: PERFORCE change 222793 for review To: Perforce Change Reviews Precedence: bulk X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.14 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Mar 2013 20:57:14 -0000 http://p4web.freebsd.org/@@222793?ac=10 Change 222793 by brooks@brooks_zenith on 2013/03/11 20:56:48 Pull in changes require to build extract_and_verify on ubuntu. Fix copyright year. Affected files ... .. //depot/projects/ctsrd/beribsd/src/ctsrd/writefile/Makefile#3 edit .. //depot/projects/ctsrd/beribsd/src/ctsrd/writefile/eav.c#2 edit .. //depot/projects/ctsrd/beribsd/src/ctsrd/writefile/eav.h#2 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/ctsrd/writefile/Makefile#3 (text+ko) ==== @@ -11,6 +11,7 @@ WARNS= 6 +CFLAGS+=-DMD5_SUPPORT LDADD+= -lbz2 -lmd -lutil .include ==== //depot/projects/ctsrd/beribsd/src/ctsrd/writefile/eav.c#2 (text+ko) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012 SRI International + * Copyright (c) 2013 SRI International * All rights reserved. * * This software was developed by SRI International and the University of @@ -31,12 +31,30 @@ #include #include +#ifdef MD5_SUPPORT #include +#endif #include #include #include "eav.h" +#ifdef __linux__ +#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ + +static void * +reallocf(void *ptr, size_t size) +{ + void *tmp; + + tmp = ptr; + ptr = realloc(ptr, size); + if (ptr == NULL) + free(tmp); + return (ptr); +} +#endif + enum eav_compression eav_taste(const unsigned char *buf, off_t len) { @@ -85,6 +103,8 @@ return "checksum mismatch"; case EAV_ERR_DIGEST_UNKNOWN: return "unknown digest"; + case EAV_ERR_DIGEST_UNSUPPORTED: + return "unsupported digest"; case EAV_ERR_COMP: return "decompression error"; case EAV_ERR_COMP_UNKNOWN: @@ -103,11 +123,14 @@ enum eav_digest dtype, const unsigned char *digest) { int ret; - char *obuf = NULL; - size_t olen = 0, prev_total_in, total_in, total_out; + unsigned char *obuf = NULL; + size_t olen = 0, total_in, total_out; bz_stream bzs; +#ifdef MD5_SUPPORT + size_t prev_total_in; MD5_CTX md5ctx; char i_md5sum[33]; +#endif switch (ctype) { case EAV_COMP_NONE: @@ -122,15 +145,23 @@ switch (dtype) { case EAV_DIGEST_NONE: + break; case EAV_DIGEST_MD5: +#ifdef MD5_SUPPORT break; +#else + return (EAV_ERR_DIGEST_UNSUPPORTED); +#endif + default: return (EAV_ERR_DIGEST_UNKNOWN); } if (dtype || ctype) { +#ifdef MD5_SUPPORT if (dtype == EAV_DIGEST_MD5) MD5Init(&md5ctx); +#endif if (ctype) { /* XXX: assume bzip2 for now */ @@ -139,14 +170,16 @@ return (EAV_ERR_MEM); total_in = 0; +#ifdef MD5_SUPPORT prev_total_in = 0; +#endif bzs.bzalloc = NULL; bzs.bzfree = NULL; bzs.opaque = NULL; - bzs.next_in = ibuf; + bzs.next_in = (char *)ibuf; bzs.avail_in = MIN(ilen, 1024 * 1024); - bzs.next_out = obuf; + bzs.next_out = (char *)obuf; bzs.avail_out = olen; if (BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK) return (EAV_ERR_COMP); @@ -164,10 +197,12 @@ total_out = ((size_t)bzs.total_out_hi32 << 32) + bzs.total_out_lo32; +#ifdef MD5_SUPPORT if (dtype == EAV_DIGEST_MD5) MD5Update(&md5ctx, ibuf + prev_total_in, total_in - prev_total_in); prev_total_in = total_in; +#endif if (bzs.avail_in == 0) bzs.avail_in = @@ -180,7 +215,7 @@ BZ2_bzDecompressEnd(&bzs); return (EAV_ERR_COMP); } - bzs.next_out = obuf + total_out; + bzs.next_out = (char *)obuf + total_out; bzs.avail_out = olen - total_out; } } @@ -190,10 +225,12 @@ total_out = ((size_t)bzs.total_out_hi32 << 32) + bzs.total_out_lo32; +#ifdef MD5_SUPPORT /* Push the last read block in the MD5 machine */ if (dtype == EAV_DIGEST_MD5) MD5Update(&md5ctx, ibuf + prev_total_in, total_in - prev_total_in); +#endif /* Round up to blocksize and zero pad */ olen = roundup2(total_out, blocksize); @@ -202,16 +239,20 @@ olen - total_out); /* XXX: realloc to shorten allocation? */ } else if (dtype) { +#ifdef MD5_SUPPORT if (dtype == EAV_DIGEST_MD5) MD5Update(&md5ctx, ibuf, ilen); +#endif } if (dtype) { +#ifdef MD5_SUPPORT if (dtype == EAV_DIGEST_MD5) { MD5End(&md5ctx, i_md5sum); if (strcmp(digest, i_md5sum) != 0) return (EAV_ERR_DIGEST); } +#endif } } ==== //depot/projects/ctsrd/beribsd/src/ctsrd/writefile/eav.h#2 (text+ko) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012 SRI International + * Copyright (c) 2013 SRI International * All rights reserved. * * This software was developed by SRI International and the University of @@ -36,6 +36,7 @@ EAV_ERR_MEM, EAV_ERR_DIGEST, EAV_ERR_DIGEST_UNKNOWN, + EAV_ERR_DIGEST_UNSUPPORTED, EAV_ERR_COMP, EAV_ERR_COMP_UNKNOWN, EAV_ERR_COMP_UNSUPPORTED