Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always use the passed fd in generated saferead() and safewrite() functions #272

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
qmail-qmqpc: set the correct fd in the substdio structs
The "to" and "from" substdios are initialized with fd -1 because the socket is
dynamically allocated at runtime. That is why the passed fd in the saferead()
and safewrite() functions was ignored and the socket descriptor was always used.
Update the fd in the substdios once the socket is allocated and then use the
provided fd.
  • Loading branch information
DerDakon committed Apr 5, 2024
commit b5949c75816f5b706f967253466cd545f36bdadd
7 changes: 5 additions & 2 deletions qmail-qmqpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void die_format() { _exit(91); }
int lasterror = 55;
int qmqpfd;

GEN_SAFE_TIMEOUTREAD(saferead,60,qmqpfd,die_conn())
GEN_SAFE_TIMEOUTWRITE(safewrite,60,qmqpfd,die_conn())
GEN_SAFE_TIMEOUTREAD(saferead,60,fd,die_conn())
GEN_SAFE_TIMEOUTWRITE(safewrite,60,fd,die_conn())

char buf[1024];
substdio to = SUBSTDIO_FDBUF(safewrite,-1,buf,sizeof(buf));
Expand Down Expand Up @@ -98,6 +98,9 @@ char *server;
qmqpfd = socket(AF_INET,SOCK_STREAM,0);
if (qmqpfd == -1) die_socket();

to.fd = qmqpfd;
from.fd = qmqpfd;

if (timeoutconn(qmqpfd,&ip,PORT_QMQP,10) != 0) {
lasterror = 73;
if (errno == error_timeout) lasterror = 72;
Expand Down