s3:vfs_tsmsm: fix potential segfault (freeing uninitialized buffer)
[metze/samba/wip.git] / source3 / modules / vfs_tsmsm.c
index 7dc8b38bb7dbeee758d5c7b09b583462f6f907cd..6fb1d1d2d46715a471e58b77511be9cd61eeef8f 100644 (file)
@@ -148,8 +148,8 @@ static bool tsmsm_is_offline(struct vfs_handle_struct *handle,
        dm_attrname_t dmname;
        int ret, lerrno;
        bool offline;
-       char *buf;
-       int buflen;
+       char *buf = NULL;
+       size_t buflen;
 
         /* if the file has more than FILE_IS_ONLINE_RATIO of blocks available,
           then assume it is not offline (it may not be 100%, as it could be sparse) */
@@ -200,9 +200,9 @@ static bool tsmsm_is_offline(struct vfs_handle_struct *handle,
                goto done;
        }
 
-       lerrno = 0;
-
        do {
+               lerrno = 0;
+
                ret = dm_get_dmattr(*dmsession_id, dmhandle, dmhandle_len, 
                                    DM_NO_TOKEN, &dmname, buflen, buf, &rlen);
                if (ret == -1 && errno == EINVAL) {
@@ -279,10 +279,13 @@ static ssize_t tsmsm_aio_return(struct vfs_handle_struct *handle, struct files_s
 static ssize_t tsmsm_sendfile(vfs_handle_struct *handle, int tofd, files_struct *fsp, const DATA_BLOB *hdr,
                              SMB_OFF_T offset, size_t n)
 {
-       bool file_online = tsmsm_aio_force(handle, fsp);
+       bool file_offline = tsmsm_aio_force(handle, fsp);
 
-       if(!file_online) 
-           return ENOSYS;
+       if (file_offline) {
+               DEBUG(10,("tsmsm_sendfile on offline file - rejecting\n"));
+               errno = ENOSYS;
+               return -1;
+       }
            
        return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
 }
@@ -333,7 +336,7 @@ static int tsmsm_set_offline(struct vfs_handle_struct *handle,
 
        if (tsmd->hsmscript == NULL) {
                /* no script enabled */
-               DEBUG(1, ("tsmsm_set_offline: No tsmsm:hsmscript configured\n"));
+               DEBUG(1, ("tsmsm_set_offline: No 'tsmsm:hsm script' configured\n"));
                return 0;
        }