MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix segfault on freed filename

+22 -8
+1
include/http/http1_writer.h
··· 26 26 27 27 const char *ant_http1_default_status_text(int status); 28 28 char *ant_http1_buffer_take(ant_http1_buffer_t *buf, size_t *len_out); 29 + char *ant_http1_buffer_take_cstr(ant_http1_buffer_t *buf); 29 30 30 31 bool ant_http1_write_basic_response( 31 32 ant_http1_buffer_t *buf,
+6 -6
src/http/http1_parser.c
··· 30 30 ant_http_header_t *hdr = calloc(1, sizeof(*hdr)); 31 31 if (!hdr) return false; 32 32 33 - hdr->name = ant_http1_buffer_take(&ctx->header_field, NULL); 34 - hdr->value = ant_http1_buffer_take(&ctx->header_value, NULL); 33 + hdr->name = ant_http1_buffer_take_cstr(&ctx->header_field); 34 + hdr->value = ant_http1_buffer_take_cstr(&ctx->header_value); 35 35 if (!hdr->name || !hdr->value) { 36 36 free(hdr->name); 37 37 free(hdr->value); ··· 153 153 if (out->consumed_len == 0) ctx.req.consumed_len = len; 154 154 else ctx.req.consumed_len = out->consumed_len; 155 155 156 - ctx.req.method = ant_http1_buffer_take(&ctx.method, NULL); 157 - ctx.req.target = ant_http1_buffer_take(&ctx.target, NULL); 156 + ctx.req.method = ant_http1_buffer_take_cstr(&ctx.method); 157 + ctx.req.target = ant_http1_buffer_take_cstr(&ctx.target); 158 158 ctx.req.body = (uint8_t *)ant_http1_buffer_take(&ctx.body, &ctx.req.body_len); 159 159 if (!ctx.req.method || !ctx.req.target) { 160 160 parser_ctx_free(&ctx); ··· 263 263 if (consumed_out && *consumed_out == 0) *consumed_out = len; 264 264 cp->ctx.req.consumed_len = consumed_out ? *consumed_out : len; 265 265 266 - cp->ctx.req.method = ant_http1_buffer_take(&cp->ctx.method, NULL); 267 - cp->ctx.req.target = ant_http1_buffer_take(&cp->ctx.target, NULL); 266 + cp->ctx.req.method = ant_http1_buffer_take_cstr(&cp->ctx.method); 267 + cp->ctx.req.target = ant_http1_buffer_take_cstr(&cp->ctx.target); 268 268 cp->ctx.req.body = (uint8_t *)ant_http1_buffer_take(&cp->ctx.body, &cp->ctx.req.body_len); 269 269 270 270 if (!cp->ctx.req.method || !cp->ctx.req.target)
+7
src/http/http1_writer.c
··· 96 96 return data; 97 97 } 98 98 99 + char *ant_http1_buffer_take_cstr(ant_http1_buffer_t *buf) { 100 + if (!buf) return NULL; 101 + if (!ant_http1_buffer_reserve(buf, 1)) return NULL; 102 + buf->data[buf->len] = '\0'; 103 + return ant_http1_buffer_take(buf, NULL); 104 + } 105 + 99 106 void ant_http1_buffer_free(ant_http1_buffer_t *buf) { 100 107 free(buf->data); 101 108 buf->data = NULL;
+8 -2
src/main.c
··· 317 317 318 318 static int execute_module(ant_t *js, const char *filename) { 319 319 char *use_path_owned = NULL; 320 + 320 321 const char *use_path = filename; 322 + const char *stable_use_path = filename; 321 323 322 324 ant_value_t ns = 0; 323 325 ant_value_t specifier = 0; ··· 336 338 if (use_path_owned) use_path = use_path_owned; 337 339 specifier = js_esm_make_file_url(js, use_path); 338 340 } 341 + 342 + const char *interned = intern_string(use_path, strlen(use_path)); 343 + if (interned) stable_use_path = interned; 344 + else stable_use_path = use_path; 339 345 340 346 js_set(js, js_glob(js), 341 347 "__filename", 342 348 js_mkstr(js, filename, strlen(filename)) 343 349 ); 344 350 345 - js_set_filename(js, use_path); 346 - js_setup_import_meta(js, use_path); 351 + js_set_filename(js, stable_use_path); 352 + js_setup_import_meta(js, stable_use_path); 347 353 ns = js_esm_import_sync(js, specifier); 348 354 349 355 free(use_path_owned);