Fix memory access on empty commands.

master
Nicolas Favre-Felix 14 years ago
parent a298d3c16b
commit 70d2e07043

11
acl.c

@ -43,8 +43,15 @@ acl_allow_command(struct cmd *cmd, struct conf *cfg, struct http_client *client)
in_addr_t client_addr;
const char *cmd_name = cmd->argv[0];
size_t cmd_len = cmd->argv_len[0];
const char *cmd_name;
size_t cmd_len;
if(cmd->count == 0) {
return 0;
}
cmd_name = cmd->argv[0];
cmd_len = cmd->argv_len[0];
/* some commands are always disabled, regardless of the config file. */
for(i = 0; i < sizeof(always_off) / sizeof(always_off[0]); ++i) {

@ -122,6 +122,7 @@ http_client_cleanup(struct http_client *c) {
c->cmd = NULL;
c->state = CLIENT_WAITING;
c->started_responding = 0;
}
void

@ -54,6 +54,7 @@ struct http_client {
/* pub/sub */
struct subscription *sub;
int started_responding;
struct http_response resp;

@ -95,6 +95,9 @@ cmd_run(struct server *s, struct http_client *client,
if(body && body_len) { /* PUT request */
param_count++;
}
if(param_count == 0) {
return -1;
}
client->cmd = cmd = cmd_new(param_count);
@ -113,7 +116,6 @@ cmd_run(struct server *s, struct http_client *client,
cmd->argv[0] = uri;
cmd->argv_len[0] = cmd_len;
/* check that the client is able to run this command */
if(!acl_allow_command(cmd, s->cfg, client)) {
return -1;

@ -19,8 +19,6 @@ struct cmd {
const char **argv;
size_t *argv_len;
int started_responding;
/* HTTP data */
char *mime;
int mime_free;

@ -40,9 +40,9 @@ format_send_reply(struct http_client *client, const char *p, size_t sz, const ch
free_cmd = 0;
/* start streaming */
if(cmd->started_responding == 0) {
if(client->started_responding == 0) {
const char *ct = cmd->mime?cmd->mime:content_type;
cmd->started_responding = 1;
client->started_responding = 1;
http_set_header(&client->output_headers.content_type, ct, strlen(ct));
http_send_reply_start(client, 200, "OK");
}

Loading…
Cancel
Save