Skip to content

Commit 06fb0d1

Browse files
authored
Constrain socket path buffer size (#1631)
from 3Rafal/socket-path-size
2 parents 5052aaf + bef7b7d commit 06fb0d1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33
+ merlin binary
4+
- Constrain socket path buffer size to avoid build warnings (#1631)
45
- Handle concurrent server start (#1622)
56
- Omit module prefixes for constructors and record fields in the
67
`construct` command (#1618). Prefixes are still produced when

src/frontend/ocamlmerlin/ocamlmerlin.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ static void failwith(const char *msg)
9494

9595
#define PATHSZ (PATH_MAX+1)
9696

97+
/* On Linux, sun_path size is 108 bytes.
98+
On macOS it's 104.
99+
We use 102 buffer, as we later append './'
100+
*/
101+
#define SOCKSZ (102)
102+
97103
#define BEGIN_PROTECTCWD \
98104
{ char previous_cwd[PATHSZ]; \
99105
if (!getcwd(previous_cwd, PATHSZ)) previous_cwd[0] = '\0';
@@ -569,7 +575,7 @@ LPSTR retrieve_user_sid_string()
569575

570576
static void compute_socketname(char socketname[PATHSZ], char eventname[PATHSZ], const char merlin_path[PATHSZ])
571577
#else
572-
static void compute_socketname(char socketname[PATHSZ], struct stat *st)
578+
static void compute_socketname(char socketname[SOCKSZ], struct stat *st)
573579
#endif
574580
{
575581
#ifdef _WIN32
@@ -595,7 +601,7 @@ static void compute_socketname(char socketname[PATHSZ], struct stat *st)
595601

596602
LocalFree(user_sid_string);
597603
#else
598-
snprintf(socketname, PATHSZ,
604+
snprintf(socketname, SOCKSZ,
599605
"ocamlmerlin_%llu_%llu_%llu.socket",
600606
(unsigned long long)getuid(),
601607
(unsigned long long)st->st_dev,
@@ -607,7 +613,7 @@ static void compute_socketname(char socketname[PATHSZ], struct stat *st)
607613

608614
static char
609615
merlin_path[PATHSZ] = "<not computed yet>",
610-
socketname[PATHSZ] = "<not computed yet>",
616+
socketname[SOCKSZ] = "<not computed yet>",
611617
eventname[PATHSZ] = "<not computed yet>";
612618
static unsigned char argbuffer[262144];
613619

0 commit comments

Comments
 (0)