Skip to content

Commit

Permalink
#430 fix some issues with reading/writing from/to socket
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Mar 1, 2020
1 parent ecf4097 commit 844432c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

## [2.4.1] - 2020-03-01
### Changed
- Fixed a crash that could occur when reading from a socket (EBADF) or writing to a socket (SIGPIPE) [#430](https://github.com/koekeishiya/yabai/issues/430)

## [2.4.0] - 2020-03-01
### Added
- Support exclusion for command arguments of type REGEX [#173](https://github.com/koekeishiya/yabai/issues/173)
Expand Down Expand Up @@ -196,7 +200,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added
- First official release

[Unreleased]: https://github.com/koekeishiya/yabai/compare/v2.4.0...HEAD
[Unreleased]: https://github.com/koekeishiya/yabai/compare/v2.4.1...HEAD
[2.4.1]: https://github.com/koekeishiya/yabai/compare/v2.4.0...v2.4.1
[2.4.0]: https://github.com/koekeishiya/yabai/compare/v2.3.0...v2.4.0
[2.3.0]: https://github.com/koekeishiya/yabai/compare/v2.2.3...v2.3.0
[2.2.3]: https://github.com/koekeishiya/yabai/compare/v2.2.2...v2.2.3
Expand Down
16 changes: 10 additions & 6 deletions src/misc/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ char *socket_read(int sockfd, int *len)
char buffer[BUFSIZ];

while ((bytes_read = read(sockfd, buffer, sizeof(buffer)-1)) > 0) {
result = realloc(result, cursor+bytes_read+1);
char *temp = realloc(result, cursor+bytes_read+1);
if (!temp) goto err;

result = temp;
memcpy(result+cursor, buffer, bytes_read);
cursor += bytes_read;
}

if (bytes_read == -1) {
free(result);
result = NULL;
*len = 0;
} else {
if (result && bytes_read != -1) {
result[cursor] = '\0';
*len = cursor;
} else {
if (result) free(result);
err:
result = NULL;
*len = 0;
}

return result;
Expand Down
1 change: 1 addition & 0 deletions src/yabai.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ static inline void init_misc_settings(void)

NSApplicationLoad();
signal(SIGCHLD, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
CGSetLocalEventsSuppressionInterval(0.0f);
CGEnableEventStateCombining(false);
g_connection = SLSMainConnectionID();
Expand Down

0 comments on commit 844432c

Please sign in to comment.