lkml.org 
[lkml]   [2013]   [Nov]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectAF_ALG buggy with sendfile
From
If I use sendfile() to send to a accept()ed AF_ALG socket set up for
"hash", I get the wrong
answer, if I read() and then write() I get the right answer. None of
the system calls return an error.

test case attached.

--

---
Shawn Landden
+1 360 389 3001 (SMS preferred)

#include <sys/sendfile.h>
#include <sys/socket.h>
#include <linux/if_alg.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void)
{
int opfd;
int tfmfd;
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "hash",
.salg_name = "sha1"
};
char buf2[10000000];
char buf[20];
int i;
struct stat st;

tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0);

bind(tfmfd, (struct sockaddr *)&sa, sizeof(sa));

opfd = accept(tfmfd, NULL, 0);

int true = open("/bin/true", O_RDONLY);
fstat(true, &st);

sendfile(opfd, true, NULL, st.st_size);
read(opfd, &buf, 20);

for (i = 0; i < 20; i++) {
printf("%02x", (unsigned char)buf[i]);
}
printf("\n");

lseek(true, 0, SEEK_SET);
read(true, &buf2, st.st_size);
write(opfd, &buf2, st.st_size);
read(opfd, &buf, 20);

for (i = 0; i < 20; i++) {
printf("%02x", (unsigned char)buf[i]);
}
printf("\n");

close(opfd);
close(tfmfd);

return 0;
}

\
 
 \ /
  Last update: 2013-11-24 18:41    [W:0.160 / U:0.664 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site