summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/libsmbclient.c64
1 files changed, 61 insertions, 3 deletions
diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c
index ce0b32a5ca..29f2d807ba 100644
--- a/source3/libsmb/libsmbclient.c
+++ b/source3/libsmb/libsmbclient.c
@@ -667,9 +667,18 @@ ssize_t smbc_read(int fd, void *buf, size_t count)
}
+ /* Check that the buffer exists ... */
+
+ if (buf == NULL) {
+
+ errno = EINVAL;
+ return -1;
+
+ }
+
fe = smbc_file_table[fd - smbc_start_fd];
- if (!fe->file) {
+ if (!fe || !fe->file) {
errno = EBADF;
return -1;
@@ -727,6 +736,13 @@ ssize_t smbc_write(int fd, void *buf, size_t count)
fe = smbc_file_table[fd - smbc_start_fd];
+ if (!fe || !fe->file) {
+
+ errno = EBADF;
+ return -1;
+
+ }
+
ret = cli_write(&fe->srv->cli, fe->cli_fd, 0, buf, fe->offset, count);
if (ret <= 0) {
@@ -765,6 +781,13 @@ int smbc_close(int fd)
fe = smbc_file_table[fd - smbc_start_fd];
+ if (!fe) {
+
+ errno = EBADF;
+ return -1;
+
+ }
+
if (!fe->file) {
return smbc_closedir(fd);
@@ -967,6 +990,13 @@ off_t smbc_lseek(int fd, off_t offset, int whence)
fe = smbc_file_table[fd - smbc_start_fd];
+ if (!fe) {
+
+ errno = EBADF;
+ return -1;
+
+ }
+
if (!fe->file) {
return smbc_lseekdir(fd, offset, whence);
@@ -1208,6 +1238,13 @@ int smbc_fstat(int fd, struct stat *st)
fe = smbc_file_table[fd - smbc_start_fd];
+ if (!fe) {
+
+ errno = EBADF;
+ return -1;
+
+ }
+
if (!fe->file) {
return smbc_fstatdir(fd, st);
@@ -1620,7 +1657,7 @@ int smbc_opendir(const char *fname)
}
else {
- errno = EINVAL;
+ errno = ENODEV; /* Neither the workgroup nor server exists */
if (smbc_file_table[slot]) free(smbc_file_table[slot]);
smbc_file_table[slot] = NULL;
return -1;
@@ -1695,7 +1732,7 @@ int smbc_closedir(int fd)
if (!fe) {
- errno = ENOENT; /* FIXME: Is this correct */
+ errno = EBADF;
return -1;
}
@@ -1739,6 +1776,13 @@ struct smbc_dirent *smbc_readdir(unsigned int fd)
fe = smbc_file_table[fd - smbc_start_fd];
+ if (!fe) {
+
+ errno = EBADF;
+ return NULL;
+
+ }
+
if (fe->file != False) { /* FIXME, should be dir, perhaps */
errno = ENOTDIR;
@@ -1802,6 +1846,13 @@ int smbc_getdents(unsigned int fd, struct smbc_dirent *dirp, int count)
fe = smbc_file_table[fd - smbc_start_fd];
+ if (!fe) {
+
+ errno = EBADF;
+ return -1;
+
+ }
+
if (fe->file != False) { /* FIXME, should be dir, perhaps */
errno = ENOTDIR;
@@ -2027,6 +2078,13 @@ off_t smbc_telldir(int fd)
fe = smbc_file_table[fd - smbc_start_fd];
+ if (!fe) {
+
+ errno = EBADF;
+ return -1;
+
+ }
+
if (fe->file != False) { /* FIXME, should be dir, perhaps */
errno = ENOTDIR;