Skip to content

Commit

Permalink
fix: check if Unix Domain socket file exists before listening. (#921)
Browse files Browse the repository at this point in the history
* docs: Update CHANGELOG.

* fix: Check if Unix Domain socket file exists before listening.

* Test
  • Loading branch information
zobo committed Jul 15, 2024
1 parent 5c37f12 commit f1dc59f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/phpDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ class PhpDebugSession extends vscode.DebugSession {
throw new Error('Cannot have port and socketPath set at the same time')
}
if (args.hostname?.toLowerCase()?.startsWith('unix://') === true) {
if (fs.existsSync(args.hostname.substring(7))) {
throw new Error(
`File ${args.hostname.substring(7)} exists and cannot be used for Unix Domain socket`
)
}
server.listen(args.hostname.substring(7))
} else if (args.hostname?.startsWith('\\\\') === true) {
server.listen(args.hostname)
Expand Down
10 changes: 10 additions & 0 deletions src/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ describe('PHP Debug Adapter', () => {
client.waitForEvent('terminated'),
])
})
;(process.platform === 'win32' ? it.skip : it)('should error on existing unix pipe', async () => {
await assert.isRejected(
client.launch({
program,
hostname: 'unix:///tmp',
runtimeArgs: ['-dxdebug.client_host=unix:///tmp'],
}),
/File .+ exists and cannot be used for Unix Domain socket/
)
})
})

describe('continuation commands', () => {
Expand Down

0 comments on commit f1dc59f

Please sign in to comment.