Skip to content

Commit

Permalink
bug-fix: fix invalid file descriptor check
Browse files Browse the repository at this point in the history
Some functions validated file descriptor to be greater 0.
If a process is started without stdin, stdout and stderr
the first file descriptor allocated by the process will be 0.
This also will be the case if the above mentioned file descriptors
will be closed on purpose.
As 0 is a valid fd, some methods had to be changed to reflect this.

Signed-off-by: Alexander Mohr <[email protected]>
  • Loading branch information
Alexander Mohr committed Dec 17, 2020
1 parent b748545 commit 5a73b99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit 5a73b99

Please sign in to comment.