Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 2001 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
*client_id = silc_calloc(1, sizeof(**client_id));
(*client_id)[0] = silc_id_payload_parse_id(tmp, len);
+ if ((*client_id)[0] == NULL) {
+ silc_free(*client_id);
+ return FALSE;
+ }
*client_id_count = 1;
/* Take all ID's from the command packet */
if (argc > 3) {
- for (k = 1, i = 4; i < argc; i++) {
+ for (k = 1, i = 4; i < argc + 1; i++) {
tmp = silc_argument_get_arg_type(cmd->args, i, &len);
if (tmp) {
*client_id = silc_realloc(*client_id, sizeof(**client_id) *
(*client_id_count + 1));
- (*client_id)[k++] = silc_id_payload_parse_id(tmp, len);
+ (*client_id)[k] = silc_id_payload_parse_id(tmp, len);
+ if ((*client_id)[k] == NULL) {
+ /* Cleanup all and fail */
+ for (i = 0; i < *client_id_count; i++)
+ silc_free((*client_id)[i]);
+ silc_free(*client_id);
+ return FALSE;
+ }
(*client_id_count)++;
+ k++;
}
}
}
for (i = 0; i < clients_count; i++) {
entry = clients[i];
- if (!entry->nickname || !entry->username || !entry->userinfo) {
+ if (!entry->nickname || !entry->username) {
SilcBuffer tmpbuf;
unsigned short old_ident;
if (clients_count > 1 && i == clients_count - 1)
status = SILC_STATUS_LIST_END;
+ /* Sanity check, however these should never fail. However, as
+ this sanity check has been added here they have failed. */
+ if (!entry->nickname || !entry->username)
+ continue;
+
/* Send WHOIS reply */
idp = silc_id_payload_encode(entry->id, SILC_ID_CLIENT);
tmp = silc_argument_get_first_arg(cmd->args, NULL);
memset(uh, 0, sizeof(uh));
memset(nh, 0, sizeof(nh));
-
+
strncat(nh, entry->nickname, strlen(entry->nickname));
if (!strchr(entry->nickname, '@')) {
strncat(nh, "@", 1);
mandatory fields that WHOIS command reply requires. Check for these and
make query from the server who owns the client if some fields are
missing. */
- if (server->server_type == SILC_ROUTER &&
- !silc_server_command_whois_check(cmd, clients, clients_count)) {
+ if (!silc_server_command_whois_check(cmd, clients, clients_count)) {
ret = -1;
goto out;
}
mandatory fields that WHOIS command reply requires. Check for these and
make query from the server who owns the client if some fields are
missing. */
- if (server->server_type == SILC_ROUTER &&
- !silc_server_command_whois_check(cmd, clients, clients_count)) {
+ if (!silc_server_command_whois_check(cmd, clients, clients_count)) {
ret = -1;
goto out;
}
SilcServerCommandContext cmd = (SilcServerCommandContext)context;
int ret;
- SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_WHOIS, cmd, 1, 3);
+ SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_WHOIS, cmd, 1, 3328);
if (cmd->sock->type == SILC_SOCKET_TYPE_CLIENT)
ret = silc_server_command_whois_from_client(cmd);
/* Check that all mandatory fields are present and request those data
from the server who owns the client if necessary. */
- if (!cmd->pending && server->server_type == SILC_ROUTER &&
+ if (!cmd->pending &&
!silc_server_command_identify_check(cmd, clients, clients_count)) {
ret = -1;
goto out;
/* Check that all mandatory fields are present and request those data
from the server who owns the client if necessary. */
- if (!cmd->pending && server->server_type == SILC_ROUTER &&
+ if (!cmd->pending &&
!silc_server_command_identify_check(cmd, clients, clients_count)) {
ret = -1;
goto out;
SilcServerCommandContext cmd = (SilcServerCommandContext)context;
int ret;
- SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_IDENTIFY, cmd, 1, 3);
+ SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_IDENTIFY, cmd, 1, 3328);
if (cmd->sock->type == SILC_SOCKET_TYPE_CLIENT)
ret = silc_server_command_identify_from_client(cmd);
/* Send notify about nickname change to our router. We send the new
ID and ask to replace it with the old one. If we are router the
packet is broadcasted. */
- if (!cmd->server->standalone)
+ if (!server->standalone)
silc_server_send_replace_id(server, server->router->connection,
server->server_type == SILC_SERVER ?
FALSE : TRUE, client->id,
goto out;
}
channel_id = silc_id_payload_parse_id(tmp, tmp_len);
+ if (!channel_id) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_TOPIC,
+ SILC_STATUS_ERR_NO_CHANNEL_ID);
+ goto out;
+ }
/* Check whether the channel exists */
channel = silc_idlist_find_channel_by_id(server->local_list,
idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
/* Send notify about topic change to all clients on the channel */
- silc_server_send_notify_to_channel(server, channel, TRUE,
+ silc_server_send_notify_to_channel(server, NULL, channel, TRUE,
SILC_NOTIFY_TYPE_TOPIC_SET, 2,
idp->data, idp->len,
channel->topic, strlen(channel->topic));
goto out;
}
dest_id = silc_id_payload_parse_id(tmp, len);
+ if (!dest_id) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE,
+ SILC_STATUS_ERR_NO_CLIENT_ID);
+ goto out;
+ }
/* Get Channel ID */
tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
goto out;
}
channel_id = silc_id_payload_parse_id(tmp, len);
+ if (!channel_id) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE,
+ SILC_STATUS_ERR_NO_CHANNEL_ID);
+ goto out;
+ }
/* Check whether the channel exists */
channel = silc_idlist_find_channel_by_id(server->local_list,
SILC_STATUS_ERR_NO_SERVER_ID);
goto out;
}
- id = silc_id_str2id(tmp, SILC_ID_SERVER);
+ id = silc_id_str2id(tmp, len, SILC_ID_SERVER);
if (!id)
goto out;
SilcBuffer buffer, idp;
SilcPacketContext *packet = silc_packet_context_alloc();
+ SILC_LOG_DEBUG(("Start"));
+
/* Create USERS command packet and process it. */
idp = silc_id_payload_encode(channel->id, SILC_ID_CHANNEL);
buffer = silc_command_payload_encode_va(SILC_COMMAND_USERS, 0, 1,
cmd = silc_calloc(1, sizeof(*cmd));
cmd->payload = silc_command_payload_parse(buffer);
+ if (!cmd->payload) {
+ silc_free(cmd);
+ silc_buffer_free(buffer);
+ silc_buffer_free(idp);
+ silc_packet_context_free(packet);
+ return;
+ }
cmd->args = silc_command_get_args(cmd->payload);
cmd->server = server;
cmd->sock = sock;
silc_server_command_pending(server, SILC_COMMAND_USERS, 0,
silc_server_command_users, (void *)cmd);
cmd->pending = TRUE;
- silc_free(buffer);
- silc_free(idp);
+ silc_buffer_free(buffer);
+ silc_buffer_free(idp);
return;
}
/* Process USERS command. */
silc_server_command_users((void *)cmd);
- silc_free(buffer);
- silc_free(idp);
+ silc_buffer_free(buffer);
+ silc_buffer_free(idp);
silc_packet_context_free(packet);
}
/* Send the channel key. This is broadcasted to the channel but is not
sent to the client who is joining to the channel. */
- silc_server_send_channel_key(server, channel,
+ silc_server_send_channel_key(server, NULL, channel,
server->server_type == SILC_ROUTER ?
FALSE : server->standalone);
if (!cmd->pending) {
/* Send JOIN notify to locally connected clients on the channel */
- silc_server_send_notify_to_channel(server, channel, FALSE,
+ silc_server_send_notify_to_channel(server, NULL, channel, FALSE,
SILC_NOTIFY_TYPE_JOIN, 1,
clidp->data, clidp->len);
goto out;
}
client_id = silc_id_payload_parse_id(tmp, tmp_len);
+ if (!client_id) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_JOIN,
+ SILC_STATUS_ERR_NOT_ENOUGH_PARAMS);
+ goto out;
+ }
/* Get cipher name */
cipher = silc_argument_get_arg_type(cmd->args, 4, NULL);
goto out;
}
channel_id = silc_id_payload_parse_id(tmp_id, tmp_len2);
+ if (!channel_id) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_CMODE,
+ SILC_STATUS_ERR_NO_CHANNEL_ID);
+ goto out;
+ }
/* Get the channel mode mask */
tmp_mask = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
/* Send CMODE_CHANGE notify */
cidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
- silc_server_send_notify_to_channel(server, channel, TRUE,
+ silc_server_send_notify_to_channel(server, NULL, channel, TRUE,
SILC_NOTIFY_TYPE_CMODE_CHANGE, 2,
cidp->data, cidp->len,
tmp_mask, tmp_len);
goto out;
}
channel_id = silc_id_payload_parse_id(tmp_id, tmp_len);
+ if (!channel_id) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE,
+ SILC_STATUS_ERR_NO_CHANNEL_ID);
+ goto out;
+ }
/* Get channel entry */
channel = silc_idlist_find_channel_by_id(server->local_list,
goto out;
}
client_id = silc_id_payload_parse_id(tmp_id, tmp_len);
+ if (!client_id) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_CUMODE,
+ SILC_STATUS_ERR_NO_CHANNEL_ID);
+ goto out;
+ }
/* Get target client's entry */
target_client = silc_idlist_find_client_by_id(server->local_list,
/* Send notify to channel, notify only if mode was actually changed. */
if (notify) {
idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
- silc_server_send_notify_to_channel(server, channel, TRUE,
+ silc_server_send_notify_to_channel(server, NULL, channel, TRUE,
SILC_NOTIFY_TYPE_CUMODE_CHANGE, 3,
idp->data, idp->len,
tmp_mask, 4, tmp_id, tmp_len);
goto out;
}
id = silc_id_payload_parse_id(tmp, len);
+ if (!id) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_LEAVE,
+ SILC_STATUS_ERR_NO_CHANNEL_ID);
+ goto out;
+ }
/* Get channel entry */
channel = silc_idlist_find_channel_by_id(server->local_list, id, NULL);
silc_server_packet_send(server,
cmd->server->router->connection,
SILC_PACKET_CHANNEL_KEY, 0, packet->data,
- packet->len, TRUE);
+ packet->len, FALSE);
} else {
}
unsigned int list_count = 0;
unsigned short ident = silc_command_get_ident(cmd->payload);
- SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_USERS, cmd, 1, 2);
+ SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_USERS, cmd, 1, 1);
/* Get Channel ID */
channel_id = silc_argument_get_arg_type(cmd->args, 1, &channel_id_len);
goto out;
}
id = silc_id_payload_parse_id(channel_id, channel_id_len);
+ if (!id) {
+ silc_server_command_send_status_reply(cmd, SILC_COMMAND_USERS,
+ SILC_STATUS_ERR_NO_CHANNEL_ID);
+ goto out;
+ }
/* If we are server and we don't know about this channel we will send
the command to our router. If we know about the channel then we also