fix: Corrected assorted bugs

master
Sean McBride 3 years ago
parent 332b492761
commit f51da123e2

@ -36,7 +36,7 @@ client_socket_close(int client_socket, struct sockaddr *client_address)
typedef void (*void_cb)(void);
/**
* Rejects request due to admission control or error
* Writes buffer to the client socket
* @param client_socket - the client we are rejecting
* @param buffer - buffer to write to socket
* @param on_eagain - cb to execute when client socket returns EAGAIN. If NULL, error out
@ -53,19 +53,20 @@ client_socket_send(int client_socket, const char *buffer, size_t buffer_len, voi
ssize_t sent = write(client_socket, &buffer[cursor], buffer_len - cursor);
if (sent < 0) {
if (errno == EAGAIN) {
if (on_eagain) {
on_eagain();
} else {
if (on_eagain == NULL) {
rc = -1;
goto done;
}
on_eagain();
} else {
debuglog("Error sending to client: %s", strerror(errno));
rc = -1;
goto done;
}
}
cursor += sent;
assert(sent > 0);
cursor += (size_t)sent;
};
rc = 0;

@ -28,11 +28,10 @@ current_sandbox_send_response()
struct vec_u8 *response = sandbox->response;
assert(response != NULL);
int rc;
ssize_t sent = 0;
int rc;
/* Determine values to template into our HTTP response */
ssize_t response_body_size = response->length;
size_t response_body_size = response->length;
char * module_content_type = sandbox->module->response_content_type;
const char *content_type = strlen(module_content_type) > 0 ? module_content_type : "text/plain";
@ -40,21 +39,11 @@ current_sandbox_send_response()
uint64_t end_time = __getcycles();
sandbox->total_time = end_time - sandbox->timestamp_of.request_arrival;
/* Generate and send HTTP Response Headers */
ssize_t response_header_size = http_response_200_size(content_type, response_body_size);
char response_header_buffer[response_header_size + 1];
rc = http_header_200_build(response_header_buffer, content_type, response_body_size);
if (rc <= 0) {
perror("sprintf");
goto err;
}
client_socket_send(sandbox->client_socket_descriptor, response_header_buffer, response_header_size,
/* Send HTTP Response Header and Body */
http_header_200_write(sandbox->client_socket_descriptor, module_content_type, response_body_size);
client_socket_send(sandbox->client_socket_descriptor, (const char *)response->buffer, response_body_size,
current_sandbox_sleep);
/* Send HTTP Response Body */
client_socket_send(sandbox->client_socket_descriptor, (const char *)response->buffer,
response_body_size, current_sandbox_sleep);
http_total_increment_2xx();
rc = 0;

@ -39,29 +39,11 @@
/* The sum of format specifier characters in the template above */
#define HTTP_RESPONSE_200_TEMPLATE_FORMAT_SPECIFIER_LENGTH 5
/**
* Calculates the number of bytes of the HTTP response containing the passed header values
* @return total size in bytes
*/
static inline size_t
http_response_200_size(const char *content_type, ssize_t content_length)
{
size_t size = 0;
size += strlen(HTTP_RESPONSE_200_TEMPLATE) - HTTP_RESPONSE_200_TEMPLATE_FORMAT_SPECIFIER_LENGTH;
size += strlen(content_type);
while (content_length > 0) {
content_length /= 10;
size++;
}
return size;
}
static inline int
http_header_200_build(char *buffer, const char *content_type, ssize_t content_length)
http_header_200_write(int fd, const char *content_type, size_t content_length)
{
return sprintf(buffer, HTTP_RESPONSE_200_TEMPLATE, content_type, content_length);
return dprintf(fd, HTTP_RESPONSE_200_TEMPLATE, content_type, content_length);
}
static inline const char *

@ -49,7 +49,7 @@ sandbox_receive_request(struct sandbox *sandbox)
ssize_t bytes_received = recv(sandbox->client_socket_descriptor, &request->buffer[request_length],
request_capacity - request_length, 0);
if (bytes_received == -1) {
if (bytes_received < 0) {
if (errno == EAGAIN) {
current_sandbox_sleep();
continue;
@ -74,19 +74,21 @@ sandbox_receive_request(struct sandbox *sandbox)
goto err;
}
assert(bytes_received > 0);
#ifdef LOG_HTTP_PARSER
debuglog("Sandbox: %lu http_parser_execute(%p, %p, %p, %zu\n)", sandbox->id, parser, settings,
&sandbox->request.base[sandbox->request.length], bytes_received);
#endif
size_t bytes_parsed = http_parser_execute(parser, settings,
(const char *)&request->buffer[request_length],
bytes_received);
(size_t)bytes_received);
if (bytes_parsed != bytes_received) {
if (bytes_parsed != (size_t)bytes_received) {
debuglog("Error: %s, Description: %s\n",
http_errno_name((enum http_errno)sandbox->http_parser.http_errno),
http_errno_description((enum http_errno)sandbox->http_parser.http_errno));
debuglog("Length Parsed %zu, Length Read %zu\n", bytes_parsed, bytes_received);
debuglog("Length Parsed %zu, Length Read %zu\n", bytes_parsed, (size_t)bytes_received);
debuglog("Error parsing socket %d\n", sandbox->client_socket_descriptor);
goto err;
}

@ -50,7 +50,6 @@ struct sandbox {
int client_socket_descriptor;
http_parser http_parser;
struct http_request http_request;
ssize_t http_request_length; /* TODO: Get rid of me */
struct vec_u8 * request;
struct vec_u8 * response;

@ -112,7 +112,7 @@ static inline char
wasm_memory_get_char(struct wasm_memory *self, uint32_t offset)
{
assert(offset + sizeof(char) <= self->size);
return (char)self->data[offset];
return *(char *)&self->data[offset];
}
/**
@ -148,7 +148,7 @@ static inline int8_t
wasm_memory_get_i8(struct wasm_memory *self, uint32_t offset)
{
assert(offset + sizeof(int8_t) <= self->size);
return (int8_t)self->data[offset];
return *(int8_t *)&self->data[offset];
}
/**
@ -243,7 +243,7 @@ static inline void
wasm_memory_set_i8(struct wasm_memory *self, uint32_t offset, int8_t value)
{
assert(offset + sizeof(int8_t) <= self->size);
self->data[offset] = value;
*(int8_t *)&self->data[offset] = value;
}
/**
@ -279,7 +279,7 @@ static inline void
wasm_memory_set_i64(struct wasm_memory *self, uint64_t offset, int64_t value)
{
assert(offset + sizeof(int64_t) <= self->size);
*(int32_t *)&self->data[offset] = value;
*(int64_t *)&self->data[offset] = value;
}
static inline void

@ -57,6 +57,7 @@ wasm_table_set(struct wasm_table *self, uint32_t idx, uint32_t type_id, char *po
{
assert(self != NULL);
assert(idx < self->capacity);
assert(pointer != NULL);
/* TODO: atomic for multiple concurrent invocations? Issue #97 */
if (self->data[idx].type_id == type_id && self->data[idx].func_pointer == pointer) return;

@ -10,7 +10,7 @@ SLEDGE_COMPILETIME_INC=${SLEDGE_RT_DIR}/include
SLEDGE_COMPILETIME_SRC=${SLEDGE_RT_DIR}/compiletime/*.c
.PHONY: all
all: fibonacci.install empty.install ekf.install cifar10.install lpd.install resize.install
all: fibonacci.install empty.install ekf.install cifar10.install gocr.install lpd.install resize.install
.PHONY: clean
clean:

Loading…
Cancel
Save