|
1 | 1 | /* |
2 | 2 | * libwebsockets - small server side websockets and web server implementation |
3 | 3 | * |
4 | | - * Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com> |
| 4 | + * Copyright (C) 2010 - 2025 Andy Green <andy@warmcat.com> |
5 | 5 | * |
6 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | 7 | * of this software and associated documentation files (the "Software"), to |
@@ -356,3 +356,37 @@ lwsac_detach(struct lwsac **head) |
356 | 356 | lwsl_debug("%s: head %p: refcount %d: Marked as detached\n", |
357 | 357 | __func__, *head, lachead->refcount); |
358 | 358 | } |
| 359 | + |
| 360 | +int |
| 361 | +_lwsac_assert_valid(struct lwsac *aco, void *check, size_t len, const char *name_ac, const char *name_blob, |
| 362 | + const char *filename, int line) |
| 363 | +{ |
| 364 | + struct lwsac *ac = aco; |
| 365 | + |
| 366 | + while (ac) { |
| 367 | + void *pos = (uint8_t *)&ac[1], |
| 368 | + *end = ((uint8_t *)ac) + ac->ofs; |
| 369 | + |
| 370 | + if (check >= pos && (void *)(((uint8_t *)check) + len) <= end) |
| 371 | + return 0; |
| 372 | + |
| 373 | + ac = ac->next; |
| 374 | + } |
| 375 | + |
| 376 | + ac = aco; |
| 377 | + |
| 378 | + while (ac) { |
| 379 | + void *pos = (uint8_t *)&ac[1], |
| 380 | + *end = ((uint8_t *)ac) + ac->ofs; |
| 381 | + |
| 382 | + lwsl_notice("%s: ac chunk %p -> %p\n", __func__, pos, end); |
| 383 | + |
| 384 | + ac = ac->next; |
| 385 | + } |
| 386 | + |
| 387 | + lwsl_err("%s:%d: %s (%p) len %u is not found inside lwsac %s (%p)\n", filename, line, name_blob, check, (unsigned int)len, name_ac, aco); |
| 388 | + assert(0); /* checked ptr is not in ac */ |
| 389 | + |
| 390 | + return 1; |
| 391 | +} |
| 392 | + |
0 commit comments