~ubuntu-branches/ubuntu/vivid/musl/vivid

« back to all changes in this revision

Viewing changes to src/network/socketpair.c

  • Committer: Package Import Robot
  • Author(s): Kevin Bortis
  • Date: 2014-05-26 22:45:52 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20140526224552-qrtsct934q29xo0x
Tags: 1.1.4-1
* Import upstream version 1.1.4. (Closes: #754758)
* Fixes possible stack-based buffer overflow CVE-2014-3484 (Closes: #750815) 
* Includes fix for build regression on armhf and armel

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <sys/socket.h>
 
2
#include <fcntl.h>
 
3
#include <errno.h>
2
4
#include "syscall.h"
3
5
 
4
6
int socketpair(int domain, int type, int protocol, int fd[2])
5
7
{
6
 
        return socketcall(socketpair, domain, type, protocol, fd, 0, 0);
 
8
        int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0);
 
9
        if (r<0 && (errno==EINVAL || errno==EPROTONOSUPPORT)
 
10
            && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) {
 
11
                r = socketcall(socketpair, domain,
 
12
                        type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK),
 
13
                        protocol, fd, 0, 0);
 
14
                if (r < 0) return r;
 
15
                if (type & SOCK_CLOEXEC) {
 
16
                        __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC);
 
17
                        __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC);
 
18
                }
 
19
                if (type & SOCK_NONBLOCK) {
 
20
                        __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK);
 
21
                        __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK);
 
22
                }
 
23
        }
 
24
        return r;
7
25
}