fix coverity tell < 0 and store fread bytes issues

This commit is contained in:
toddouska
2014-12-04 10:53:29 -08:00
parent a9d9ff8b58
commit 7fbf8359e2

View File

@@ -8659,9 +8659,15 @@ CYASSL_X509* CyaSSL_X509_d2i_fp(CYASSL_X509** x509, XFILE file)
sz = XFTELL(file); sz = XFTELL(file);
XREWIND(file); XREWIND(file);
if (sz < 0) {
CYASSL_MSG("Bad tell on FILE");
return NULL;
}
fileBuffer = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE); fileBuffer = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE);
if (fileBuffer != NULL) { if (fileBuffer != NULL) {
if ((int)XFREAD(fileBuffer, sz, 1, file) > 0) { int ret = (int)XFREAD(fileBuffer, sz, 1, file);
if (ret > 0) {
newX509 = CyaSSL_X509_d2i(NULL, fileBuffer, (int)sz); newX509 = CyaSSL_X509_d2i(NULL, fileBuffer, (int)sz);
} }
XFREE(fileBuffer, NULL, DYNAMIC_TYPE_FILE); XFREE(fileBuffer, NULL, DYNAMIC_TYPE_FILE);
@@ -8685,6 +8691,7 @@ CYASSL_X509* CyaSSL_X509_load_certificate_file(const char* fname, int format)
#endif #endif
byte* fileBuffer = staticBuffer; byte* fileBuffer = staticBuffer;
int dynamic = 0; int dynamic = 0;
int ret;
long sz = 0; long sz = 0;
XFILE file; XFILE file;
@@ -8714,8 +8721,13 @@ CYASSL_X509* CyaSSL_X509_load_certificate_file(const char* fname, int format)
} }
dynamic = 1; dynamic = 1;
} }
else if (sz < 0) {
XFCLOSE(file);
return NULL;
}
if ((int)XFREAD(fileBuffer, sz, 1, file) < 0) { ret = (int)XFREAD(fileBuffer, sz, 1, file);
if (ret < 0) {
XFCLOSE(file); XFCLOSE(file);
if (dynamic) if (dynamic)
XFREE(fileBuffer, NULL, DYNAMIC_TYPE_FILE); XFREE(fileBuffer, NULL, DYNAMIC_TYPE_FILE);