Skip to content

Commit

Permalink
Fix coverity-reported issues
Browse files Browse the repository at this point in the history
The errors in sesman/chansrv/chansrv_fuse.c appear to be false positives
caused by allocating xhandle->dir_handle, and then
casting xhandle to an integer in xfuse_handle_to_fuse_handle(), thus
hiding xhandle->dir_handle

For both occurrences, the logic has been simplified and made the same,
and a comment has been added to suppress the error.
  • Loading branch information
matt335672 committed Jan 13, 2025
1 parent d98c883 commit b047430
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
26 changes: 20 additions & 6 deletions sesman/chansrv/chansrv_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,16 +1169,26 @@ void xfuse_devredir_cb_enum_dir_done(struct state_dirscan *fip,
struct fuse_file_info *fi = &fip->fi;
XFUSE_HANDLE *xhandle = xfuse_handle_create();

if (xhandle == NULL
|| (xhandle->dir_handle = xfs_opendir(g_xfs, fip->pinum)) == NULL)
if (xhandle == NULL)
{
xfuse_handle_delete(xhandle);
fuse_reply_err(fip->req, ENOMEM);
}
else
{
fi->fh = xfuse_handle_to_fuse_handle(xhandle);
fuse_reply_open(fip->req, &fip->fi);
// Coverity gets confused by xfuse_handle_to_fuse_handle(), and
// sees the dir_handle leaked
//coverity[RESOURCE_LEAK:FALSE]
xhandle->dir_handle = xfs_opendir(g_xfs, fip->pinum);
if (xhandle->dir_handle == NULL)
{
xfuse_handle_delete(xhandle);
fuse_reply_err(fip->req, ENOMEM);
}
else
{
fi->fh = xfuse_handle_to_fuse_handle(xhandle);
fuse_reply_open(fip->req, &fip->fi);
}
}
}

Expand Down Expand Up @@ -2687,7 +2697,11 @@ static void xfuse_cb_opendir(fuse_req_t req, fuse_ino_t ino,
}
else
{
if ((xhandle->dir_handle = xfs_opendir(g_xfs, ino)) == NULL)
// Coverity gets confused by xfuse_handle_to_fuse_handle(), and
// sees the dir_handle leaked
//coverity[RESOURCE_LEAK:FALSE]
xhandle->dir_handle = xfs_opendir(g_xfs, ino);
if (xhandle->dir_handle == NULL)
{
xfuse_handle_delete(xhandle);
fuse_reply_err(req, ENOMEM);
Expand Down
42 changes: 24 additions & 18 deletions xrdpapi/xrdpapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ mysend(int sck, const void *adata, int bytes);
static int
myrecv(int sck, void *adata, int bytes);

static void
free_wts(struct wts_obj *wts)
{
if (wts != NULL)
{
if (wts->fd >= 0)
{
close(wts->fd);
}
free(wts);
}
}

/*
* Opens a handle to the server end of a specified virtual channel - this
* call is deprecated - use WTSVirtualChannelOpenEx() instead
Expand Down Expand Up @@ -116,15 +129,15 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName,
if (wts->display_num < 0)
{
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: fatal error; invalid DISPLAY");
free(wts);
free_wts(wts);
return NULL;
}

/* we use unix domain socket to communicate with chansrv */
if ((wts->fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: socket failed");
free(wts);
free_wts(wts);
return NULL;
}

Expand Down Expand Up @@ -155,7 +168,7 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName,
else
{
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: connect failed");
free(wts);
free_wts(wts);
return NULL;
}
}
Expand All @@ -164,7 +177,7 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName,
if (!can_send(wts->fd, 500, 1))
{
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: can_send failed");
free(wts);
free_wts(wts);
return NULL;
}

Expand All @@ -179,7 +192,7 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName,
if (connect_data == NULL)
{
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: calloc failed");
free(wts);
free_wts(wts);
return NULL;
}

Expand Down Expand Up @@ -208,31 +221,31 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName,
if (mysend(wts->fd, connect_data, bytes) != bytes)
{
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: mysend failed");
free(wts);
free_wts(wts);
return NULL;
}
LOG_DEVEL(LOG_LEVEL_DEBUG, "WTSVirtualChannelOpenEx: sent ok");

if (!can_recv(wts->fd, 500, 1))
{
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: can_recv failed");
free(wts);
free_wts(wts);
return NULL;
}

/* get response */
if (myrecv(wts->fd, connect_data, 4) != 4)
{
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: myrecv failed");
free(wts);
free_wts(wts);
return NULL;
}

if ((connect_data[0] != 0) || (connect_data[1] != 0) ||
(connect_data[2] != 0) || (connect_data[3] != 0))
{
LOG(LOG_LEVEL_ERROR, "WTSVirtualChannelOpenEx: connect_data not ok");
free(wts);
free_wts(wts);
return NULL;
}

Expand Down Expand Up @@ -406,21 +419,14 @@ WTSVirtualChannelRead(void *hChannelHandle, unsigned int TimeOut,
int
WTSVirtualChannelClose(void *hChannelHandle)
{
struct wts_obj *wts;

wts = (struct wts_obj *)hChannelHandle;
struct wts_obj *wts = (struct wts_obj *)hChannelHandle;

if (wts == NULL)
{
return 0;
}

if (wts->fd != -1)
{
close(wts->fd);
}

free(wts);
free_wts(wts);
return 1;
}

Expand Down

0 comments on commit b047430

Please sign in to comment.