File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -255,6 +255,11 @@ int dns_dispatcher_register(struct dns_socket_dispatcher *ctx)
255255 entry -> pair = ctx ;
256256
257257 for (int i = 0 ; i < ctx -> fds_len ; i ++ ) {
258+ CHECKIF ((int )ctx -> fds [i ].fd >= (int )ARRAY_SIZE (dispatch_table )) {
259+ ret = - ERANGE ;
260+ goto out ;
261+ }
262+
258263 if (dispatch_table [ctx -> fds [i ].fd ].ctx == NULL ) {
259264 dispatch_table [ctx -> fds [i ].fd ].ctx = ctx ;
260265 }
@@ -287,6 +292,11 @@ int dns_dispatcher_register(struct dns_socket_dispatcher *ctx)
287292 ctx -> pair = NULL ;
288293
289294 for (int i = 0 ; i < ctx -> fds_len ; i ++ ) {
295+ if ((int )ctx -> fds [i ].fd >= (int )ARRAY_SIZE (dispatch_table )) {
296+ ret = - ERANGE ;
297+ goto out ;
298+ }
299+
290300 if (dispatch_table [ctx -> fds [i ].fd ].ctx == NULL ) {
291301 dispatch_table [ctx -> fds [i ].fd ].ctx = ctx ;
292302 }
@@ -308,17 +318,25 @@ int dns_dispatcher_register(struct dns_socket_dispatcher *ctx)
308318
309319int dns_dispatcher_unregister (struct dns_socket_dispatcher * ctx )
310320{
321+ int ret = 0 ;
322+
311323 k_mutex_lock (& lock , K_FOREVER );
312324
313325 (void )sys_slist_find_and_remove (& sockets , & ctx -> node );
314326
315327 for (int i = 0 ; i < ctx -> fds_len ; i ++ ) {
328+ CHECKIF ((int )ctx -> fds [i ].fd >= (int )ARRAY_SIZE (dispatch_table )) {
329+ ret = - ERANGE ;
330+ goto out ;
331+ }
332+
316333 dispatch_table [ctx -> fds [i ].fd ].ctx = NULL ;
317334 }
318335
336+ out :
319337 k_mutex_unlock (& lock );
320338
321- return 0 ;
339+ return ret ;
322340}
323341
324342void dns_dispatcher_init (void )
You can’t perform that action at this time.
0 commit comments