gcc-lots-o-warnings fixes

This commit is contained in:
toddouska
2012-05-25 13:09:27 -07:00
parent 6a62623c64
commit a1bb4e3f93
3 changed files with 106 additions and 97 deletions

View File

@@ -4105,94 +4105,94 @@ static int GetEnumerated(const byte* input, word32* inOutIdx, int *value)
static int DecodeSingleResponse(byte* source, static int DecodeSingleResponse(byte* source,
word32* ioIndex, OcspResponse* resp, word32 size) word32* ioIndex, OcspResponse* resp, word32 size)
{ {
word32 index = *ioIndex, prevIndex, oid; word32 idx = *ioIndex, prevIndex, oid;
int length, remainder, qty = 0; int length, remainder, qty = 0;
/* Outer wrapper of the SEQUENCE OF Single Responses. */ /* Outer wrapper of the SEQUENCE OF Single Responses. */
if (GetSequence(source, &index, &length, size) < 0) if (GetSequence(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
remainder = length; remainder = length;
/* First Single Response */ /* First Single Response */
while (remainder != 0 && qty < STATUS_LIST_SIZE) while (remainder != 0 && qty < STATUS_LIST_SIZE)
{ {
prevIndex = index; prevIndex = idx;
/* Wrapper around the Single Response */ /* Wrapper around the Single Response */
if (GetSequence(source, &index, &length, size) < 0) if (GetSequence(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
/* Wrapper around the CertID */ /* Wrapper around the CertID */
if (GetSequence(source, &index, &length, size) < 0) if (GetSequence(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
/* Skip the hash algorithm */ /* Skip the hash algorithm */
if (GetAlgoId(source, &index, &oid, size) < 0) if (GetAlgoId(source, &idx, &oid, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
/* Skip the hash of CN */ /* Skip the hash of CN */
if (source[index++] != ASN_OCTET_STRING) if (source[idx++] != ASN_OCTET_STRING)
return ASN_PARSE_E; return ASN_PARSE_E;
if (GetLength(source, &index, &length, size) < 0) if (GetLength(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
index += length; idx += length;
/* Skip the hash of the issuer public key */ /* Skip the hash of the issuer public key */
if (source[index++] != ASN_OCTET_STRING) if (source[idx++] != ASN_OCTET_STRING)
return ASN_PARSE_E; return ASN_PARSE_E;
if (GetLength(source, &index, &length, size) < 0) if (GetLength(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
index += length; idx += length;
/* Read the serial number, it is handled as a string, not as a /* Read the serial number, it is handled as a string, not as a
* proper number. Just XMEMCPY the data over, rather than load it * proper number. Just XMEMCPY the data over, rather than load it
* as an mp_int. */ * as an mp_int. */
if (source[index++] != ASN_INTEGER) if (source[idx++] != ASN_INTEGER)
return ASN_PARSE_E; return ASN_PARSE_E;
if (GetLength(source, &index, &length, size) < 0) if (GetLength(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
if (length <= EXTERNAL_SERIAL_SIZE) { if (length <= EXTERNAL_SERIAL_SIZE) {
if (source[index] == 0) { if (source[idx] == 0) {
index++; idx++;
length--; length--;
} }
XMEMCPY(resp->certSN[qty], source + index, length); XMEMCPY(resp->certSN[qty], source + idx, length);
resp->certSNsz[qty] = length; resp->certSNsz[qty] = length;
} else { } else {
return ASN_GETINT_E; return ASN_GETINT_E;
} }
index += length; idx += length;
/* CertStatus */ /* CertStatus */
switch (source[index++]) switch (source[idx++])
{ {
case (ASN_CONTEXT_SPECIFIC | CERT_GOOD): case (ASN_CONTEXT_SPECIFIC | CERT_GOOD):
resp->certStatus[qty] = CERT_GOOD; resp->certStatus[qty] = CERT_GOOD;
index++; idx++;
break; break;
case (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | CERT_REVOKED): case (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | CERT_REVOKED):
resp->certStatus[qty] = CERT_REVOKED; resp->certStatus[qty] = CERT_REVOKED;
GetLength(source, &index, &length, size); GetLength(source, &idx, &length, size);
index += length; idx += length;
break; break;
case (ASN_CONTEXT_SPECIFIC | CERT_UNKNOWN): case (ASN_CONTEXT_SPECIFIC | CERT_UNKNOWN):
resp->certStatus[qty] = CERT_UNKNOWN; resp->certStatus[qty] = CERT_UNKNOWN;
index++; idx++;
break; break;
default: default:
return ASN_PARSE_E; return ASN_PARSE_E;
} }
if (source[index++] != ASN_GENERALIZED_TIME) if (source[idx++] != ASN_GENERALIZED_TIME)
return ASN_PARSE_E; return ASN_PARSE_E;
if (GetLength(source, &index, &length, size) < 0) if (GetLength(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
resp->thisUpdate = source + index; resp->thisUpdate = source + idx;
index += length; idx += length;
remainder = remainder + prevIndex - index; remainder = remainder + prevIndex - idx;
qty++; qty++;
} }
resp->certStatusCount = qty; resp->certStatusCount = qty;
*ioIndex = index; *ioIndex = idx;
return 0; return 0;
} }
@@ -4200,60 +4200,60 @@ static int DecodeSingleResponse(byte* source,
static int DecodeOcspRespExtensions(byte* source, static int DecodeOcspRespExtensions(byte* source,
word32* ioIndex, OcspResponse* resp, word32 sz) word32* ioIndex, OcspResponse* resp, word32 sz)
{ {
word32 index = *ioIndex; word32 idx = *ioIndex;
int length; int length;
int ext_bound; /* boundary index for the sequence of extensions */ int ext_bound; /* boundary index for the sequence of extensions */
word32 oid; word32 oid;
CYASSL_ENTER("DecodeOcspRespExtensions"); CYASSL_ENTER("DecodeOcspRespExtensions");
if (source[index++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC | 1)) if (source[idx++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC | 1))
return ASN_PARSE_E; return ASN_PARSE_E;
if (GetLength(source, &index, &length, sz) < 0) return ASN_PARSE_E; if (GetLength(source, &idx, &length, sz) < 0) return ASN_PARSE_E;
if (GetSequence(source, &index, &length, sz) < 0) return ASN_PARSE_E; if (GetSequence(source, &idx, &length, sz) < 0) return ASN_PARSE_E;
ext_bound = index + length; ext_bound = idx + length;
while (index < ext_bound) { while (idx < (word32)ext_bound) {
if (GetSequence(source, &index, &length, sz) < 0) { if (GetSequence(source, &idx, &length, sz) < 0) {
CYASSL_MSG("\tfail: should be a SEQUENCE"); CYASSL_MSG("\tfail: should be a SEQUENCE");
return ASN_PARSE_E; return ASN_PARSE_E;
} }
oid = 0; oid = 0;
if (GetObjectId(source, &index, &oid, sz) < 0) { if (GetObjectId(source, &idx, &oid, sz) < 0) {
CYASSL_MSG("\tfail: OBJECT ID"); CYASSL_MSG("\tfail: OBJECT ID");
return ASN_PARSE_E; return ASN_PARSE_E;
} }
/* check for critical flag */ /* check for critical flag */
if (source[index] == ASN_BOOLEAN) { if (source[idx] == ASN_BOOLEAN) {
CYASSL_MSG("\tfound optional critical flag, moving past"); CYASSL_MSG("\tfound optional critical flag, moving past");
index += (ASN_BOOL_SIZE + 1); idx += (ASN_BOOL_SIZE + 1);
} }
/* process the extension based on the OID */ /* process the extension based on the OID */
if (source[index++] != ASN_OCTET_STRING) { if (source[idx++] != ASN_OCTET_STRING) {
CYASSL_MSG("\tfail: should be an OCTET STRING"); CYASSL_MSG("\tfail: should be an OCTET STRING");
return ASN_PARSE_E; return ASN_PARSE_E;
} }
if (GetLength(source, &index, &length, sz) < 0) { if (GetLength(source, &idx, &length, sz) < 0) {
CYASSL_MSG("\tfail: extension data length"); CYASSL_MSG("\tfail: extension data length");
return ASN_PARSE_E; return ASN_PARSE_E;
} }
if (oid == OCSP_NONCE_OID) { if (oid == OCSP_NONCE_OID) {
resp->nonce = source + index; resp->nonce = source + idx;
resp->nonceSz = length; resp->nonceSz = length;
} }
index += length; idx += length;
} }
*ioIndex = index; *ioIndex = idx;
return 0; return 0;
} }
@@ -4261,54 +4261,54 @@ static int DecodeOcspRespExtensions(byte* source,
static int DecodeResponseData(byte* source, static int DecodeResponseData(byte* source,
word32* ioIndex, OcspResponse* resp, word32 size) word32* ioIndex, OcspResponse* resp, word32 size)
{ {
word32 index = *ioIndex; word32 idx = *ioIndex;
int length, result; int length;
int version; int version;
word32 responderId = 0; word32 responderId = 0;
if (GetSequence(source, &index, &length, size) < 0) if (GetSequence(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
resp->respBegin = index; resp->respBegin = idx;
resp->respLength = length; resp->respLength = length;
/* Get version. It is an EXPLICIT[0] DEFAULT(0) value. If this /* Get version. It is an EXPLICIT[0] DEFAULT(0) value. If this
* item isn't an EXPLICIT[0], then set version to zero and move * item isn't an EXPLICIT[0], then set version to zero and move
* onto the next item. * onto the next item.
*/ */
if (source[index] == (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED)) if (source[idx] == (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED))
{ {
index += 2; /* Eat the value and length */ idx += 2; /* Eat the value and length */
if (GetMyVersion(source, &index, &version) < 0) if (GetMyVersion(source, &idx, &version) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
} else } else
version = 0; version = 0;
responderId = source[index++]; responderId = source[idx++];
if ((responderId == (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | 1)) || if ((responderId == (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | 1)) ||
(responderId == (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | 2))) (responderId == (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | 2)))
{ {
if (GetLength(source, &index, &length, size) < 0) if (GetLength(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
index += length; idx += length;
} }
else else
return ASN_PARSE_E; return ASN_PARSE_E;
/* save pointer to the producedAt time */ /* save pointer to the producedAt time */
if (source[index++] != ASN_GENERALIZED_TIME) if (source[idx++] != ASN_GENERALIZED_TIME)
return ASN_PARSE_E; return ASN_PARSE_E;
if (GetLength(source, &index, &length, size) < 0) if (GetLength(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
resp->producedAt = source + index; resp->producedAt = source + idx;
index += length; idx += length;
if (DecodeSingleResponse(source, &index, resp, size) < 0) if (DecodeSingleResponse(source, &idx, resp, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
if (DecodeOcspRespExtensions(source, &index, resp, size) < 0) if (DecodeOcspRespExtensions(source, &idx, resp, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
*ioIndex = index; *ioIndex = idx;
return 0; return 0;
} }
@@ -4316,16 +4316,19 @@ static int DecodeResponseData(byte* source,
static int DecodeCerts(byte* source, static int DecodeCerts(byte* source,
word32* ioIndex, OcspResponse* resp, word32 size) word32* ioIndex, OcspResponse* resp, word32 size)
{ {
word32 index = *ioIndex; word32 idx = *ioIndex;
if (source[index++] == (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC))
(void)resp;
if (source[idx++] == (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC))
{ {
int length; int length;
if (GetLength(source, &index, &length, size) < 0) if (GetLength(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
index += length; idx += length;
} }
*ioIndex = index; *ioIndex = idx;
return 0; return 0;
} }
@@ -4333,42 +4336,42 @@ static int DecodeBasicOcspResponse(byte* source,
word32* ioIndex, OcspResponse* resp, word32 size) word32* ioIndex, OcspResponse* resp, word32 size)
{ {
int length; int length;
word32 index = *ioIndex; word32 idx = *ioIndex;
word32 end_index; word32 end_index;
if (GetSequence(source, &index, &length, size) < 0) if (GetSequence(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
if (index + length > size) if (idx + length > size)
return ASN_INPUT_E; return ASN_INPUT_E;
end_index = index + length; end_index = idx + length;
if (DecodeResponseData(source, &index, resp, size) < 0) if (DecodeResponseData(source, &idx, resp, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
/* Get the signature algorithm */ /* Get the signature algorithm */
if (GetAlgoId(source, &index, &resp->sigOID, size) < 0) if (GetAlgoId(source, &idx, &resp->sigOID, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
/* Obtain pointer to the start of the signature, and save the size */ /* Obtain pointer to the start of the signature, and save the size */
if (source[index++] == ASN_BIT_STRING) if (source[idx++] == ASN_BIT_STRING)
{ {
int sigLength = 0; int sigLength = 0;
if (GetLength(source, &index, &sigLength, size) < 0) if (GetLength(source, &idx, &sigLength, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
resp->sigLength = sigLength; resp->sigLength = sigLength;
resp->sigIndex = index; resp->sigIndex = idx;
index += sigLength; idx += sigLength;
} }
/* /*
* Check the length of the BasicOcspResponse against the current index to * Check the length of the BasicOcspResponse against the current index to
* see if there are certificates, they are optional. * see if there are certificates, they are optional.
*/ */
if (index < end_index) if (idx < end_index)
return DecodeCerts(source, &index, resp, size); return DecodeCerts(source, &idx, resp, size);
*ioIndex = index; *ioIndex = idx;
return 0; return 0;
} }
@@ -4382,52 +4385,55 @@ void InitOcspResponse(OcspResponse* resp, byte* source, word32 inSz, void* heap)
} }
void FreeOcspResponse(OcspResponse* resp) {} void FreeOcspResponse(OcspResponse* resp)
{
(void)resp;
}
int OcspResponseDecode(OcspResponse* resp) int OcspResponseDecode(OcspResponse* resp)
{ {
int length = 0; int length = 0;
word32 index = 0; word32 idx = 0;
byte* source = resp->source; byte* source = resp->source;
word32 size = resp->maxIdx; word32 size = resp->maxIdx;
word32 oid; word32 oid;
/* peel the outer SEQUENCE wrapper */ /* peel the outer SEQUENCE wrapper */
if (GetSequence(source, &index, &length, size) < 0) if (GetSequence(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
/* First get the responseStatus, an ENUMERATED */ /* First get the responseStatus, an ENUMERATED */
if (GetEnumerated(source, &index, &resp->responseStatus) < 0) if (GetEnumerated(source, &idx, &resp->responseStatus) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
if (resp->responseStatus != OCSP_SUCCESSFUL) if (resp->responseStatus != OCSP_SUCCESSFUL)
return 0; return 0;
/* Next is an EXPLICIT record called ResponseBytes, OPTIONAL */ /* Next is an EXPLICIT record called ResponseBytes, OPTIONAL */
if (index >= size) if (idx >= size)
return ASN_INPUT_E; return ASN_INPUT_E;
if (source[index++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC)) if (source[idx++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC))
return ASN_PARSE_E; return ASN_PARSE_E;
if (GetLength(source, &index, &length, size) < 0) if (GetLength(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
/* Get the responseBytes SEQUENCE */ /* Get the responseBytes SEQUENCE */
if (GetSequence(source, &index, &length, size) < 0) if (GetSequence(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
/* Check ObjectID for the resposeBytes */ /* Check ObjectID for the resposeBytes */
if (GetObjectId(source, &index, &oid, size) < 0) if (GetObjectId(source, &idx, &oid, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
if (oid != OCSP_BASIC_OID) if (oid != OCSP_BASIC_OID)
return ASN_PARSE_E; return ASN_PARSE_E;
if (source[index++] != ASN_OCTET_STRING) if (source[idx++] != ASN_OCTET_STRING)
return ASN_PARSE_E; return ASN_PARSE_E;
if (GetLength(source, &index, &length, size) < 0) if (GetLength(source, &idx, &length, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
if (DecodeBasicOcspResponse(source, &index, resp, size) < 0) if (DecodeBasicOcspResponse(source, &idx, resp, size) < 0)
return ASN_PARSE_E; return ASN_PARSE_E;
return 0; return 0;
@@ -4515,6 +4521,8 @@ int EncodeOcspRequest(DecodedCert* cert, byte* output, word32 outputSz)
extSz, totalSz; extSz, totalSz;
int i; int i;
(void)outputSz;
CYASSL_ENTER("EncodeOcspRequest"); CYASSL_ENTER("EncodeOcspRequest");
algoSz = SetAlgoID(SHAh, algoArray, hashType); algoSz = SetAlgoID(SHAh, algoArray, hashType);
issuerSz = SetDigest(cert->issuerHash, SHA_SIZE, issuerArray); issuerSz = SetDigest(cert->issuerHash, SHA_SIZE, issuerArray);

View File

@@ -463,7 +463,7 @@ static void* DoMonitor(void* arg)
/* Start Monitoring the CRL path(s) in a thread */ /* Start Monitoring the CRL path(s) in a thread */
int StartMonitorCRL(CYASSL_CRL* crl) static int StartMonitorCRL(CYASSL_CRL* crl)
{ {
pthread_attr_t attr; pthread_attr_t attr;
@@ -490,7 +490,7 @@ int StartMonitorCRL(CYASSL_CRL* crl)
#else /* HAVE_CRL_MONITOR */ #else /* HAVE_CRL_MONITOR */
int StartMonitorCRL(CYASSL_CRL* crl) static int StartMonitorCRL(CYASSL_CRL* crl)
{ {
return NOT_COMPILED_IN; return NOT_COMPILED_IN;
} }

View File

@@ -104,7 +104,7 @@ static int decode_url(const char* url, int urlSz,
} }
else else
{ {
int i, cur, hostname; int i, cur;
/* need to break the url down into scheme, address, and port */ /* need to break the url down into scheme, address, and port */
/* "http://example.com:8080/" */ /* "http://example.com:8080/" */
@@ -185,8 +185,9 @@ static INLINE void tcp_socket(SOCKET_T* sockfd, SOCKADDR_IN_T* addr,
entry->h_length); entry->h_length);
host = inet_ntoa(tmp.sin_addr); host = inet_ntoa(tmp.sin_addr);
} }
else else {
CYASSL_MSG("no entry for host"); CYASSL_MSG("no entry for host");
}
} }
*sockfd = socket(AF_INET_V, SOCK_STREAM, 0); *sockfd = socket(AF_INET_V, SOCK_STREAM, 0);
@@ -206,8 +207,9 @@ static INLINE void tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port)
SOCKADDR_IN_T addr; SOCKADDR_IN_T addr;
tcp_socket(sockfd, &addr, ip, port); tcp_socket(sockfd, &addr, ip, port);
if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) if (connect(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) {
CYASSL_MSG("tcp connect failed"); CYASSL_MSG("tcp connect failed");
}
} }
@@ -230,7 +232,6 @@ static byte* decode_http_response(byte* httpBuf, int httpBufSz, int* ocspRespSz)
int stop = 0; int stop = 0;
byte* contentType = NULL; byte* contentType = NULL;
byte* contentLength = NULL; byte* contentLength = NULL;
byte* content = NULL;
char* buf = (char*)httpBuf; /* kludge so I'm not constantly casting */ char* buf = (char*)httpBuf; /* kludge so I'm not constantly casting */
if (strncasecmp(buf, "HTTP/1", 6) != 0) if (strncasecmp(buf, "HTTP/1", 6) != 0)