Bug 2432 - wrong structure used for sendfilev64() in lib/sendfile.c
wrong structure used for sendfilev64() in lib/sendfile.c
Status: RESOLVED WONTFIX
Product: Samba 3.0
Classification: Unclassified
Component: Build environment
3.0.11
Sparc Solaris
: P3 normal
: none
Assigned To: Samba Bugzilla Account
Samba QA Contact
:
Depends on: 2428
Blocks:
  Show dependency treegraph
 
Reported: 2005-03-09 07:27 UTC by Walter Haidinger
Modified: 2010-04-26 03:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Walter Haidinger 2005-03-09 07:27:11 UTC
In lib/sendfile.c, line 218,
   nwritten = sendfilev64(tofd, vec, sfvcnt, &xferred);
a 32-bit structure is used for the 64-bit call sendfilev64 (line 180): [*]
   struct sendfilevec vec[2];

gcc 3.4.2 under Solaris 9 then complains during build:
Compiling lib/sendfile.c
lib/sendfile.c: In function `sys_sendfile':
lib/sendfile.c:188: warning: cast from pointer to integer of different size

Line 188 reads:
   vec[0].sfv_off = (off_t)header->data;

Casting to off64_t fixes the size bug, the pointer to integer warning remains.
I have not digged into the sources far enough yet to provide a fix for this too. 

If forced to detect the off64_t datatype 
(see https://bugzilla.samba.org/show_bug.cgi?id=2428), the following patch 
adds the proper 64-bit datatype.
Please note that the patch below is only a PARTIAL FIX, i.e. the casting 
problem bug remains and there will be most probably other places
to change the off_t type to off64_t.

--- sendfile.c.orig     Wed Mar  9 12:27:04 2005
+++ sendfile.c  Wed Mar  9 13:21:20 2005
@@ -177,7 +177,11 @@
 {
        int sfvcnt;
        size_t total, xferred;
+#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) &&
defined(HAVE_SENDFILEV64)
+       struct sendfilevec64 vec[2];
+#else
        struct sendfilevec vec[2];
+#endif
        ssize_t hdr_len = 0;
 
        if (header) {
@@ -185,7 +189,11 @@
 
                vec[0].sfv_fd = SFV_FD_SELF;
                vec[0].sfv_flag = 0;
+#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) &&
defined(HAVE_SENDFILEV64)
+               vec[0].sfv_off = (off64_t)header->data;
+#else 
                vec[0].sfv_off = (off_t)header->data;
+#endif
                vec[0].sfv_len = hdr_len = header->length;
 
                vec[1].sfv_fd = fromfd;


Also, please note that some calculations with the return value of sendfilev64(),
nwritten, and the offset is done, so this might be a more serious problem!

Btw, the same bug exists in configure at line 37670 in the test for 
the solaris sendfilev64 support:
  struct sendfilevec vec[2];

Changing it to 
  struct sendfilevec64 vec[2];
makes conftest run without a warning.

Regards, Walter

[*] 
Notice the differnt types for stv_off in
/usr/include/sys/sendfile.h:
...
/*
 * Structure used by sendfilev()
 */
typedef struct sendfilevec {
        int             sfv_fd;
        uint_t          sfv_flag;
        off_t           sfv_off;
        size_t          sfv_len;
} sendfilevec_t;

#if     defined(_LARGEFILE64_SOURCE)
/*
 * For 32-bit apps accessing largefile offsets
 * using sendfilev64.
 */
typedef struct sendfilevec64 {
        int             sfv_fd;
        uint_t          sfv_flag;
        off64_t         sfv_off;
        size_t          sfv_len;
} sendfilevec64_t;
#endif /* _LARGEFILE64_SOURCE */
...
extern ssize_t sendfilev64(int, const struct sendfilevec64 *, int, size_t *);
Comment 1 Stefan Metzmacher 2010-04-26 03:18:07 UTC
If it's still broken in 3.5, please reopen.
3.0 isn't supported anymore.