File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121
2222 - name : Run clang-tidy
2323 run : |
24- clang-tidy src/ctx.c --warnings-as-errors=* -- -std=c11 -Isrc
24+ clang-tidy src/ctx.c --warnings-as-errors=* --checks=-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling -- -std=c11 -Isrc
2525
2626 build :
2727 runs-on : ${{ matrix.os }}
Original file line number Diff line number Diff line change 11#define _DEFAULT_SOURCE
2+ #include <assert.h>
3+ #include <stdint.h>
24#include <stdlib.h>
35#include <string.h>
46#include <sys/mman.h>
@@ -25,10 +27,20 @@ cj_ctx *create_cj_ctx(void)
2527
2628void grow_cj_ctx (cj_ctx * ctx )
2729{
28- uint64_t half = ctx -> size ;
29- ctx -> size *= 2 ;
30- ctx -> mem = realloc (ctx -> mem , ctx -> size );
31- memset (ctx -> mem + half , 0 , half );
30+ if (!ctx )
31+ return ;
32+
33+ uint64_t old_size = ctx -> size ;
34+ uint64_t new_size = old_size * 2 ;
35+ if (new_size < old_size )
36+ return ;
37+ uint8_t * new_mem = realloc (ctx -> mem , new_size );
38+ if (!new_mem )
39+ return ;
40+
41+ ctx -> mem = new_mem ;
42+ memset (ctx -> mem + old_size , 0 , old_size );
43+ ctx -> size = new_size ;
3244}
3345
3446void destroy_cj_ctx (cj_ctx * ctx )
@@ -53,7 +65,9 @@ cj_fn create_cj_fn(cj_ctx *ctx)
5365 return NULL ;
5466 }
5567
56- memcpy (raw + sizeof (uint64_t ), ctx -> mem , code_size );
68+ assert (ctx -> mem );
69+ uint8_t * dest = raw + sizeof (uint64_t );
70+ memcpy (dest , ctx -> mem , code_size );
5771 * ((uint64_t * )raw ) = code_size ;
5872
5973 if (mprotect (raw , total_size , PROT_READ | PROT_EXEC ) != 0 )
You can’t perform that action at this time.
0 commit comments