Skip to content

Commit

Permalink
fix buffer overrun
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Dyer committed Aug 13, 2012
1 parent ff7ad66 commit 7b61255
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions utils/b64tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$

static void encodeblock(const unsigned char* in, ostream* os, int len) {
char out[4];
// cerr << len << endl;
out[0] = cb64[ in[0] >> 2 ];
out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
out[2] = (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '=');
out[1] = cb64[ ((in[0] & 0x03) << 4) | (len > 1 ? ((in[1] & 0xf0) >> 4) : static_cast<unsigned char>(0))];
out[2] = (len > 2 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '=');
out[3] = (len > 2 ? cb64[ in[2] & 0x3f ] : '=');
os->write(out, 4);
}
Expand Down

0 comments on commit 7b61255

Please sign in to comment.