Skip to content

Commit

Permalink
src/script/script.h: endian compatibility for PUSHDATA sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
laanwj committed Mar 6, 2015
1 parent 4f92773 commit 4e853aa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/script/script.h
Expand Up @@ -14,6 +14,7 @@
#include <string.h>
#include <string>
#include <vector>
#include "crypto/common.h"

static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes

Expand Down Expand Up @@ -416,14 +417,16 @@ class CScript : public std::vector<unsigned char>
else if (b.size() <= 0xffff)
{
insert(end(), OP_PUSHDATA2);
unsigned short nSize = b.size();
insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
uint8_t data[2];
WriteLE16(data, b.size());
insert(end(), data, data + sizeof(data));
}
else
{
insert(end(), OP_PUSHDATA4);
unsigned int nSize = b.size();
insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
uint8_t data[4];
WriteLE32(data, b.size());
insert(end(), data, data + sizeof(data));
}
insert(end(), b.begin(), b.end());
return *this;
Expand Down Expand Up @@ -496,15 +499,14 @@ class CScript : public std::vector<unsigned char>
{
if (end() - pc < 2)
return false;
nSize = 0;
memcpy(&nSize, &pc[0], 2);
nSize = ReadLE16(&pc[0]);
pc += 2;
}
else if (opcode == OP_PUSHDATA4)
{
if (end() - pc < 4)
return false;
memcpy(&nSize, &pc[0], 4);
nSize = ReadLE32(&pc[0]);
pc += 4;
}
if (end() - pc < 0 || (unsigned int)(end() - pc) < nSize)
Expand Down

0 comments on commit 4e853aa

Please sign in to comment.