Skip to content

Commit 3c42e08

Browse files
committed
Always use PATH_MAX for representing path size or maximum filename size
1 parent 4ddeeaf commit 3c42e08

File tree

10 files changed

+23
-22
lines changed

10 files changed

+23
-22
lines changed

doc/doc-txt/ChangeLog

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ LC/01 Prefer the use of size_t for variables representing sizes. Even if most
4545
In the meantime, this doesn’t impact any cases where negative length could
4646
have been used, as an error value.
4747

48+
LC/02 Some values representing maximum path size were hard coded.
49+
They are now replaced with the PATH_MAX macro.
50+
4851

4952
Exim version 4.87
5053
-----------------

src/exim_monitor/em_globals.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ BOOL log_datestamping = FALSE;
5959
int log_depth = 150;
6060
uschar *log_display_buffer;
6161
uschar *log_file = NULL;
62-
uschar log_file_open[256];
62+
uschar log_file_open[PATH_MAX];
6363
uschar *log_font = NULL;
6464
ino_t log_inode;
6565
long int log_position;

src/exim_monitor/em_hdr.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ purposes! */
3131
/* ANSI C includes */
3232

3333
#include <ctype.h>
34+
#include <limits.h>
3435
#include <setjmp.h>
3536
#include <signal.h>
3637
#include <stdarg.h>
@@ -252,7 +253,7 @@ extern BOOL log_datestamping; /* TRUE if logs are datestamped */
252253
extern int log_depth; /* depth of log tail window */
253254
extern uschar *log_display_buffer; /* to hold display text */
254255
extern uschar *log_file; /* supplied name of exim log file */
255-
extern uschar log_file_open[256]; /* actual open file */
256+
extern uschar log_file_open[PATH_MAX]; /* actual open file */
256257
extern uschar *log_font; /* font for log display */
257258
extern ino_t log_inode; /* the inode of the log file */
258259
extern long int log_position; /* position in log file */

src/exim_monitor/em_log.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ link count of zero on the currently open file. */
367367

