Skip to content

Commit 2707823

Browse files
committed
Always use PATH_MAX for representing path size or maximum filename size
1 parent 48f7ad2 commit 2707823

File tree

8 files changed

+22
-20
lines changed

8 files changed

+22
-20
lines changed

doc/doc-txt/ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ LC/01 Prefer the use of size_t for variables representing sizes. Even if most
4848
In the meantime, this doesn’t impact any cases where negative length could
4949
have been used, as an error value.
5050

51+
LC/02 Some values representing maximum path size were hard coded.
52+
They are now replaced with the PATH_MAX macro.
53+
5154

5255
Exim version 4.87
5356
-----------------

src/exim_monitor/em_globals.c

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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>
@@ -253,7 +254,7 @@ extern BOOL log_datestamping; /* TRUE if logs are datestamped */
253254
extern int log_depth; /* depth of log tail window */
254255
extern uschar *log_display_buffer; /* to hold display text */
255256
extern uschar *log_file; /* supplied name of exim log file */
256-
extern uschar log_file_open[256]; /* actual open file */
257+
extern uschar log_file_open[PATH_MAX]; /* actual open file */
257258
extern uschar *log_font; /* font for log display */
258259
extern ino_t log_inode; /* the inode of the log file */
259260
extern long int log_position; /* position in log file */

src/exim_monitor/em_log.c

Lines changed: 1 addition & 1 deletion
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/lookups/dbmdb.c

Lines changed: 4 additions & 4 deletions
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 4 deletions
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

0 commit comments

Comments
 (0)