You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In such situation, v3.8.1+ assumes that fd is not a socket but a file descriptor,
while earlier versions always assumed fd to be a socket in first place.
In other words, v3.8.0 and earlier gave a socket precedence over a file descriptor with the same value,
while v3.8.1 and later give a file descriptor precedence over a socket with the same value.
The discussion at #266 already outlines possible fixes.
Code snippet to likely produce a socket vs. file descriptor conflict:
#include<io.h>
#include<stdio.h>
#include<WinSock2.h>intmain(int argc, constchar *argv[])
{
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
int sd = (int)socket(AF_INET, SOCK_STREAM, 0);
// Use up file descriptors until fopen() failsint fd = -1;
while (FILE* f = fopen(argv[0], "rb"))
fd = _fileno(f);
intptr_t sh = _get_osfhandle(sd);
intptr_t fh = _get_osfhandle(fd);
printf("The operating-system file handle associated with fd is %p\n", fh);
printf("The operating-system file handle associated with sd is %p\n", sh);
return0;
}
Employing _dup2() to achieve the same:
#include<io.h>
#include<stdio.h>
#include<WinSock2.h>intmain(int argc, constchar *argv[])
{
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
int sd = (int)socket(AF_INET, SOCK_STREAM, 0);
// Duplicate stdout descriptor to produce a collision with the socket_dup2(1, sd);
intptr_t sh = _get_osfhandle(sd);
printf("The operating-system file handle associated with sd is %p\n", sh);
return0;
}
The text was updated successfully, but these errors were encountered:
datadiode
added a commit
to datadiode/portable
that referenced
this issue
Jul 17, 2024
In such situation, v3.8.1+ assumes that fd is not a socket but a file descriptor,
while earlier versions always assumed fd to be a socket in first place.
In other words, v3.8.0 and earlier gave a socket precedence over a file descriptor with the same value,
while v3.8.1 and later give a file descriptor precedence over a socket with the same value.
The discussion at #266 already outlines possible fixes.
Code snippet to likely produce a socket vs. file descriptor conflict:
Employing _dup2() to achieve the same:
The text was updated successfully, but these errors were encountered: