Commit Graph

20 Commits

Author SHA1 Message Date
Jon Griffiths
a861d3c57f Revert variable signedness changes.
In the line:

    for (carry = bin[i], j = size - 1; (j > high) || carry; --j)

my analysis missed that the compare (j > high) is always true when
high is 0 and j wraps around. So although the loop does not store
through a negative 'j' offset, it does require j to become negative
in order to terminate the loop in that case. My apologies.
2016-04-10 02:22:01 +12:00
Jon Griffiths
5df7d3b19a b58enc: Make loop variables unsigned
size can only be positive (and non-zero) as it is set to a positive expr + 1.
high is initialised with size-1 which is never negative, and then set to j at
the end of each loop iteration. It therefore can only be negative if j can.
The heart of the loop assigns to buf[j] which is on the stack. If j can become
negative during the loop then this is clearly undefined behaviour.

Following the loop, high is unused and j is reset to 0 and only incremented.
Thus both variables can be declared unsigned, and sys/types.h removed since
there are no more ssize_t variables remaining. This removes the last two sign
compare warnings from this file.
2016-04-04 21:16:13 +12:00
Jon Griffiths
e77d2999fe b58enc: Make loop variables unsigned
zcount can only ever be positive as it starts from 0 and is incremented.
i can only be positive as it starts from zcount and is incremented. This
removes one of three sign compare warnings in this function.
2016-04-04 21:15:21 +12:00
Aaron Voisine
13dfa66514 fix for potential out-of-bounds memory access
if when counting leading zeros an invalid digit is encountered with it's high-bit set, the index into b58digits_map will be out-of-bounds
2015-02-27 12:21:24 -08:00
Luke Dashjr
b6adca8ebb Bugfix: Add missing <sys/types.h> include for ssize_t 2014-11-18 23:15:36 +00:00
Luke Dashjr
2c6b7916b6 Bugfix: Use signed types so that j can go negative without underflow
In some cases, j made it negative which made (j > high) true creating a segfault condition
2014-10-26 00:26:42 +00:00
Luke Dashjr
fa132f17c4 Address most LLVM warnings 2014-09-16 07:27:55 +00:00
Luke Dashjr
6d2d2c5f0e b58tobin: Simplify zeromask calculation (fixes bug encountered when compiling with LLVM) 2014-09-16 02:39:55 +00:00
Luke Dashjr
9f0f04769f Bugfix: b58tobin: Correct zeromask for multiple-of-four binary buffer sizes 2014-08-18 20:18:49 +00:00
Luke Dashjr
62645c5114 Avoid unsafe casting 2014-08-18 20:18:22 +00:00
Luke Dashjr
2880b80cbd Modify b58tobin to return canonical size 2014-08-18 15:50:06 +00:00
Luke Dashjr
88761e9e2c b58check: Check binsz is long enough for checksum 2014-08-18 14:51:58 +00:00
Luke Dashjr
79a608586d Bugfix: Avoid confusing digit-to-number and number-to-digit mappings 2014-08-17 16:25:35 +00:00
Luke Dashjr
b3034841db b58check_enc function and docs 2014-08-17 12:23:40 +00:00
Luke Dashjr
7ecd1102d0 b58enc: Allocate buf on the stack rather than heap 2014-08-17 12:04:10 +00:00
Luke Dashjr
a2853bb766 b58enc: Accept any kind of pointer for binary data 2014-08-17 12:03:54 +00:00
Huang Le
f55613ac56 b58enc function 2014-08-17 12:00:29 +00:00
Luke Dashjr
696869093e Accept const data for b58check 2014-08-17 11:52:33 +00:00
Luke Dashjr
195033316e Rename symbols for libbase58 2014-08-17 11:52:30 +00:00
Luke Dashjr
f703579360 Initial import of code from libblkmaker 2014-08-17 11:52:26 +00:00