diff options
author | Richard Sharpe <sharpe@samba.org> | 2001-03-01 19:21:57 +0000 |
---|---|---|
committer | Richard Sharpe <sharpe@samba.org> | 2001-03-01 19:21:57 +0000 |
commit | 1b476b12d914e57a1b46864d0e12c0ba054af949 (patch) | |
tree | f225cf9dba25a9a5c5381d37696cb3addd253b49 | |
parent | ff2616aaf90ceb744379a2c4a9f69edea6d720e2 (diff) | |
download | samba-1b476b12d914e57a1b46864d0e12c0ba054af949.tar.gz samba-1b476b12d914e57a1b46864d0e12c0ba054af949.tar.bz2 samba-1b476b12d914e57a1b46864d0e12c0ba054af949.zip |
Fix two problems identified by the test suite, one a major one
where I was indexing through a NULL pointer :-(
(This used to be commit 5f1ea70e110bd3b97a4c75b2fe0edef22847550b)
-rw-r--r-- | source3/libsmb/libsmbclient.c | 64 |
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; |