Skip to content

Commit 3c30af7

Browse files
authored
Fix stack-use-after-return (ruby#12105)
http://ci.rvm.jp/results/trunk_asan@ruby-sp1/5409001 ``` ================================================================= ==3263562==ERROR: AddressSanitizer: stack-use-after-return on address 0x735a8f190da8 at pc 0x735a6f58dabc bp 0x735a639ffd10 sp 0x735a639ffd08 READ of size 4 at 0x735a8f190da8 thread T211 ================================================================= ```
1 parent bc409f3 commit 3c30af7

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

ext/socket/ipsocket.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ struct fast_fallback_inetsock_arg
226226
int *families;
227227
int family_size;
228228
int additional_flags;
229-
int cancelled;
230229
rb_nativethread_lock_t *lock;
231230
struct fast_fallback_getaddrinfo_entry *getaddrinfo_entries[2];
232231
struct fast_fallback_getaddrinfo_shared *getaddrinfo_shared;
@@ -322,7 +321,7 @@ cancel_fast_fallback(void *ptr)
322321

323322
rb_nativethread_lock_lock(arg->lock);
324323
{
325-
*arg->cancelled = true;
324+
arg->cancelled = true;
326325
char notification = SELECT_CANCELLED;
327326
if ((write(arg->notify, &notification, 1)) < 0) {
328327
rb_syserr_fail(errno, "write(2)");
@@ -649,8 +648,8 @@ init_fast_fallback_inetsock_internal(VALUE v)
649648
arg->getaddrinfo_shared->wait = hostname_resolution_waiter;
650649
arg->getaddrinfo_shared->connection_attempt_fds = arg->connection_attempt_fds;
651650
arg->getaddrinfo_shared->connection_attempt_fds_size = arg->connection_attempt_fds_size;
652-
arg->getaddrinfo_shared->cancelled = &arg->cancelled;
653-
wait_arg.cancelled = &arg->cancelled;
651+
arg->getaddrinfo_shared->cancelled = false;
652+
wait_arg.cancelled = false;
654653

655654
for (int i = 0; i < arg->family_size; i++) {
656655
arg->getaddrinfo_entries[i] = allocate_fast_fallback_getaddrinfo_entry();
@@ -944,7 +943,7 @@ init_fast_fallback_inetsock_internal(VALUE v)
944943
arg->getaddrinfo_shared
945944
);
946945
rb_thread_check_ints();
947-
if (errno == EINTR || arg->cancelled) break;
946+
if (errno == EINTR || arg->getaddrinfo_shared->cancelled) break;
948947

949948
status = wait_arg.status;
950949
syscall = "select(2)";
@@ -1272,7 +1271,6 @@ rsock_init_inetsock(VALUE self, VALUE remote_host, VALUE remote_serv, VALUE loca
12721271
fast_fallback_arg.hostp = hostp;
12731272
fast_fallback_arg.portp = portp;
12741273
fast_fallback_arg.additional_flags = additional_flags;
1275-
fast_fallback_arg.cancelled = false;
12761274

12771275
int resolving_families[resolving_family_size];
12781276
int resolving_family_index = 0;

ext/socket/raddrinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3093,7 +3093,7 @@ do_fast_fallback_getaddrinfo(void *ptr)
30933093
rb_nativethread_lock_lock(shared->lock);
30943094
{
30953095
entry->err = err;
3096-
if (*shared->cancelled) {
3096+
if (shared->cancelled) {
30973097
if (entry->ai) {
30983098
freeaddrinfo(entry->ai);
30993099
entry->ai = NULL;

ext/socket/rubysocket.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ char *port_str(VALUE port, char *pbuf, size_t pbuflen, int *flags_ptr);
429429
struct fast_fallback_getaddrinfo_shared
430430
{
431431
int wait, notify, refcount, connection_attempt_fds_size;
432-
int *connection_attempt_fds, *cancelled;
432+
int cancelled;
433+
int *connection_attempt_fds;
433434
char *node, *service;
434435
rb_nativethread_lock_t *lock;
435436
};

0 commit comments

Comments
 (0)