Skip to content

Commit ca033a3

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 5739711 commit ca033a3

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

+428
-399
lines changed

doc/doc-docbook/spec.xfpt

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

3240832408

3240932409
.vitem "&*BOOL&~header_testname(header_line&~*hdr,&~uschar&~*name,&~&&&
32410-
int&~length,&~BOOL&~notdel)*&"
32410+
size_t&~length,&~BOOL&~notdel)*&"
3241132411
This function tests whether the given header has the given name. It is not just
3241232412
a string comparison, because white space is permitted between the name and the
3241332413
colon. If the &%notdel%& argument is true, a false return is forced for all
3241432414
&"deleted"& headers; otherwise they are not treated specially. For example:
3241532415
.code
3241632416
if (header_testname(h, US"X-Spam", 6, TRUE)) ...
3241732417
.endd
32418-
.vitem &*uschar&~*lss_b64encode(uschar&~*cleartext,&~int&~length)*&
32418+
.vitem &*uschar&~*lss_b64encode(uschar&~*cleartext,&~size_t&~length)*&
3241932419
.cindex "base64 encoding" "functions for &[local_scan()]& use"
3242032420
This function base64-encodes a string, which is passed by address and length.
3242132421
The text may contain bytes of any value, including zero. The result is passed
@@ -32505,7 +32505,7 @@ address.
3250532505
.cindex "RFC 2047"
3250632506
.vlist
3250732507
.vitem "&*uschar&~rfc2047_decode(uschar&~*string,&~BOOL&~lencheck,&&&
32508-
&~uschar&~*target,&~int&~zeroval,&~int&~*lenptr, &~&~uschar&~**error)*&"
32508+
&~uschar&~*target,&~int&~zeroval,&~size_t&~*lenptr, &~&~uschar&~**error)*&"
3250932509
This function decodes strings that are encoded according to RFC 2047. Typically
3251032510
these are the contents of header lines. First, each &"encoded word"& is decoded
3251132511
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
@@ -35,6 +35,14 @@ JH/07 Retire gnutls_require_mac et.al. These were nonfunctional since 4.80
3535
JH/08 Bug 1836: Fix crash in VRFY handling when handed an unqualified name
3636
(lacking @domain). Apply the same qualification processing as RCPT.
3737

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

3947
Exim version 4.87
4048
-----------------

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
@@ -185,7 +185,7 @@ typedef struct queue_item {
185185
struct dest_item *destinations;
186186
int input_time;
187187
int update_time;
188-
int size;
188+
size_t size;
189189
uschar *sender;
190190
uschar name[17];
191191
uschar seen;

src/exim_monitor/em_queue.c

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

764764
for (skp = &queue_skip; ; skp = &(sk->next))
765765
{
766-
int len_skip;
766+
size_t len_skip;
767767

768768
sk = *skp;
769769
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
@@ -1048,7 +1048,7 @@ static void
10481048
setup_header(const uschar *hstring)
10491049
{
10501050
const uschar *p, *q;
1051-
int hlen = Ustrlen(hstring);
1051+
size_t hlen = Ustrlen(hstring);
10521052

10531053
/* Ignore any leading newlines */
10541054
while (*hstring == '\n') hstring++, hlen--;
@@ -1159,8 +1159,8 @@ uschar *
11591159
fn_hdrs_added(void)
11601160
{
11611161
uschar * ret = NULL;
1162-
int size = 0;
1163-
int ptr = 0;
1162+
size_t size = 0;
1163+
size_t ptr = 0;
11641164
header_line * h = acl_added_headers;
11651165
uschar * s;
11661166
uschar * cp;
@@ -1259,7 +1259,7 @@ if (log_message != NULL && log_message != user_message)
12591259

12601260
if (logged == NULL)
12611261
{
1262-
int length = Ustrlen(text) + 1;
1262+
size_t length = Ustrlen(text) + 1;
12631263
log_write(0, LOG_MAIN, "%s", text);
12641264
logged = store_malloc(sizeof(string_item) + length);
12651265
logged->text = (uschar *)logged + sizeof(string_item);
@@ -1651,7 +1651,7 @@ typedef struct {
16511651
int value;
16521652
unsigned where_allowed; /* bitmap */
16531653
BOOL no_options; /* Never has /option(s) following */
1654-
unsigned alt_opt_sep; /* >0 Non-/ option separator (custom parser) */
1654+
size_t alt_opt_sep; /* >0 Non-/ option separator (custom parser) */
16551655
} verify_type_t;
16561656
static verify_type_t verify_type_list[] = {
16571657
{ US"reverse_host_lookup", VERIFY_REV_HOST_LKUP, ~0, FALSE, 0 },
@@ -2340,7 +2340,7 @@ int mode = RATE_PER_WHAT;
23402340
int old_pool, rc;
23412341
tree_node **anchor, *t;
23422342
open_db dbblock, *dbm;
2343-
int dbdb_size;
2343+
size_t dbdb_size;
23442344
dbdata_ratelimit *dbd;
23452345
dbdata_ratelimit_unique *dbdb;
23462346
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)