mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 14:36:01 +03:00
Fix segfaults if NULL is passed to some functions and set errno.
This commit is contained in:
parent
817dc1c2a4
commit
0e0317c27e
1 changed files with 26 additions and 5 deletions
|
@ -24,6 +24,7 @@
|
|||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h> /* dlopen(), dlclose(), dlsym() ... */
|
||||
|
||||
|
@ -160,23 +161,28 @@ csync_vio_handle_t *csync_vio_creat(CSYNC *ctx, const char *uri, mode_t mode) {
|
|||
return h;
|
||||
}
|
||||
|
||||
int csync_vio_close(CSYNC *ctx, csync_vio_handle_t *handle) {
|
||||
int csync_vio_close(CSYNC *ctx, csync_vio_handle_t *fhandle) {
|
||||
int rc = -1;
|
||||
|
||||
if (fhandle == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(ctx->replica) {
|
||||
case REMOTE_REPLCIA:
|
||||
rc = ctx->module.method->close(handle->method_handle);
|
||||
rc = ctx->module.method->close(fhandle->method_handle);
|
||||
break;
|
||||
case LOCAL_REPLICA:
|
||||
rc = csync_vio_local_close(handle->method_handle);
|
||||
rc = csync_vio_local_close(fhandle->method_handle);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* handle->method_handle is free'd by the above close */
|
||||
SAFE_FREE(handle->uri);
|
||||
SAFE_FREE(handle);
|
||||
SAFE_FREE(fhandle->uri);
|
||||
SAFE_FREE(fhandle);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -184,6 +190,11 @@ int csync_vio_close(CSYNC *ctx, csync_vio_handle_t *handle) {
|
|||
ssize_t csync_vio_read(CSYNC *ctx, csync_vio_handle_t *fhandle, void *buf, size_t count) {
|
||||
ssize_t rs = 0;
|
||||
|
||||
if (fhandle == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(ctx->replica) {
|
||||
case REMOTE_REPLCIA:
|
||||
rs = ctx->module.method->read(fhandle->method_handle, buf, count);
|
||||
|
@ -201,6 +212,11 @@ ssize_t csync_vio_read(CSYNC *ctx, csync_vio_handle_t *fhandle, void *buf, size_
|
|||
ssize_t csync_vio_write(CSYNC *ctx, csync_vio_handle_t *fhandle, const void *buf, size_t count) {
|
||||
ssize_t rs = 0;
|
||||
|
||||
if (fhandle == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(ctx->replica) {
|
||||
case REMOTE_REPLCIA:
|
||||
rs = ctx->module.method->write(fhandle->method_handle, buf, count);
|
||||
|
@ -258,6 +274,11 @@ csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name) {
|
|||
int csync_vio_closedir(CSYNC *ctx, csync_vio_handle_t *dhandle) {
|
||||
int rc = -1;
|
||||
|
||||
if (dhandle == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(ctx->replica) {
|
||||
case REMOTE_REPLCIA:
|
||||
rc = ctx->module.method->closedir(dhandle->method_handle);
|
||||
|
|
Loading…
Reference in a new issue