aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRostislav Skudnov <rostislav@tuxera.com>2017-02-01 18:35:13 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2017-02-04 23:10:22 +0100
commit8762512fdb088acefb9f3ea5f7b1e1bf2d336ff3 (patch)
tree309e04746b4bcb6f2ad645b29f7fcecfbff339e5
parentc31b54fd81690b3df3898437f5865674d06e6577 (diff)
downloadbusybox-w32-8762512fdb088acefb9f3ea5f7b1e1bf2d336ff3.tar.gz
busybox-w32-8762512fdb088acefb9f3ea5f7b1e1bf2d336ff3.tar.bz2
busybox-w32-8762512fdb088acefb9f3ea5f7b1e1bf2d336ff3.zip
Replace int -> uint to avoid signed integer overflow
An example of such an error (should be compiled with DEBUG_SANITIZE): runtime error: left shift of 1 by 31 places cannot be represented in type 'int' Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/libarchive/decompress_bunzip2.c6
-rw-r--r--libbb/crc32.c2
-rw-r--r--libbb/getopt32.c4
-rw-r--r--libbb/pw_encrypt.c2
-rw-r--r--miscutils/rx.c2
5 files changed, 8 insertions, 8 deletions
diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c
index fe5953da2..4fb989c29 100644
--- a/archival/libarchive/decompress_bunzip2.c
+++ b/archival/libarchive/decompress_bunzip2.c
@@ -134,7 +134,7 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
134 134
135 /* Avoid 32-bit overflow (dump bit buffer to top of output) */ 135 /* Avoid 32-bit overflow (dump bit buffer to top of output) */
136 if (bit_count >= 24) { 136 if (bit_count >= 24) {
137 bits = bd->inbufBits & ((1 << bit_count) - 1); 137 bits = bd->inbufBits & ((1U << bit_count) - 1);
138 bits_wanted -= bit_count; 138 bits_wanted -= bit_count;
139 bits <<= bits_wanted; 139 bits <<= bits_wanted;
140 bit_count = 0; 140 bit_count = 0;
@@ -158,11 +158,11 @@ static int get_next_block(bunzip_data *bd)
158{ 158{
159 struct group_data *hufGroup; 159 struct group_data *hufGroup;
160 int dbufCount, dbufSize, groupCount, *base, *limit, selector, 160 int dbufCount, dbufSize, groupCount, *base, *limit, selector,
161 i, j, t, runPos, symCount, symTotal, nSelectors, byteCount[256]; 161 i, j, runPos, symCount, symTotal, nSelectors, byteCount[256];
162 int runCnt = runCnt; /* for compiler */ 162 int runCnt = runCnt; /* for compiler */
163 uint8_t uc, symToByte[256], mtfSymbol[256], *selectors; 163 uint8_t uc, symToByte[256], mtfSymbol[256], *selectors;
164 uint32_t *dbuf; 164 uint32_t *dbuf;
165 unsigned origPtr; 165 unsigned origPtr, t;
166 166
167 dbuf = bd->dbuf; 167 dbuf = bd->dbuf;
168 dbufSize = bd->dbufSize; 168 dbufSize = bd->dbufSize;
diff --git a/libbb/crc32.c b/libbb/crc32.c
index ac9836cc9..0711ca84e 100644
--- a/libbb/crc32.c
+++ b/libbb/crc32.c
@@ -24,7 +24,7 @@ uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian)
24{ 24{
25 uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320; 25 uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320;
26 uint32_t c; 26 uint32_t c;
27 int i, j; 27 unsigned i, j;
28 28
29 if (!crc_table) 29 if (!crc_table)
30 crc_table = xmalloc(256 * sizeof(uint32_t)); 30 crc_table = xmalloc(256 * sizeof(uint32_t));
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 15b6efc09..497fc016f 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -404,7 +404,7 @@ getopt32(char **argv, const char *applet_opts, ...)
404 if (c >= 32) 404 if (c >= 32)
405 break; 405 break;
406 on_off->opt_char = *s; 406 on_off->opt_char = *s;
407 on_off->switch_on = (1 << c); 407 on_off->switch_on = (1U << c);
408 if (*++s == ':') { 408 if (*++s == ':') {
409 on_off->optarg = va_arg(p, void **); 409 on_off->optarg = va_arg(p, void **);
410 if (s[1] == '+' || s[1] == '*') { 410 if (s[1] == '+' || s[1] == '*') {
@@ -454,7 +454,7 @@ getopt32(char **argv, const char *applet_opts, ...)
454 if (c >= 32) 454 if (c >= 32)
455 break; 455 break;
456 on_off->opt_char = l_o->val; 456 on_off->opt_char = l_o->val;
457 on_off->switch_on = (1 << c); 457 on_off->switch_on = (1U << c);
458 if (l_o->has_arg != no_argument) 458 if (l_o->has_arg != no_argument)
459 on_off->optarg = va_arg(p, void **); 459 on_off->optarg = va_arg(p, void **);
460 c++; 460 c++;
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c
index 4cdc2de76..fe06a8fe6 100644
--- a/libbb/pw_encrypt.c
+++ b/libbb/pw_encrypt.c
@@ -30,7 +30,7 @@ static int i64c(int i)
30int FAST_FUNC crypt_make_salt(char *p, int cnt /*, int x */) 30int FAST_FUNC crypt_make_salt(char *p, int cnt /*, int x */)
31{ 31{
32 /* was: x += ... */ 32 /* was: x += ... */
33 int x = getpid() + monotonic_us(); 33 unsigned x = getpid() + monotonic_us();
34 do { 34 do {
35 /* x = (x*1664525 + 1013904223) % 2^32 generator is lame 35 /* x = (x*1664525 + 1013904223) % 2^32 generator is lame
36 * (low-order bit is not "random", etc...), 36 * (low-order bit is not "random", etc...),
diff --git a/miscutils/rx.c b/miscutils/rx.c
index 36fc20a72..1f6f2825c 100644
--- a/miscutils/rx.c
+++ b/miscutils/rx.c
@@ -94,7 +94,7 @@ static int receive(/*int read_fd, */int file_fd)
94 int blockBegin; 94 int blockBegin;
95 int blockNo, blockNoOnesCompl; 95 int blockNo, blockNoOnesCompl;
96 int cksum_or_crc; 96 int cksum_or_crc;
97 int expected; 97 unsigned expected;
98 int i, j; 98 int i, j;
99 99
100 blockBegin = read_byte(timeout); 100 blockBegin = read_byte(timeout);