Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(xmlsec-mingw) Fix build and tests #791

Merged
merged 16 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified config.h.in
100644 → 100755
Empty file.
485 changes: 235 additions & 250 deletions configure.ac

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/cast_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@
*
*****************************************************************************/

/* Safe cast with limits check: unsigned int -> long (assume uint >= 0) */
#if (UINT_MAX > LONG_MAX)

#define XMLSEC_SAFE_CAST_UINT_TO_LONG(srcVal, dstVal, errorAction, errorObject) \
XMLSEC_SAFE_CAST_MAX_CHECK(unsigned int, (srcVal), "%u", \
int, (dstVal), "%ld", LONG_MIN, LONG_MAX, \
errorAction, (errorObject))

#else /* UINT_MAX > LONG_MAX */

#define XMLSEC_SAFE_CAST_UINT_TO_LONG(srcVal, dstVal, errorAction, errorObject) \
(dstVal) = (srcVal);

#endif /* UINT_MAX > LONG_MAX */


/* Safe cast with limits check: size_t -> long (assume size_t >= 0) */
#if (SIZE_MAX > LONG_MAX)

Expand Down
4 changes: 2 additions & 2 deletions src/gnutls/asymkeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ xmlSecGnuTLSKeyDataEcPubKeyFromPrivKey(gnutls_privkey_t privkey) {
err = gnutls_privkey_export_ecc_raw2(privkey,
&curve, &x, &y, &k,
0);
if((err != GNUTLS_E_SUCCESS) && (curve != GNUTLS_ECC_CURVE_INVALID)) {
if((err != GNUTLS_E_SUCCESS) || (curve == GNUTLS_ECC_CURVE_INVALID)) {
xmlSecGnuTLSError("gnutls_privkey_export_ecc_raw2", err, NULL);
goto done;
}
Expand Down Expand Up @@ -2190,7 +2190,7 @@ xmlSecGnuTLSKeyDataGostPubKeyFromPrivKey(gnutls_privkey_t privkey) {
&curve, &digest, &paramset,
&x, &y, &k,
0);
if((err != GNUTLS_E_SUCCESS) && (curve != GNUTLS_ECC_CURVE_INVALID)) {
if((err != GNUTLS_E_SUCCESS) || (curve == GNUTLS_ECC_CURVE_INVALID)) {
xmlSecGnuTLSError("gnutls_privkey_export_gost_raw2", err, NULL);
goto done;
}
Expand Down
5 changes: 2 additions & 3 deletions src/gnutls/kt_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "../cast_helpers.h"
#include "../transform_helpers.h"


/*********************************************************************
*
* Key transport transforms context
Expand Down Expand Up @@ -213,7 +212,7 @@ xmlSecGnuTLSKeyTransportEncrypt(xmlSecGnuTLSKeyTransportCtxPtr ctx, xmlSecBuffer
0 /* flags */,
&plaintext,
&encrypted);
if((err != GNUTLS_E_SUCCESS) && (encrypted.data != NULL)) {
if((err != GNUTLS_E_SUCCESS) || (encrypted.data == NULL)) {
xmlSecGnuTLSError("gnutls_pubkey_encrypt_data", err, NULL);
return(-1);
}
Expand Down Expand Up @@ -262,7 +261,7 @@ xmlSecGnuTLSKeyTransportDecrypt(xmlSecGnuTLSKeyTransportCtxPtr ctx, xmlSecBuffer
0 /* flags */,
&ciphertext,
&plaintext);
if((err != GNUTLS_E_SUCCESS) && (plaintext.data != NULL)) {
if((err != GNUTLS_E_SUCCESS) || (plaintext.data == NULL)) {
xmlSecGnuTLSError("gnutls_privkey_decrypt_data", err, NULL);
return(-1);
}
Expand Down
1 change: 0 additions & 1 deletion src/keyinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,6 @@ xmlSecKeyDataEncryptedKeyXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePt
xmlSecKeyDataKlassGetName(id));
return(-1);
}

return(0);
}

Expand Down
2 changes: 0 additions & 2 deletions src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,11 @@ xmlSecKeyReqMatchKeyValue(xmlSecKeyReqPtr keyReq, xmlSecKeyDataPtr value) {

if((keyReq->keyId != xmlSecKeyDataIdUnknown) &&
(!xmlSecKeyDataCheckId(value, keyReq->keyId))) {

return(0);
}
if((keyReq->keyBitsSize > 0) &&
(xmlSecKeyDataGetSize(value) > 0) &&
(xmlSecKeyDataGetSize(value) < keyReq->keyBitsSize)) {

return(0);
}
return(1);
Expand Down
6 changes: 5 additions & 1 deletion src/nss/keytrans.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,18 @@ xmlSecNssKeyTransportCtxUpdate(xmlSecNssKeyTransportCtxPtr ctx, xmlSecBufferPtr
#ifndef XMLSEC_NO_RSA_OAEP
static int
xmlSecNssKeyTransportSetOaepParams(xmlSecNssKeyTransportCtxPtr ctx, CK_RSA_PKCS_OAEP_PARAMS* oaepParams) {
xmlSecSize size;

xmlSecAssert2(ctx != NULL, -1);
xmlSecAssert2(oaepParams != NULL, -1);

oaepParams->hashAlg = ctx->oaepHashAlg;
oaepParams->mgf = ctx->oaepMgf ;
oaepParams->source = CKZ_DATA_SPECIFIED;
oaepParams->pSourceData = xmlSecBufferGetData(&(ctx->oaepParams));
oaepParams->ulSourceDataLen = xmlSecBufferGetSize(&(ctx->oaepParams));

size = xmlSecBufferGetSize(&(ctx->oaepParams));
XMLSEC_SAFE_CAST_SIZE_TO_ULONG(size, oaepParams->ulSourceDataLen, return(-1), NULL);

return(0);
}
Expand Down
6 changes: 4 additions & 2 deletions src/nss/signatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct _xmlSecNssSignatureCtx {
PLArenaPool* arena;
SECOidTag pssHashAlgTag;
SECOidTag pssMaskAlgTag;
long pssSaltLength;
unsigned int pssSaltLength;

union {
struct {
Expand Down Expand Up @@ -424,6 +424,7 @@ xmlSecNssSignatureCreatePssParams(xmlSecNssSignatureCtxPtr ctx) {
SECAlgorithmID maskHashAlg;
SECItem *maskHashAlgItem;
SECItem *saltLengthItem;
long saltLength;
SECStatus rv;
SECItem* res;

Expand Down Expand Up @@ -470,7 +471,8 @@ xmlSecNssSignatureCreatePssParams(xmlSecNssSignatureCtxPtr ctx) {
}

/* salt length */
saltLengthItem = SEC_ASN1EncodeInteger(ctx->arena, &(params.saltLength), ctx->pssSaltLength);
XMLSEC_SAFE_CAST_UINT_TO_LONG(ctx->pssSaltLength, saltLength, return(NULL), NULL);
saltLengthItem = SEC_ASN1EncodeInteger(ctx->arena, &(params.saltLength), saltLength);
if(saltLengthItem != &(params.saltLength)) {
xmlSecNssError("SEC_ASN1EncodeInteger(saltLength)", NULL);
return(NULL);
Expand Down
Loading