--- stor.c.orig 2010-12-13 14:42:49.000000000 +1100 +++ stor.c 2020-01-29 08:56:26.000000000 +1100 @@ -136,7 +136,7 @@ stor_file( SNET *sn, char *pathdesc, cha ssize_t rr, size = 0; unsigned int md_len; extern EVP_MD *md; - EVP_MD_CTX mdctx; + EVP_MD_CTX *mdctx = NULL; unsigned char md_value[ EVP_MAX_MD_SIZE ]; char cksum_b64[ SZ_BASE64_E( EVP_MAX_MD_SIZE ) ]; @@ -146,7 +146,12 @@ stor_file( SNET *sn, char *pathdesc, cha fprintf( stderr, "line %d: No checksum listed\n", linenum ); exit( 2 ); } - EVP_DigestInit( &mdctx, md ); + mdctx = EVP_MD_CTX_new(); + if (!mdctx) { + perror(NULL); + exit( 2 ); + } + EVP_DigestInit( mdctx, md ); } /* Open and stat file */ @@ -197,12 +202,13 @@ stor_file( SNET *sn, char *pathdesc, cha if ( snet_write( sn, buf, rr, &tv ) != rr ) { fprintf( stderr, "stor_file %s failed: %s\n", pathdesc, strerror( errno )); + EVP_MD_CTX_free( mdctx ); return( -1 ); } size -= rr; if ( dodots ) { putc( '.', stdout ); fflush( stdout ); } if ( cksum ) { - EVP_DigestUpdate( &mdctx, buf, (unsigned int)rr ); + EVP_DigestUpdate( mdctx, buf, (unsigned int)rr ); } if ( showprogress ) { @@ -226,6 +232,7 @@ stor_file( SNET *sn, char *pathdesc, cha if ( snet_writef( sn, ".\r\n" ) < 0 ) { fprintf( stderr, "stor_file %s failed: %s\n", pathdesc, strerror( errno )); + EVP_MD_CTX_free( mdctx ); return( -1 ); } if ( verbose ) fputs( "\n>>> .\n", stdout ); @@ -237,7 +244,8 @@ stor_file( SNET *sn, char *pathdesc, cha /* cksum data sent */ if ( cksum ) { - EVP_DigestFinal( &mdctx, md_value, &md_len ); + EVP_DigestFinal( mdctx, md_value, &md_len ); + EVP_MD_CTX_free( mdctx ); base64_e( md_value, md_len, cksum_b64 ); if ( strcmp( trancksum, cksum_b64 ) != 0 ) { fprintf( stderr, @@ -262,7 +270,7 @@ stor_applefile( SNET *sn, char *pathdesc unsigned int md_len; unsigned int rsrc_len; extern EVP_MD *md; - EVP_MD_CTX mdctx; + EVP_MD_CTX *mdctx = NULL; unsigned char md_value[ EVP_MAX_MD_SIZE ]; char cksum_b64[ EVP_MAX_MD_SIZE ]; @@ -272,7 +280,12 @@ stor_applefile( SNET *sn, char *pathdesc fprintf( stderr, "line %d: No checksum listed\n", linenum ); exit( 2 ); } - EVP_DigestInit( &mdctx, md ); + mdctx = EVP_MD_CTX_new(); + if (!mdctx) { + perror(NULL); + exit( 2 ); + } + EVP_DigestInit( mdctx, md ); } /* Check size listed in transcript */ @@ -303,6 +316,7 @@ stor_applefile( SNET *sn, char *pathdesc if ( snprintf( rsrc_path, MAXPATHLEN, "%s%s", path, _PATH_RSRCFORKSPEC ) >= MAXPATHLEN ) { errno = ENAMETOOLONG; + EVP_MD_CTX_free( mdctx ); return( -1 ); } if (( rfd = open( rsrc_path, O_RDONLY )) < 0 ) { @@ -335,11 +349,12 @@ stor_applefile( SNET *sn, char *pathdesc AS_HEADERLEN ) { fprintf( stderr, "stor_applefile %s failed: %s\n", pathdesc, strerror( errno )); + EVP_MD_CTX_free( mdctx ); return( -1 ); } size -= AS_HEADERLEN; if ( cksum ) { - EVP_DigestUpdate( &mdctx, (char *)&as_header, AS_HEADERLEN ); + EVP_DigestUpdate( mdctx, (char *)&as_header, AS_HEADERLEN ); } if ( dodots ) { putc( '.', stdout ); fflush( stdout ); } if ( showprogress ) { @@ -353,11 +368,12 @@ stor_applefile( SNET *sn, char *pathdesc != ( 3 * sizeof( struct as_entry ))) { fprintf( stderr, "stor_applefile %s failed: %s\n", pathdesc, strerror( errno )); + EVP_MD_CTX_free( mdctx ); return( -1 ); } size -= ( 3 * sizeof( struct as_entry )); if ( cksum ) { - EVP_DigestUpdate( &mdctx, (char *)&afinfo->as_ents, + EVP_DigestUpdate( mdctx, (char *)&afinfo->as_ents, (unsigned int)( 3 * sizeof( struct as_entry ))); } if ( dodots ) { putc( '.', stdout ); fflush( stdout ); } @@ -371,11 +387,12 @@ stor_applefile( SNET *sn, char *pathdesc &tv ) != FINFOLEN ) { fprintf( stderr, "stor_applefile %s failed: %s\n", pathdesc, strerror( errno )); + EVP_MD_CTX_free( mdctx ); return( -1 ); } size -= FINFOLEN; if ( cksum ) { - EVP_DigestUpdate( &mdctx, afinfo->ai.ai_data, FINFOLEN ); + EVP_DigestUpdate( mdctx, afinfo->ai.ai_data, FINFOLEN ); } if ( dodots ) { putc( '.', stdout ); fflush( stdout ); } if ( showprogress ) { @@ -389,11 +406,12 @@ stor_applefile( SNET *sn, char *pathdesc if ( snet_write( sn, buf, rc, &tv ) != rc ) { fprintf( stderr, "stor_applefile %s failed: %s\n", pathdesc, strerror( errno )); + EVP_MD_CTX_free( mdctx ); return( -1 ); } size -= rc; if ( cksum ) { - EVP_DigestUpdate( &mdctx, buf, (unsigned int)rc ); + EVP_DigestUpdate( mdctx, buf, (unsigned int)rc ); } if ( dodots ) { putc( '.', stdout ); fflush( stdout ); } if ( showprogress ) { @@ -413,11 +431,12 @@ stor_applefile( SNET *sn, char *pathdesc if ( snet_write( sn, buf, rc, &tv ) != rc ) { fprintf( stderr, "stor_applefile %s failed: %s\n", pathdesc, strerror( errno )); + EVP_MD_CTX_free( mdctx ); return( -1 ); } size -= rc; if ( cksum ) { - EVP_DigestUpdate( &mdctx, buf, (unsigned int)rc ); + EVP_DigestUpdate( mdctx, buf, (unsigned int)rc ); } if ( dodots ) { putc( '.', stdout ); fflush( stdout ); } if ( showprogress ) { @@ -442,6 +461,7 @@ stor_applefile( SNET *sn, char *pathdesc if ( snet_writef( sn, ".\r\n" ) < 0 ) { fprintf( stderr, "stor_applefile %s failed: %s\n", pathdesc, strerror( errno )); + EVP_MD_CTX_free( mdctx ); return( -1 ); } if ( verbose ) fputs( "\n>>> .\n", stdout ); @@ -463,7 +483,8 @@ stor_applefile( SNET *sn, char *pathdesc /* cksum data sent */ if ( cksum ) { - EVP_DigestFinal( &mdctx, md_value, &md_len ); + EVP_DigestFinal( mdctx, md_value, &md_len ); + EVP_MD_CTX_free( mdctx ); base64_e( ( char*)&md_value, md_len, cksum_b64 ); if ( strcmp( trancksum, cksum_b64 ) != 0 ) { fprintf( stderr,