Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug-Fix for invalid file descriptor validation and missing timeout in unix socket poll #281

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/lib/dlt_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -4242,13 +4242,8 @@ DltReturnValue dlt_user_log_check_user_message(void)
nfd[0].events = POLLIN;
nfd[0].fd = fd;

#if defined DLT_LIB_USE_UNIX_SOCKET_IPC || defined DLT_LIB_USE_VSOCK_IPC
if (fd != DLT_FD_INIT) {
ret = poll(nfd, 1, -1);
#else /* DLT_LIB_USE_FIFO_IPC */
if (fd != DLT_FD_INIT && dlt_user.dlt_log_handle > 0) {
ret = poll(nfd, 1, DLT_USER_RECEIVE_NDELAY);
#endif
if (fd >= 0) {
ret = poll(nfd, 1, DLT_USER_RECEIVE_MDELAY);
if (ret) {
if (nfd[0].revents & (POLLHUP | POLLNVAL | POLLERR)) {
dlt_user.dlt_log_handle = DLT_FD_INIT;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/dlt_user_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
/* delay for housekeeper thread (nsec) while receiving messages*/
#define DLT_USER_RECEIVE_NDELAY (500 * 1000 * 1000)

/* timeout for poll operations in milliseconds*/
#define DLT_USER_RECEIVE_MDELAY (500)

/* Name of environment variable for local print mode */
#define DLT_USER_ENV_LOCAL_PRINT_MODE "DLT_LOCAL_PRINT_MODE"

Expand Down
4 changes: 2 additions & 2 deletions src/shared/dlt_offline_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ DltReturnValue dlt_offline_trace_write(DltOfflineTrace *trace,
int size3)
{

if (trace->ohandle <= 0)
if (trace->ohandle < 0)
return DLT_RETURN_ERROR;

/* check file size here */
Expand Down Expand Up @@ -440,7 +440,7 @@ DltReturnValue dlt_offline_trace_write(DltOfflineTrace *trace,
DltReturnValue dlt_offline_trace_free(DltOfflineTrace *trace)
{

if (trace->ohandle <= 0)
if (trace->ohandle < 0)
return DLT_RETURN_ERROR;

/* close last used log file */
Expand Down
9 changes: 7 additions & 2 deletions src/shared/dlt_user_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2
struct iovec iov[2];
uint32_t bytes_written;

if (handle <= 0)
if (handle < 0)
/* Invalid handle */
return DLT_RETURN_ERROR;

Expand All @@ -130,7 +130,7 @@ DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2
struct iovec iov[3];
uint32_t bytes_written;

if (handle <= 0)
if (handle < 0)
/* Invalid handle */
return DLT_RETURN_ERROR;

Expand All @@ -145,6 +145,11 @@ DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2

if (bytes_written != (len1 + len2 + len3)) {
switch (errno) {
case ETIMEDOUT:
{
return DLT_RETURN_PIPE_ERROR; /* ETIMEDOUT - connect timeout */
break;
}
case EBADF:
{
return DLT_RETURN_PIPE_ERROR; /* EBADF - handle not open */
Expand Down