s3: printing: Make printing_pread_data() update the offset paramter, if not passed...
authorJeremy Allison <jra@samba.org>
Wed, 2 May 2018 20:45:44 +0000 (13:45 -0700)
committerRalph Boehme <slow@samba.org>
Fri, 4 May 2018 20:34:24 +0000 (22:34 +0200)
As all callers pass -1 here, still not used.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/printing/nt_printing.c

index c5c6e07ec3bc09fdda2f565e624cd4f57f43e5ec..1a31199d6abb49fb759c4ae289cfb511b6d3cdcf 100644 (file)
@@ -318,16 +318,31 @@ const char *get_short_archi(const char *long_archi)
 
 static ssize_t printing_pread_data(files_struct *fsp,
                                char *buf,
-                               off_t *poff_unused,
+                               off_t *poff,
                                size_t byte_count)
 {
        size_t total=0;
+       off_t in_pos = *poff;
+
+       if (in_pos != (off_t)-1) {
+               in_pos = SMB_VFS_LSEEK(fsp, in_pos, SEEK_SET);
+               if (in_pos == (off_t)-1) {
+                       return -1;
+               }
+               /* Don't allow integer wrap on read. */
+               if (in_pos + byte_count < in_pos) {
+                       return -1;
+               }
+       }
 
        while (total < byte_count) {
                ssize_t ret = SMB_VFS_READ(fsp, buf + total,
                                        byte_count - total);
 
                if (ret == 0) {
+                       if (*poff != (off_t)-1) {
+                               *poff = in_pos;
+                       }
                        return total;
                }
                if (ret == -1) {
@@ -337,8 +352,12 @@ static ssize_t printing_pread_data(files_struct *fsp,
                                return -1;
                        }
                }
+               in_pos += ret;
                total += ret;
        }
+       if (*poff != (off_t)-1) {
+               *poff = in_pos;
+       }
        return (ssize_t)total;
 }