Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16b0c48

Browse files
committed
oauth: Ensure unused socket registrations are removed
If Curl needs to switch the direction of a socket's registration (e.g.from CURL_POLL_IN to CURL_POLL_OUT), it expects the old registration tobe discarded. For epoll, this happened via EPOLL_CTL_MOD, but forkqueue, the old registration would remain if it was not explicitlyremoved by Curl.Explicitly remove the opposite-direction event during registrations. (Ifthat event doesn't exist, we'll just get an ENOENT, which will beignored by the same code that handles CURL_POLL_REMOVE.) A fewassertions are also added to strengthen the relationship between thenumber of events added, the number of events pulled off the queue, andthe lengths of the kevent arrays.Reviewed-by: Thomas Munro <thomas.munro@gmail.com>Backpatch-through: 18Discussion:https://postgr.es/m/CAOYmi+nDZxJHaWj9_jRSyf8uMToCADAmOfJEggsKW-kY7aUwHA@mail.gmail.com
1 parentff181d1 commit16b0c48

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

‎src/interfaces/libpq-oauth/oauth-curl.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,22 +1291,31 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
12911291

12921292
return0;
12931293
#elif defined(HAVE_SYS_EVENT_H)
1294-
structkeventev[2]= {0};
1294+
structkeventev[2];
12951295
structkeventev_out[2];
12961296
structtimespectimeout= {0};
12971297
intnev=0;
12981298
intres;
12991299

1300+
/*
1301+
* We don't know which of the events is currently registered, perhaps
1302+
* both, so we always try to remove unneeded events. This means we need to
1303+
* tolerate ENOENT below.
1304+
*/
13001305
switch (what)
13011306
{
13021307
caseCURL_POLL_IN:
13031308
EV_SET(&ev[nev],socket,EVFILT_READ,EV_ADD |EV_RECEIPT,0,0,0);
13041309
nev++;
1310+
EV_SET(&ev[nev],socket,EVFILT_WRITE,EV_DELETE |EV_RECEIPT,0,0,0);
1311+
nev++;
13051312
break;
13061313

13071314
caseCURL_POLL_OUT:
13081315
EV_SET(&ev[nev],socket,EVFILT_WRITE,EV_ADD |EV_RECEIPT,0,0,0);
13091316
nev++;
1317+
EV_SET(&ev[nev],socket,EVFILT_READ,EV_DELETE |EV_RECEIPT,0,0,0);
1318+
nev++;
13101319
break;
13111320

13121321
caseCURL_POLL_INOUT:
@@ -1317,12 +1326,6 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
13171326
break;
13181327

13191328
caseCURL_POLL_REMOVE:
1320-
1321-
/*
1322-
* We don't know which of these is currently registered, perhaps
1323-
* both, so we try to remove both. This means we need to tolerate
1324-
* ENOENT below.
1325-
*/
13261329
EV_SET(&ev[nev],socket,EVFILT_READ,EV_DELETE |EV_RECEIPT,0,0,0);
13271330
nev++;
13281331
EV_SET(&ev[nev],socket,EVFILT_WRITE,EV_DELETE |EV_RECEIPT,0,0,0);
@@ -1334,7 +1337,10 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
13341337
return-1;
13351338
}
13361339

1337-
res=kevent(actx->mux,ev,nev,ev_out,lengthof(ev_out),&timeout);
1340+
Assert(nev <=lengthof(ev));
1341+
Assert(nev <=lengthof(ev_out));
1342+
1343+
res=kevent(actx->mux,ev,nev,ev_out,nev,&timeout);
13381344
if (res<0)
13391345
{
13401346
actx_error(actx,"could not modify kqueue: %m");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp