fix user code read NULL content bug

worker_generates_requests_to_global_queue
Xiaosu Lyu 3 years ago
parent 6e3d6ef311
commit 49f5ba3897

@ -68,6 +68,8 @@ struct sandbox {
deadline (cycles) */
uint64_t total_time; /* Total time from Request to Response */
int cursor;
/* System Interface State */
int32_t return_value;
wasi_context_t *wasi_context;

@ -660,7 +660,7 @@ wasi_snapshot_preview1_backing_fd_read(wasi_context_t *context, __wasi_fd_t fd,
if (fd == STDIN_FILENO) {
struct sandbox *current_sandbox = current_sandbox_get();
struct http_request *current_request = &current_sandbox->http->http_request;
int old_read = current_request->cursor;
int old_read = current_sandbox->cursor;
int bytes_to_read = current_request->body_length - old_read;
assert(current_request->body_length >= 0);
@ -669,13 +669,13 @@ wasi_snapshot_preview1_backing_fd_read(wasi_context_t *context, __wasi_fd_t fd,
if (bytes_to_read == 0) goto done;
int amount_to_copy = iovs[i].buf_len > bytes_to_read ? bytes_to_read : iovs[i].buf_len;
memcpy(iovs[i].buf, current_request->body + current_request->cursor, amount_to_copy);
current_request->cursor += amount_to_copy;
bytes_to_read = current_request->body_length - current_request->cursor;
memcpy(iovs[i].buf, current_request->body + current_sandbox->cursor, amount_to_copy);
current_sandbox->cursor += amount_to_copy;
bytes_to_read = current_request->body_length - current_sandbox->cursor;
}
done:
*nwritten_retptr = current_request->cursor - old_read;
*nwritten_retptr = current_sandbox->cursor - old_read;
return __WASI_ERRNO_SUCCESS;
}

@ -29,6 +29,7 @@ int
init_response_body(struct sandbox *sandbox)
{
if (sandbox->response_body.data == NULL) {
sandbox->response_body.size = 0;
int rc = auto_buf_init(&sandbox->response_body);
if (rc < 0) {
printf("failed to init http body autobuf, exit\n");

Loading…
Cancel
Save