mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Fix buffer overflow and formatting
This commit is contained in:
parent
b39146d9c3
commit
77ab33f7bf
@ -24,43 +24,42 @@ void MD5Builder::addHexString(const char * data){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MD5Builder::addStream(Stream & stream, const size_t total_len) {
|
bool MD5Builder::addStream(Stream & stream, const size_t total_len) {
|
||||||
const int buf_size = 512;
|
const int buf_size = 512;
|
||||||
int bytesleft = total_len;
|
int bytesleft = total_len;
|
||||||
uint8_t * buf = (uint8_t*) malloc(buf_size);
|
uint8_t * buf = (uint8_t*) malloc(buf_size);
|
||||||
if(buf) {
|
if(buf) {
|
||||||
while((stream.available() > -1) && (bytesleft > 0)) {
|
while((stream.available() > -1) && (bytesleft > 0)) {
|
||||||
|
// get available data size
|
||||||
|
int sizeAvailable = stream.available();
|
||||||
|
if(sizeAvailable) {
|
||||||
|
int readBytes = sizeAvailable;
|
||||||
|
|
||||||
// get available data size
|
// read only the asked bytes
|
||||||
int sizeAvailable = stream.available();
|
if(readBytes > bytesleft) {
|
||||||
if(sizeAvailable) {
|
readBytes = bytesleft ;
|
||||||
int readBytes = sizeAvailable;
|
|
||||||
|
|
||||||
// read only the asked bytes
|
|
||||||
if(readBytes > bytesleft) {
|
|
||||||
readBytes = bytesleft ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// not read more the buffer can handle
|
|
||||||
if(readBytes > buf_size) {
|
|
||||||
readBytes = buf_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// read data
|
|
||||||
int bytesread = stream.readBytes(buf, readBytes);
|
|
||||||
bytesleft -= bytesread;
|
|
||||||
if(bytesread > 0) {
|
|
||||||
MD5Update(&_ctx, buf, bytesread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// time for network streams
|
|
||||||
delay(0);
|
|
||||||
}
|
}
|
||||||
// not free null ptr
|
|
||||||
free(buf);
|
// not read more the buffer can handle
|
||||||
return (bytesleft == 0);
|
if(readBytes > buf_size) {
|
||||||
} else {
|
readBytes = buf_size;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
// read data
|
||||||
|
int bytesread = stream.readBytes(buf, readBytes);
|
||||||
|
bytesleft -= bytesread;
|
||||||
|
if(bytesread > 0) {
|
||||||
|
MD5Update(&_ctx, buf, bytesread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// time for network streams
|
||||||
|
delay(0);
|
||||||
}
|
}
|
||||||
|
// guaranteed not null
|
||||||
|
free(buf);
|
||||||
|
return (bytesleft == 0);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MD5Builder::calculate(void){
|
void MD5Builder::calculate(void){
|
||||||
@ -77,7 +76,7 @@ void MD5Builder::getChars(char * output){
|
|||||||
}
|
}
|
||||||
|
|
||||||
String MD5Builder::toString(void){
|
String MD5Builder::toString(void){
|
||||||
char out[32];
|
char out[33];
|
||||||
getChars(out);
|
getChars(out);
|
||||||
return String(out);
|
return String(out);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user