368368
if (log_datestamping)
369369
{
370-
uschar log_file_wanted[256];
370+
uschar log_file_wanted[PATH_MAX];
371371
/* Do *not* use "%s" here, we need the %D datestamp in the log_file to
372372
* be expanded! */
373373
string_format(log_file_wanted, sizeof(log_file_wanted), CS log_file);

src/src/dcc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ dcc_process(uschar **listptr)
7272
uschar sendbuf[4096];
7373
uschar recvbuf[4096];
7474
uschar dcc_return_text[1024];
75-
uschar mbox_path[1024];
75+
uschar mbox_path[PATH_MAX];
7676
uschar message_subdir[2];
7777
struct header_line *dcchdr;
7878
uschar *dcc_acl_options;

src/src/lookups/dbmdb.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ rc = lf_check_file(-1, filename, S_IFREG, modemask, owners, owngroups,
5454
"dbm", errmsg);
5555
#else
5656
{
57-
uschar filebuffer[256];
58-
(void)sprintf(CS filebuffer, "%.250s.db", filename);
57+
uschar filebuffer[PATH_MAX];
58+
(void)sprintf(CS filebuffer, "%.*s.db", PATH_MAX-16, filename);
5959
rc = lf_check_file(-1, filebuffer, S_IFREG, modemask, owners, owngroups,
6060
"dbm", errmsg);
6161
if (rc < 0) /* stat() failed */
6262
{
63-
(void)sprintf(CS filebuffer, "%.250s.dir", filename);
63+
(void)sprintf(CS filebuffer, "%.*s.dir", PATH_MAX-16, filename);
6464
rc = lf_check_file(-1, filebuffer, S_IFREG, modemask, owners, owngroups,
6565
"dbm", errmsg);
6666
if (rc == 0) /* x.dir was OK */
6767
{
68-
(void)sprintf(CS filebuffer, "%.250s.pag", filename);
68+
(void)sprintf(CS filebuffer, "%.*s.pag", PATH_MAX-16, filename);
6969
rc = lf_check_file(-1, filebuffer, S_IFREG, modemask, owners, owngroups,
7070
"dbm", errmsg);
7171
}

src/src/mime.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ mime_get_decode_file(uschar *pname, uschar *fname)
194194
FILE *f = NULL;
195195
uschar *filename;
196196

197-
filename = (uschar *)malloc(2048);
197+
filename = (uschar *)malloc(PATH_MAX);
198198

199199
if (pname && fname)
200200
{
201-
(void)string_format(filename, 2048, "%s/%s", pname, fname);
201+
(void)string_format(filename, PATH_MAX, "%s/%s", pname, fname);
202202
f = modefopen(filename,"wb+",SPOOL_MODE);
203203
}
204204
else if (!pname)
@@ -212,7 +212,7 @@ else if (!fname)
212212
do
213213
{
214214
struct stat mystat;
215-
(void)string_format(filename, 2048,
215+
(void)string_format(filename, PATH_MAX,
216216
"%s/%s-%05u", pname, message_id, file_nr++);
217217
/* security break */
218218
if (file_nr >= 1024)
@@ -236,8 +236,8 @@ mime_decode(const uschar **listptr)
236236
int sep = 0;
237237
const uschar *list = *listptr;
238238
uschar *option;
239-
uschar option_buffer[1024];
240-
uschar decode_path[1024];
239+
uschar option_buffer[PATH_MAX];
240+
uschar decode_path[PATH_MAX];
241241
FILE *decode_file = NULL;
242242
long f_pos = 0;
243243
ssize_t size_counter = 0;
@@ -249,7 +249,7 @@ if (mime_stream == NULL)
249249
f_pos = ftell(mime_stream);
250250

251251
/* build default decode path (will exist since MBOX must be spooled up) */
252-
(void)string_format(decode_path,1024,"%s/scan/%s",spool_directory,message_id);
252+
(void)string_format(decode_path,PATH_MAX,"%s/scan/%s",spool_directory,message_id);
253253

254254
/* try to find 1st option */
255255
if ((option = string_nextinlist(&list, &sep,
@@ -783,15 +783,15 @@ while(1)
783783
(Ustrncmp(mime_content_type,"message/rfc822",14) == 0) )
784784
{
785785
const uschar *rfc822name = NULL;
786-
uschar filename[2048];
786+
uschar filename[PATH_MAX];
787787
int file_nr = 0;
788788
int result = 0;
789789

790790
/* must find first free sequential filename */
791791
do
792792
{
793793
struct stat mystat;
794-
(void)string_format(filename, 2048,
794+
(void)string_format(filename, PATH_MAX,
795795
"%s/scan/%s/__rfc822_%05u", spool_directory, message_id, file_nr++);
796796
/* security break */
797797
if (file_nr >= 128)

src/src/parse.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ for (;;)
13811381
if (Ustrncmp(s, ":include:", 9) == 0)
13821382
{
13831383
uschar *filebuf;
1384-
uschar filename[256];
1384+
uschar filename[PATH_MAX];
13851385
uschar *t = s+9;
13861386
int flen = len - 9;
13871387
int frc;

src/src/receive.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -1168,15 +1168,13 @@ run_mime_acl(uschar *acl, BOOL *smtp_yield_ptr, uschar **smtp_reply_ptr,
11681168
uschar **blackholed_by_ptr)
11691169
{
11701170
FILE *mbox_file;
1171-
uschar rfc822_file_path[2048];
1171+
uschar rfc822_file_path[PATH_MAX]={0};
11721172
unsigned long mbox_size;
11731173
header_line *my_headerlist;
11741174
uschar *user_msg, *log_msg;
11751175
int mime_part_count_buffer = -1;
11761176
int rc = OK;
11771177

1178-
memset(CS rfc822_file_path,0,2048);
1179-
11801178
/* check if it is a MIME message */
11811179
my_headerlist = header_list;
11821180
while (my_headerlist != NULL)
@@ -1238,7 +1236,7 @@ if (Ustrlen(rfc822_file_path) > 0)
12381236
/* check if we must check any message/rfc822 attachments */
12391237
if (rc == OK)
12401238
{
1241-
uschar temp_path[1024];
1239+
uschar temp_path[PATH_MAX];
12421240
struct dirent * entry;
12431241
DIR * tempdir;
12441242

test/src/client.c

-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ init_dh(void)
358358
int fd;
359359
int ret;
360360
gnutls_datum_t m;
361-
uschar filename[200];
362361
struct stat statbuf;
363362

364363
/* Initialize the data structures for holding the parameters */

0 commit comments

Comments
 (0)