mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Handle null state, don't read/write on error
Need to guard against errors when reading/writing probably, if there is an error, forgo those events. Guard against null state (and the byproduct, a segfault), check if the state is null before utilizing it.
This commit is contained in:
		| @@ -1702,19 +1702,22 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) { | |||||||
|         } else { |         } else { | ||||||
|             JanetStream *stream = p; |             JanetStream *stream = p; | ||||||
|             JanetListenerState *state = stream->state; |             JanetListenerState *state = stream->state; | ||||||
|  |             if (NULL != state) { | ||||||
|                 state->event = events + i; |                 state->event = events + i; | ||||||
|                 JanetAsyncStatus statuses[4]; |                 JanetAsyncStatus statuses[4]; | ||||||
|                 for (int i = 0; i < 4; i++) |                 for (int i = 0; i < 4; i++) | ||||||
|                     statuses[i] = JANET_ASYNC_STATUS_NOT_DONE; |                     statuses[i] = JANET_ASYNC_STATUS_NOT_DONE; | ||||||
|  |  | ||||||
|  |                 if (!(events[i].flags & EV_ERROR)) { | ||||||
|                     if (events[i].filter == EVFILT_WRITE) |                     if (events[i].filter == EVFILT_WRITE) | ||||||
|                         statuses[0] = state->machine(state, JANET_ASYNC_EVENT_WRITE); |                         statuses[0] = state->machine(state, JANET_ASYNC_EVENT_WRITE); | ||||||
|                     if (events[i].filter == EVFILT_READ) |                     if (events[i].filter == EVFILT_READ) | ||||||
|                         statuses[1] = state->machine(state, JANET_ASYNC_EVENT_READ); |                         statuses[1] = state->machine(state, JANET_ASYNC_EVENT_READ); | ||||||
|             if (events[i].flags & EV_ERROR) |  | ||||||
|                 statuses[2] = state->machine(state, JANET_ASYNC_EVENT_ERR); |  | ||||||
|                     if ((events[i].flags & EV_EOF) && !(events[i].data > 0)) |                     if ((events[i].flags & EV_EOF) && !(events[i].data > 0)) | ||||||
|                         statuses[3] = state->machine(state, JANET_ASYNC_EVENT_HUP); |                         statuses[3] = state->machine(state, JANET_ASYNC_EVENT_HUP); | ||||||
|  |                 } else { | ||||||
|  |                     statuses[2] = state->machine(state, JANET_ASYNC_EVENT_ERR); | ||||||
|  |                 } | ||||||
|                 if(statuses[0] == JANET_ASYNC_STATUS_DONE || |                 if(statuses[0] == JANET_ASYNC_STATUS_DONE || | ||||||
|                    statuses[1] == JANET_ASYNC_STATUS_DONE || |                    statuses[1] == JANET_ASYNC_STATUS_DONE || | ||||||
|                    statuses[2] == JANET_ASYNC_STATUS_DONE || |                    statuses[2] == JANET_ASYNC_STATUS_DONE || | ||||||
| @@ -1723,6 +1726,7 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| void janet_ev_init(void) { | void janet_ev_init(void) { | ||||||
|     janet_ev_init_common(); |     janet_ev_init_common(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 llmII
					llmII