fixing incorrect buffer size allocation, and unsafe integer size type

This commit is contained in:
SlowRiot 2014-11-20 01:58:57 +00:00
parent 87333f3ae2
commit 76cc2bf7b4
2 changed files with 64 additions and 60 deletions

View File

@ -13,6 +13,8 @@
-- Bruce Guenter <bruce@untroubled.org> -- Bruce Guenter <bruce@untroubled.org>
Translation to simpler C++ Code Translation to simpler C++ Code
-- Volker Grabsch <vog@notjusthosting.com> -- Volker Grabsch <vog@notjusthosting.com>
Fixing bugs and improving style
-- Eugene Hopkinson <slowriot at voxelstorm dot com>
*/ */
#include "sha1.h" #include "sha1.h"
@ -241,7 +243,7 @@ void SHA1::transform(uint32 block[BLOCK_BYTES])
} }
void SHA1::buffer_to_block(const std::string &buffer, uint32 block[BLOCK_BYTES]) void SHA1::buffer_to_block(const std::string &buffer, uint32 block[BLOCK_INTS])
{ {
/* Convert the std::string (byte buffer) to a uint32 array (MSB) */ /* Convert the std::string (byte buffer) to a uint32 array (MSB) */
for (unsigned int i = 0; i < BLOCK_INTS; i++) for (unsigned int i = 0; i < BLOCK_INTS; i++)
@ -254,7 +256,7 @@ void SHA1::buffer_to_block(const std::string &buffer, uint32 block[BLOCK_BYTES])
} }
void SHA1::read(std::istream &is, std::string &s, int max) void SHA1::read(std::istream &is, std::string &s, size_t max)
{ {
char* sbuf = new char[max]; char* sbuf = new char[max];

View File

@ -13,6 +13,8 @@
-- Bruce Guenter <bruce@untroubled.org> -- Bruce Guenter <bruce@untroubled.org>
Translation to simpler C++ Code Translation to simpler C++ Code
-- Volker Grabsch <vog@notjusthosting.com> -- Volker Grabsch <vog@notjusthosting.com>
Fixing bugs and improving style
-- Eugene Hopkinson <slowriot at voxelstorm dot com>
*/ */
#ifndef SHA1_HPP #ifndef SHA1_HPP
@ -46,8 +48,8 @@ private:
void reset(); void reset();
void transform(uint32 block[BLOCK_BYTES]); void transform(uint32 block[BLOCK_BYTES]);
static void buffer_to_block(const std::string &buffer, uint32 block[BLOCK_BYTES]); static void read(std::istream &is, std::string &s, size_t max);
static void read(std::istream &is, std::string &s, int max); static void buffer_to_block(const std::string &buffer, uint32 block[BLOCK_INTS]);
}; };
std::string sha1(const std::string &string); std::string sha1(const std::string &string);