Skip to content

Commit

Permalink
Constrain socket path buffer size (#1631)
Browse files Browse the repository at this point in the history
from 3Rafal/socket-path-size
  • Loading branch information
voodoos authored Jul 4, 2023
2 parents 5052aaf + bef7b7d commit 06fb0d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
==========
+ merlin binary
- Constrain socket path buffer size to avoid build warnings (#1631)
- Handle concurrent server start (#1622)
- Omit module prefixes for constructors and record fields in the
`construct` command (#1618). Prefixes are still produced when
Expand Down
12 changes: 9 additions & 3 deletions src/frontend/ocamlmerlin/ocamlmerlin.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ static void failwith(const char *msg)

#define PATHSZ (PATH_MAX+1)

/* On Linux, sun_path size is 108 bytes.
On macOS it's 104.
We use 102 buffer, as we later append './'
*/
#define SOCKSZ (102)

#define BEGIN_PROTECTCWD \
{ char previous_cwd[PATHSZ]; \
if (!getcwd(previous_cwd, PATHSZ)) previous_cwd[0] = '\0';
Expand Down Expand Up @@ -569,7 +575,7 @@ LPSTR retrieve_user_sid_string()

static void compute_socketname(char socketname[PATHSZ], char eventname[PATHSZ], const char merlin_path[PATHSZ])
#else
static void compute_socketname(char socketname[PATHSZ], struct stat *st)
static void compute_socketname(char socketname[SOCKSZ], struct stat *st)
#endif
{
#ifdef _WIN32
Expand All @@ -595,7 +601,7 @@ static void compute_socketname(char socketname[PATHSZ], struct stat *st)

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

static char
merlin_path[PATHSZ] = "<not computed yet>",
socketname[PATHSZ] = "<not computed yet>",
socketname[SOCKSZ] = "<not computed yet>",
eventname[PATHSZ] = "<not computed yet>";
static unsigned char argbuffer[262144];

Expand Down

0 comments on commit 06fb0d1

Please sign in to comment.