!bufev_p->write_suspended) {
/* Somebody added data to the buffer, and we would like to
* write, and we were not writing. So, start writing. */
- be_socket_add(&bufev->ev_write, &bufev->timeout_write);
- /* XXXX handle failure from be_socket_add */
+ if (be_socket_add(&bufev->ev_write, &bufev->timeout_write) == -1) {
+ // Should we log this?
+ }
}
}
evrpc_request_cb_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res)
{
struct evrpc_req_generic *rpc_state = arg;
+ EVUTIL_ASSERT(rpc_state);
struct evrpc *rpc = rpc_state->rpc;
struct evhttp_request *req = rpc_state->http_req;
void
evrpc_request_done(struct evrpc_req_generic *rpc_state)
{
- struct evhttp_request *req = rpc_state->http_req;
- struct evrpc *rpc = rpc_state->rpc;
+ struct evhttp_request *req;
+ struct evrpc *rpc;
+
+ EVUTIL_ASSERT(rpc_state);
+
+ req = rpc_state->http_req;
+ rpc = rpc_state->rpc;
if (rpc->reply_complete(rpc_state->reply) == -1) {
/* the reply was not completely filled in. error out */
evrpc_request_done_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res)
{
struct evrpc_req_generic *rpc_state = arg;
+ EVUTIL_ASSERT(rpc_state);
struct evhttp_request *req = rpc_state->http_req;
if (hook_res == EVRPC_TERMINATE)
int made_fd = 0;
if (*fd_ptr < 0) {
- made_fd = 1;
if ((*fd_ptr = socket(sa->sa_family, SOCK_STREAM, 0)) < 0)
goto err;
+ made_fd = 1;
if (evutil_make_socket_nonblocking(*fd_ptr) < 0) {
goto err;
}
evutil_socket_t sock;
struct sockaddr_in my_addr;
sock = socket(PF_INET, SOCK_DGRAM, 0);
+ if (sock == -1) {
+ perror("socket");
+ exit(1);
+ }
evutil_make_socket_nonblocking(sock);
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(10053);
int n;
char cbuf[128];
n = evbuffer_remove(buf, cbuf, sizeof(buf)-1);
- fwrite(cbuf, 1, n, stdout);
+ if (n > 0)
+ fwrite(cbuf, 1, n, stdout);
}
puts(">>>");
/* We need to decode it, to see what path the user really wanted. */
decoded_path = evhttp_uridecode(path, 0, NULL);
+ if (decoded_path == NULL)
+ goto err;
/* Don't allow any ".."s in the path, to avoid exposing stuff outside
* of the docroot. This test is both overzealous and underzealous:
* it forbids aceptable paths like "/this/one..here", but it doesn't
}
switch (c) {
+ char ** eptr;
case 'p':
- port = atoi(argv[i+1]);
+ port = (int)strtol(argv[i+1], eptr, 10);
+ if (!(argv[i+1] && (**eptr == '\0'))) {
+ fprintf(stderr, "Bad port\n");
+ exit(1);
+ }
break;
case 'l':
- content_len = atol(argv[i+1]);
+ content_len = (int)strtol(argv[i+1], eptr, 10);
+ if (!(argv[i+1] && (**eptr == '\0'))) {
+ fprintf(stderr, "Bad content length\n");
+ exit(1);
+ }
if (content_len == 0) {
fprintf(stderr, "Bad content length\n");
exit(1);