Index: generic/tlsEncrypt.c ================================================================== --- generic/tlsEncrypt.c +++ generic/tlsEncrypt.c @@ -922,14 +922,12 @@ return TCL_ERROR; } /* Allocate storage for result. Size should be data size + block size. */ resultObj = Tcl_NewObj(); - out_buf = Tcl_SetByteArrayLength(resultObj, data_len+EVP_MAX_BLOCK_LENGTH); - if (resultObj == NULL || out_buf == NULL) { + if (resultObj == NULL) { Tcl_AppendResult(interp, "Memory allocation error", (char *) NULL); - Tcl_DecrRefCount(resultObj); return TCL_ERROR; } /* Do function */ if (fn) { @@ -936,11 +934,18 @@ /* Get data or return error if none */ if (objc == 3) { data = Tcl_GetByteArrayFromObj(objv[2], &data_len); } else { Tcl_WrongNumArgs(interp, 1, objv, "update data"); + return TCL_ERROR; + } + + /* Allocate output buffer */ + out_buf = Tcl_SetByteArrayLength(resultObj, data_len+EVP_MAX_BLOCK_LENGTH); + if (data == NULL || out_buf == NULL) { Tcl_DecrRefCount(resultObj); + Tcl_AppendResult(interp, "Memory allocation error", (char *) NULL); return TCL_ERROR; } /* Update function */ if (EncryptUpdate(interp, statePtr->type, statePtr->ctx, out_buf, &out_len, data, data_len) == TCL_OK) { @@ -950,10 +955,18 @@ Tcl_DecrRefCount(resultObj); return TCL_ERROR; } } else { + /* Allocate output buffer */ + out_buf = Tcl_SetByteArrayLength(resultObj, EVP_MAX_BLOCK_LENGTH); + if (out_buf == NULL) { + Tcl_DecrRefCount(resultObj); + Tcl_AppendResult(interp, "Memory allocation error", (char *) NULL); + return TCL_ERROR; + } + /* Finalize function */ if (EncryptFinalize(interp, statePtr->type, statePtr->ctx, out_buf, &out_len) == TCL_OK) { out_buf = Tcl_SetByteArrayLength(resultObj, (Tcl_Size) out_len); Tcl_SetObjResult(interp, resultObj); } else { @@ -1107,11 +1120,12 @@ /* *------------------------------------------------------------------- * * EncryptFileHandler -- * - * Perform encryption function on a block of data and return result. + * Perform encryption function on a block of data, write it to a + * file, then return the result. * * Returns: * TCL_OK or TCL_ERROR * * Side effects: