Skip to content

Commit b1fa87e

Browse files
committed
Additonal safeguard : Prefer the use of unsigned pointer sizes for reprensenting length in core functions instead of signed int in order to prevent possibly existing overflows for crafted requests. This should also fix buffer overflows in the case someone run that software on a 16 bit x86 with an already supported ᴏꜱ.
1 parent 59f02c2 commit b1fa87e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+427
-398
lines changed

doc/doc-docbook/spec.xfpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32489,15 +32489,15 @@ match the specification, the function does nothing.
3248932489

3249032490

3249132491
.vitem "&*BOOL&~header_testname(header_line&~*hdr,&~uschar&~*name,&~&&&
32492-
int&~length,&~BOOL&~notdel)*&"
32492+
size_t&~length,&~BOOL&~notdel)*&"
3249332493
This function tests whether the given header has the given name. It is not just
3249432494
a string comparison, because white space is permitted between the name and the
3249532495
colon. If the &%notdel%& argument is true, a false return is forced for all
3249632496
&"deleted"& headers; otherwise they are not treated specially. For example:
3249732497
.code
3249832498
if (header_testname(h, US"X-Spam", 6, TRUE)) ...
3249932499
.endd
32500-
.vitem &*uschar&~*lss_b64encode(uschar&~*cleartext,&~int&~length)*&
32500+
.vitem &*uschar&~*lss_b64encode(uschar&~*cleartext,&~size_t&~length)*&
3250132501
.cindex "base64 encoding" "functions for &[local_scan()]& use"
3250232502
This function base64-encodes a string, which is passed by address and length.
3250332503
The text may contain bytes of any value, including zero. The result is passed
@@ -32587,7 +32587,7 @@ address.
3258732587
.cindex "RFC 2047"
3258832588
.vlist
3258932589
.vitem "&*uschar&~rfc2047_decode(uschar&~*string,&~BOOL&~lencheck,&&&
32590-
&~uschar&~*target,&~int&~zeroval,&~int&~*lenptr, &~&~uschar&~**error)*&"
32590+
&~uschar&~*target,&~int&~zeroval,&~size_t&~*lenptr, &~&~uschar&~**error)*&"
3259132591
This function decodes strings that are encoded according to RFC 2047. Typically
3259232592
these are the contents of header lines. First, each &"encoded word"& is decoded
3259332593
from the Q or B encoding into a byte-string. Then, if provided with the name of

doc/doc-txt/ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ JH/09 Bug 1804: Avoid writing msglog files when in -bh or -bhc mode.
4040
JH/10 Support ${sha256:} applied to a string (as well as the previous
4141
certificate).
4242

43+
LC/01 Prefer the use of size_t for variables representing sizes. Even if most
44+
strings in Exim are limited to 2¹⁵, This acts as a suplemental protection
45+
against overflows.
46+
Especially for 16 bits x86 where INT_MAX is already 2¹⁵ and pointers used
47+
in Unix programs are FAR (20 bits wide).
48+
In the meantime, this doesn’t impact any cases where negative length could
49+
have been used, as an error value.
50+
4351

4452
Exim version 4.87
4553
-----------------

src/exim_monitor/em_TextPop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ struct SearchAndReplace * search;
468468
text.firstPos = 0;
469469
text.format = FMT8BIT;
470470

471-
dir = (XawTextScanDirection)(int) ((caddr_t)XawToggleGetCurrent(search->left_toggle) -
471+
dir = (XawTextScanDirection)(size_t) ((caddr_t)XawToggleGetCurrent(search->left_toggle) -
472472
R_OFFSET);
473473

474474
pos = XawTextSearch( tw, dir, &text);

src/exim_monitor/em_hdr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ typedef struct queue_item {
186186
struct dest_item *destinations;
187187
int input_time;
188188
int update_time;
189-
int size;
189+
size_t size;
190190
uschar *sender;
191191
uschar name[17];
192192
uschar seen;

src/exim_monitor/em_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ while (p != NULL)
762762

763763
for (skp = &queue_skip; ; skp = &(sk->next))
764764
{
765-
int len_skip;
765+
size_t len_skip;
766766

767767
sk = *skp;
768768
while (sk != NULL && now >= sk->reveal)

src/exim_monitor/em_strip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void stripchartAction(Widget w, XtPointer client_data, XtPointer value)
6363
double *ptr = (double *)value;
6464
static int thresholds[] =
6565
{10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 0};
66-
int num = (int)client_data;
66+
size_t num = (size_t)client_data;
6767
int oldmax = 0;
6868
int newmax = 0;
6969
int newvalue = 0;

src/src/acl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ static void
10601060
setup_header(const uschar *hstring)
10611061
{
10621062
const uschar *p, *q;
1063-
int hlen = Ustrlen(hstring);
1063+
size_t hlen = Ustrlen(hstring);
10641064

10651065
/* Ignore any leading newlines */
10661066
while (*hstring == '\n') hstring++, hlen--;
@@ -1171,8 +1171,8 @@ uschar *
11711171
fn_hdrs_added(void)
11721172
{
11731173
uschar * ret = NULL;
1174-
int size = 0;
1175-
int ptr = 0;
1174+
size_t size = 0;
1175+
size_t ptr = 0;
11761176
header_line * h = acl_added_headers;
11771177
uschar * s;
11781178
uschar * cp;
@@ -1271,7 +1271,7 @@ if (log_message != NULL && log_message != user_message)
12711271

12721272
if (logged == NULL)
12731273
{
1274-
int length = Ustrlen(text) + 1;
1274+
size_t length = Ustrlen(text) + 1;
12751275
log_write(0, LOG_MAIN, "%s", text);
12761276
logged = store_malloc(sizeof(string_item) + length);
12771277
logged->text = (uschar *)logged + sizeof(string_item);
@@ -1663,7 +1663,7 @@ typedef struct {
16631663
int value;
16641664
unsigned where_allowed; /* bitmap */
16651665
BOOL no_options; /* Never has /option(s) following */
1666-
unsigned alt_opt_sep; /* >0 Non-/ option separator (custom parser) */
1666+
size_t alt_opt_sep; /* >0 Non-/ option separator (custom parser) */
16671667
} verify_type_t;
16681668
static verify_type_t verify_type_list[] = {
16691669
{ US"reverse_host_lookup", VERIFY_REV_HOST_LKUP, ~0, FALSE, 0 },
@@ -2352,7 +2352,7 @@ int mode = RATE_PER_WHAT;
23522352
int old_pool, rc;
23532353
tree_node **anchor, *t;
23542354
open_db dbblock, *dbm;
2355-
int dbdb_size;
2355+
size_t dbdb_size;
23562356
dbdata_ratelimit *dbd;
23572357
dbdata_ratelimit_unique *dbdb;
23582358
struct timeval tv;

src/src/auths/check_serv_cond.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ HDEBUG(D_auth)
7272
debug_printf(" $auth%d = %s\n", i + 1, auth_vars[i]);
7373
}
7474
for (i = 1; i <= expand_nmax; i++)
75-
debug_printf(" $%d = %.*s\n", i, expand_nlength[i], expand_nstring[i]);
75+
debug_printf(" $%u = %.*s\n", i, (unsigned int)expand_nlength[i], expand_nstring[i]);
7676
debug_print_string(ablock->server_debug_string); /* customized debug */
7777
}
7878

src/src/auths/cram_md5.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ compute_cram_md5(uschar *secret, uschar *challenge, uschar *digestptr)
9797
{
9898
md5 base;
9999
int i;
100-
int len = Ustrlen(secret);
100+
size_t len = Ustrlen(secret);
101101
uschar isecret[64];
102102
uschar osecret[64];
103103
uschar md5secret[16];
@@ -250,7 +250,7 @@ auth_cram_md5_client(
250250
smtp_outblock *outblock, /* output connection */
251251
int timeout, /* command timeout */
252252
uschar *buffer, /* for reading response */
253-
int buffsize) /* size of buffer */
253+
size_t buffsize) /* size of buffer */
254254
{
255255
auth_cram_md5_options_block *ob =
256256
(auth_cram_md5_options_block *)(ablock->options_block);

src/src/auths/cram_md5.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ extern auth_cram_md5_options_block auth_cram_md5_option_defaults;
2727
extern void auth_cram_md5_init(auth_instance *);
2828
extern int auth_cram_md5_server(auth_instance *, uschar *);
2929
extern int auth_cram_md5_client(auth_instance *, smtp_inblock *,
30-
smtp_outblock *, int, uschar *, int);
30+
smtp_outblock *, int, uschar *, size_t);
3131

3232
/* End of cram_md5.h */

0 commit comments

Comments
 (0)