Skip to content

Commit

Permalink
Some further cleanup of p12d.c. Bugscape bug 52528. r=wtc.
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonb%netscape.com committed Dec 20, 2003
1 parent 3052b8f commit 1a1c248
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions security/nss/lib/pkcs12/p12d.c
Expand Up @@ -1098,14 +1098,15 @@ p12u_DigestRead(void *arg, unsigned char *buf, unsigned long len)
SEC_PKCS12DecoderContext* p12cxt = arg;

if(!buf || len == 0 || !p12cxt->buffer) {
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return -1;
}

if ((p12cxt->filesize - p12cxt->currentpos) < (long)len) {
/* trying to read past the end of the buffer */
toread = p12cxt->filesize - p12cxt->currentpos;
}
memcpy(buf, (void*)((char*)p12cxt->buffer + p12cxt->currentpos), toread);
memcpy(buf, (char*)p12cxt->buffer + p12cxt->currentpos, toread);
p12cxt->currentpos += toread;
return toread;
}
Expand Down Expand Up @@ -1136,7 +1137,7 @@ p12u_DigestWrite(void *arg, unsigned char *buf, unsigned long len)
p12cxt->allocated = newsize;
}
PR_ASSERT(p12cxt->buffer);
memcpy((void*)((char*)p12cxt->buffer + p12cxt->currentpos), buf, len);
memcpy((char*)p12cxt->buffer + p12cxt->currentpos, buf, len);
p12cxt->currentpos += len;
return len;
}
Expand Down Expand Up @@ -1291,10 +1292,8 @@ SEC_PKCS12DecoderUpdate(SEC_PKCS12DecoderContext *p12dcx,
#define IN_BUF_LEN 1024
#ifdef DEBUG
static const char bufferEnd[] = { "BufferEnd" } ;
#define FUDGE sizeof bufferEnd
#else
#define FUDGE 128 /* extra protection when assertions disabled. */
#endif
#define FUDGE 128 /* must be as large as bufferEnd or more. */

/* verify the hmac by reading the data from the temporary file
* using the routines specified when the decodingContext was
Expand All @@ -1318,6 +1317,7 @@ sec_pkcs12_decoder_verify_mac(SEC_PKCS12DecoderContext *p12dcx)
CK_MECHANISM_TYPE integrityMech;

if(!p12dcx || p12dcx->error) {
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return SECFailure;
}
buf = (unsigned char *)PORT_Alloc(IN_BUF_LEN + FUDGE);
Expand Down Expand Up @@ -1388,7 +1388,7 @@ sec_pkcs12_decoder_verify_mac(SEC_PKCS12DecoderContext *p12dcx)

if (bytesRead > IN_BUF_LEN) {
/* dRead callback overflowed buffer. */
PORT_SetError(SEC_ERROR_PKCS12_UNABLE_TO_READ);
PORT_SetError(SEC_ERROR_INPUT_LEN);
goto loser;
}

Expand Down

0 comments on commit 1a1c248

Please sign in to comment.