Unverified Commit fd8f8ac4 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

bugfix: lseek should return off_t

lseek was triggering a number overflow by converting long to integer on
its return value

Added specific lseek test
parent 8dace0ce
Loading
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -112,3 +112,15 @@ test path resolution:
  artifacts:
    paths:
     - "${LOG_PATH}"

test lseek:
  stage: test
  script:
    - mkdir -p "${LOG_PATH}"
    - ${INSTALL_PATH}/bin/gkfs_daemon --mount /tmp/mountdir --root /tmp/root &
    - sleep 4
    - LD_PRELOAD=${INSTALL_PATH}/lib/libgkfs_intercept.so ${TESTS_BUILD_PATH}/gkfs_test_lseek
  artifacts:
    paths:
     - "${LOG_PATH}"
+2 −2
Original line number Diff line number Diff line
@@ -33,9 +33,9 @@ int adafs_statvfs(struct statvfs* buf);

int adafs_statfs(struct statfs* buf);

off64_t adafs_lseek(int fd, off64_t offset, int whence);
off64_t adafs_lseek(unsigned int fd, off64_t offset, unsigned int whence);

off64_t adafs_lseek(std::shared_ptr<OpenFile> adafs_fd, off64_t offset, int whence);
off64_t adafs_lseek(std::shared_ptr<OpenFile> adafs_fd, off64_t offset, unsigned int whence);

int adafs_truncate(const std::string& path, off_t offset);

+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ int hook_unlinkat(int dirfd, const char * cpath, int flags);
int hook_symlinkat(const char * oldname, int newdfd, const char * newname);
int hook_access(const char* path, int mask);
int hook_faccessat(int dirfd, const char * cpath, int mode);
int hook_lseek(unsigned int fd, off_t offset, unsigned int whence);
off_t hook_lseek(unsigned int fd, off_t offset, unsigned int whence);
int hook_truncate(const char *path, long length);
int hook_ftruncate(unsigned int fd, unsigned long length);
int hook_dup(unsigned int fd);
+2 −2
Original line number Diff line number Diff line
@@ -251,11 +251,11 @@ int adafs_statvfs(struct statvfs* buf) {
    return 0;
}

off64_t adafs_lseek(int fd, off64_t offset, int whence) {
off_t adafs_lseek(unsigned int fd, off_t offset, unsigned int whence) {
    return adafs_lseek(CTX->file_map()->get(fd), offset, whence);
}

off64_t adafs_lseek(shared_ptr<OpenFile> adafs_fd, off64_t offset, int whence) {
off_t adafs_lseek(shared_ptr<OpenFile> adafs_fd, off_t offset, unsigned int whence) {
    switch (whence) {
        case SEEK_SET:
            CTX->log()->debug("{}() whence is SEEK_SET", __func__);
+1 −1
Original line number Diff line number Diff line
@@ -280,7 +280,7 @@ int hook_faccessat(int dirfd, const char * cpath, int mode) {
    }
}

int hook_lseek(unsigned int fd, off_t offset, unsigned int whence) {
off_t hook_lseek(unsigned int fd, off_t offset, unsigned int whence) {
    CTX->log()->trace("{}() called with fd {}, offset {}, whence {}", __func__, fd, offset, whence);
    if (CTX->file_map()->exist(fd)) {
        auto off_ret = adafs_lseek(fd, static_cast<off64_t>(offset), whence);
Loading