Improve treatment of signature components

This commit is contained in:
seelabs
2015-09-26 20:15:20 -04:00
committed by Miguel Portilla
parent 8d37cd9169
commit 379110a8a2
2 changed files with 5 additions and 4 deletions

View File

@@ -98,7 +98,7 @@ public:
: m_skip (0)
{
// The format is: <02> <length of signature> <signature>
if ((sig[0] != 0x02) || (size < 3))
if ((size < 3) || (sig[0] != 0x02))
return;
std::size_t const len (sig[1]);

View File

@@ -271,12 +271,13 @@ unsigned long RFC1751::extract (char const* s, int start, int length)
assert (length >= 0);
assert (start + length <= 66);
int const shiftR = 24 - (length + (start % 8));
cl = s[start / 8]; // get components
cc = s[start / 8 + 1];
cr = s[start / 8 + 2];
cc = (shiftR < 16) ? s[start / 8 + 1] : 0;
cr = (shiftR < 8) ? s[start / 8 + 2] : 0;
x = ((long) (cl << 8 | cc) << 8 | cr) ; // Put bits together
x = x >> (24 - (length + (start % 8))); // Right justify number
x = x >> shiftR; // Right justify number
x = ( x & (0xffff >> (16 - length) ) ); // Trim extra bits.
return x;