projects
/
silc.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c6e651c
)
updates.
author
Pekka Riikonen
<priikone@silcnet.org>
Thu, 7 Mar 2002 20:11:49 +0000
(20:11 +0000)
committer
Pekka Riikonen
<priikone@silcnet.org>
Thu, 7 Mar 2002 20:11:49 +0000
(20:11 +0000)
13 files changed:
CHANGES
patch
|
blob
|
history
TODO-1.0
patch
|
blob
|
history
apps/silcd/serverconfig.c
patch
|
blob
|
history
lib/silccore/silcargument.c
patch
|
blob
|
history
lib/silccore/silcauth.c
patch
|
blob
|
history
lib/silccore/silcchannel.c
patch
|
blob
|
history
lib/silccore/silccommand.c
patch
|
blob
|
history
lib/silccore/silcid.c
patch
|
blob
|
history
lib/silccore/silcidcache.c
patch
|
blob
|
history
lib/silccore/silcnotify.c
patch
|
blob
|
history
lib/silccore/silcpacket.c
patch
|
blob
|
history
lib/silccore/silcprivate.c
patch
|
blob
|
history
lib/silcutil/silcbuffer.h
patch
|
blob
|
history
diff --git
a/CHANGES
b/CHANGES
index 7b9d3ec89dffe3653cef3c145bec39e21785d756..78b6134540fc6263f4ecdd88a347c05ecc72741d 100644
(file)
--- a/
CHANGES
+++ b/
CHANGES
@@
-6,6
+6,12
@@
Thu Mar 7 19:21:22 EET 2002 Pekka Riikonen <priikone@silcnet.org>
* Added more error printing to logs in server code. Affected
files silcd/server.c and silcd/protocol.c.
* Added more error printing to logs in server code. Affected
files silcd/server.c and silcd/protocol.c.
+ * Fixed -S option parsing in Irssi SILC Client. Affected file
+ irssi/src/silc/core/silc-core.c.
+
+ * Added silc_buffer_alloc_size function. Affected file is
+ lib/silcutil/silcbuffer.h.
+
Tue Mar 5 14:37:27 EET 2002 Pekka Riikonen <priikone@silcnet.org>
* Changed all silc_[hash|hmac|cipher|pkcs]_default tables to
Tue Mar 5 14:37:27 EET 2002 Pekka Riikonen <priikone@silcnet.org>
* Changed all silc_[hash|hmac|cipher|pkcs]_default tables to
diff --git
a/TODO-1.0
b/TODO-1.0
index 601712ea2fa4fd3571ec01efbd9e44a211407bcd..cc751428bd4bef498f10224e0565141bece29183 100644
(file)
--- a/
TODO-1.0
+++ b/
TODO-1.0
@@
-90,14
+90,6
@@
least could be done.
SILC_BUFFER_LEN macro can do the same. These would save
totally 8 bytes of memory per buffer.
SILC_BUFFER_LEN macro can do the same. These would save
totally 8 bytes of memory per buffer.
- Add also perhaps function silc_buffer_alloc_size that would
- effectively do:
-
- return silc_buffer_pull_tail(silc_buffer_alloc(size),
- size);
-
- to not require the user to give the pull_tail anymore.
-
o Scheduler can be optimized for FD tasks by changing the fd_queue
to SilcHashTable instead of using linked list. We need to do
one-to-one mapping of FD to task and hash table is more efficient
o Scheduler can be optimized for FD tasks by changing the fd_queue
to SilcHashTable instead of using linked list. We need to do
one-to-one mapping of FD to task and hash table is more efficient
diff --git
a/apps/silcd/serverconfig.c
b/apps/silcd/serverconfig.c
index 09fde6070f8fdab3de3aa6accfd0e64efb627e97..e0f029158c047c847673f8231f2b85b6597198ee 100644
(file)
--- a/
apps/silcd/serverconfig.c
+++ b/
apps/silcd/serverconfig.c
@@
-1293,7
+1293,7
@@
bool silc_server_config_register_ciphers(SilcServer server)
int i;
for (i = 0; silc_default_ciphers[i].name; i++)
if (!strcmp(silc_default_ciphers[i].name, cipher->name)) {
int i;
for (i = 0; silc_default_ciphers[i].name; i++)
if (!strcmp(silc_default_ciphers[i].name, cipher->name)) {
- silc_cipher_register(&silc_default_ciphers[i]);
+ silc_cipher_register(
(SilcCipherObject *)
&silc_default_ciphers[i]);
break;
}
if (!silc_cipher_is_supported(cipher->name)) {
break;
}
if (!silc_cipher_is_supported(cipher->name)) {
@@
-1394,7
+1394,7
@@
bool silc_server_config_register_hashfuncs(SilcServer server)
int i;
for (i = 0; silc_default_hash[i].name; i++)
if (!strcmp(silc_default_hash[i].name, hash->name)) {
int i;
for (i = 0; silc_default_hash[i].name; i++)
if (!strcmp(silc_default_hash[i].name, hash->name)) {
- silc_hash_register(&silc_default_hash[i]);
+ silc_hash_register(
(SilcHashObject *)
&silc_default_hash[i]);
break;
}
if (!silc_hash_is_supported(hash->name)) {
break;
}
if (!silc_hash_is_supported(hash->name)) {
@@
-1478,6
+1478,7
@@
bool silc_server_config_register_hmacs(SilcServer server)
silc_server_stop(server);
exit(1);
}
silc_server_stop(server);
exit(1);
}
+
/* Register the HMAC */
memset(&hmac_obj, 0, sizeof(hmac_obj));
hmac_obj.name = hmac->name;
/* Register the HMAC */
memset(&hmac_obj, 0, sizeof(hmac_obj));
hmac_obj.name = hmac->name;
@@
-1506,7
+1507,7
@@
bool silc_server_config_register_pkcs(SilcServer server)
int i;
for (i = 0; silc_default_pkcs[i].name; i++)
if (!strcmp(silc_default_pkcs[i].name, pkcs->name)) {
int i;
for (i = 0; silc_default_pkcs[i].name; i++)
if (!strcmp(silc_default_pkcs[i].name, pkcs->name)) {
- silc_pkcs_register(&silc_default_pkcs[i]);
+ silc_pkcs_register(
(SilcPKCSObject *)
&silc_default_pkcs[i]);
break;
}
if (!silc_pkcs_is_supported(pkcs->name)) {
break;
}
if (!silc_pkcs_is_supported(pkcs->name)) {
diff --git
a/lib/silccore/silcargument.c
b/lib/silccore/silcargument.c
index efd2cafd3d4bbd51b8dc50bca292e6f838e3bd23..dd470a37dbc4ef704a7d6f55e9cc5a2d17250799 100644
(file)
--- a/
lib/silccore/silcargument.c
+++ b/
lib/silccore/silcargument.c
@@
-43,7
+43,7
@@
SilcArgumentPayload silc_argument_payload_parse(const unsigned char *payload,
SilcUInt32 argc)
{
SilcBufferStruct buffer;
SilcUInt32 argc)
{
SilcBufferStruct buffer;
- SilcArgumentPayload new;
+ SilcArgumentPayload new
p
;
SilcUInt16 p_len = 0;
unsigned char arg_num = 0;
unsigned char arg_type = 0;
SilcUInt16 p_len = 0;
unsigned char arg_num = 0;
unsigned char arg_type = 0;
@@
-53,10
+53,18
@@
SilcArgumentPayload silc_argument_payload_parse(const unsigned char *payload,
SILC_LOG_DEBUG(("Parsing argument payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
SILC_LOG_DEBUG(("Parsing argument payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
- new = silc_calloc(1, sizeof(*new));
- new->argv = silc_calloc(argc, sizeof(unsigned char *));
- new->argv_lens = silc_calloc(argc, sizeof(SilcUInt32));
- new->argv_types = silc_calloc(argc, sizeof(SilcUInt32));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
+ newp->argv = silc_calloc(argc, sizeof(unsigned char *));
+ if (!newp->argv)
+ goto err;
+ newp->argv_lens = silc_calloc(argc, sizeof(SilcUInt32));
+ if (!newp->argv_lens)
+ goto err;
+ newp->argv_types = silc_calloc(argc, sizeof(SilcUInt32));
+ if (!newp->argv_types)
+ goto err;
/* Get arguments */
arg_num = 1;
/* Get arguments */
arg_num = 1;
@@
-68,8
+76,8
@@
SilcArgumentPayload silc_argument_payload_parse(const unsigned char *payload,
if (ret == -1)
goto err;
if (ret == -1)
goto err;
- new->argv_lens[i] = p_len;
- new->argv_types[i] = arg_type;
+ new
p
->argv_lens[i] = p_len;
+ new
p
->argv_types[i] = arg_type;
if (p_len > buffer.len - 3)
break;
if (p_len > buffer.len - 3)
break;
@@
-77,7
+85,7
@@
SilcArgumentPayload silc_argument_payload_parse(const unsigned char *payload,
/* Get argument data */
silc_buffer_pull(&buffer, 3);
ret = silc_buffer_unformat(&buffer,
/* Get argument data */
silc_buffer_pull(&buffer, 3);
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI_XNSTRING_ALLOC(&new->argv[i],
+ SILC_STR_UI_XNSTRING_ALLOC(&new
p
->argv[i],
p_len),
SILC_STR_END);
if (ret == -1)
p_len),
SILC_STR_END);
if (ret == -1)
@@
-90,27
+98,22
@@
SilcArgumentPayload silc_argument_payload_parse(const unsigned char *payload,
if (buffer.len != 0)
goto err;
if (buffer.len != 0)
goto err;
- new->argc = argc;
- new->pos = 0;
+ new
p
->argc = argc;
+ new
p
->pos = 0;
silc_buffer_push(&buffer, pull_len);
silc_buffer_push(&buffer, pull_len);
- return new;
+ return new
p
;
err:
err:
- if (i) {
- int k;
+ if (i)
+ for (ret = 0; ret < i; ret++)
+ silc_free(newp->argv[ret]);
- for (k = 0; k < i; k++)
- silc_free(new->argv[k]);
- }
-
- silc_free(new->argv);
- silc_free(new->argv_lens);
- silc_free(new->argv_types);
-
- if (new)
- silc_free(new);
+ silc_free(newp->argv);
+ silc_free(newp->argv_lens);
+ silc_free(newp->argv_types);
+ silc_free(newp);
return NULL;
}
return NULL;
}
@@
-132,8
+135,9
@@
SilcBuffer silc_argument_payload_encode(SilcUInt32 argc,
for (i = 0; i < argc; i++)
len += 3 + argv_lens[i];
for (i = 0; i < argc; i++)
len += 3 + argv_lens[i];
- buffer = silc_buffer_alloc(len);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(len);
+ if (!buffer)
+ return NULL;
/* Put arguments */
for (i = 0; i < argc; i++) {
/* Put arguments */
for (i = 0; i < argc; i++) {
@@
-165,8
+169,9
@@
SilcBuffer silc_argument_payload_encode_payload(SilcArgumentPayload payload)
for (i = 0; i < payload->argc; i++)
len += 3 + payload->argv_lens[i];
for (i = 0; i < payload->argc; i++)
len += 3 + payload->argv_lens[i];
- buffer = silc_buffer_alloc(len);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(len);
+ if (!buffer)
+ return NULL;
/* Put arguments */
for (i = 0; i < payload->argc; i++) {
/* Put arguments */
for (i = 0; i < payload->argc; i++) {
diff --git
a/lib/silccore/silcauth.c
b/lib/silccore/silcauth.c
index 23029640c43bef8f61cfee6248995199dfd04d38..b3fb455891707f1efc0f250078a14cf40a675616 100644
(file)
--- a/
lib/silccore/silcauth.c
+++ b/
lib/silccore/silcauth.c
@@
-44,40
+44,42
@@
SilcAuthPayload silc_auth_payload_parse(const unsigned char *data,
SilcUInt32 data_len)
{
SilcBufferStruct buffer;
SilcUInt32 data_len)
{
SilcBufferStruct buffer;
- SilcAuthPayload new;
+ SilcAuthPayload new
p
;
int ret;
SILC_LOG_DEBUG(("Parsing Authentication Payload"));
silc_buffer_set(&buffer, (unsigned char *)data, data_len);
int ret;
SILC_LOG_DEBUG(("Parsing Authentication Payload"));
silc_buffer_set(&buffer, (unsigned char *)data, data_len);
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
/* Parse the payload */
ret = silc_buffer_unformat(&buffer,
/* Parse the payload */
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI_SHORT(&new->len),
- SILC_STR_UI_SHORT(&new->auth_method),
- SILC_STR_UI16_NSTRING_ALLOC(&new->random_data,
- &new->random_len),
- SILC_STR_UI16_NSTRING_ALLOC(&new->auth_data,
- &new->auth_len),
+ SILC_STR_UI_SHORT(&new
p
->len),
+ SILC_STR_UI_SHORT(&new
p
->auth_method),
+ SILC_STR_UI16_NSTRING_ALLOC(&new
p
->random_data,
+ &new
p
->random_len),
+ SILC_STR_UI16_NSTRING_ALLOC(&new
p
->auth_data,
+ &new
p
->auth_len),
SILC_STR_END);
if (ret == -1) {
SILC_STR_END);
if (ret == -1) {
- silc_free(new);
+ silc_free(new
p
);
return NULL;
}
return NULL;
}
- if (new->len != buffer.len) {
- silc_auth_payload_free(new);
+ if (new
p
->len != buffer.len) {
+ silc_auth_payload_free(new
p
);
return NULL;
}
/* If password authentication, random data must not be set */
return NULL;
}
/* If password authentication, random data must not be set */
- if (new
->auth_method == SILC_AUTH_PASSWORD && new
->random_len) {
- silc_auth_payload_free(new);
+ if (new
p->auth_method == SILC_AUTH_PASSWORD && newp
->random_len) {
+ silc_auth_payload_free(new
p
);
return NULL;
}
return NULL;
}
- return new;
+ return new
p
;
}
/* Encodes authentication payload into buffer and returns it */
}
/* Encodes authentication payload into buffer and returns it */
@@
-94,8
+96,9
@@
SilcBuffer silc_auth_payload_encode(SilcAuthMethod method,
SILC_LOG_DEBUG(("Encoding Authentication Payload"));
len = 2 + 2 + 2 + random_len + 2 + auth_len;
SILC_LOG_DEBUG(("Encoding Authentication Payload"));
len = 2 + 2 + 2 + random_len + 2 + auth_len;
- buffer = silc_buffer_alloc(len);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(len);
+ if (!buffer)
+ return NULL;
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(len),
SILC_STR_UI_SHORT(method),
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(len),
SILC_STR_UI_SHORT(method),
@@
-173,8
+176,12
@@
silc_auth_public_key_encode_data(SilcPublicKey public_key,
}
id_len = silc_id_get_len(id, type);
}
id_len = silc_id_get_len(id, type);
- buf = silc_buffer_alloc(random_len + id_len + pk_len);
- silc_buffer_pull_tail(buf, SILC_BUFFER_END(buf));
+ buf = silc_buffer_alloc_size(random_len + id_len + pk_len);
+ if (!buf) {
+ silc_free(pk);
+ silc_free(id_data);
+ return NULL;
+ }
silc_buffer_format(buf,
SILC_STR_UI_XNSTRING(random, random_len),
SILC_STR_UI_XNSTRING(id_data, id_len),
silc_buffer_format(buf,
SILC_STR_UI_XNSTRING(random, random_len),
SILC_STR_UI_XNSTRING(id_data, id_len),
@@
-182,6
+189,8
@@
silc_auth_public_key_encode_data(SilcPublicKey public_key,
SILC_STR_END);
ret = silc_memdup(buf->data, buf->len);
SILC_STR_END);
ret = silc_memdup(buf->data, buf->len);
+ if (!ret)
+ return NULL;
if (ret_len)
*ret_len = buf->len;
if (ret_len)
*ret_len = buf->len;
@@
-420,26
+429,28
@@
silc_key_agreement_payload_parse(const unsigned char *payload,
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
- SilcKeyAgreementPayload new;
+ SilcKeyAgreementPayload new
p
;
int ret;
SILC_LOG_DEBUG(("Parsing Key Agreement Payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
int ret;
SILC_LOG_DEBUG(("Parsing Key Agreement Payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
/* Parse the payload */
ret = silc_buffer_unformat(&buffer,
/* Parse the payload */
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI16_NSTRING_ALLOC(&new->hostname,
- &new->hostname_len),
- SILC_STR_UI_INT(&new->port),
+ SILC_STR_UI16_NSTRING_ALLOC(&new
p
->hostname,
+ &new
p
->hostname_len),
+ SILC_STR_UI_INT(&new
p
->port),
SILC_STR_END);
if (ret == -1) {
SILC_STR_END);
if (ret == -1) {
- silc_free(new);
+ silc_free(new
p
);
return NULL;
}
return NULL;
}
- return new;
+ return new
p
;
}
/* Encodes the Key Agreement protocol and returns the encoded buffer */
}
/* Encodes the Key Agreement protocol and returns the encoded buffer */
@@
-452,8
+463,9
@@
SilcBuffer silc_key_agreement_payload_encode(const char *hostname,
SILC_LOG_DEBUG(("Encoding Key Agreement Payload"));
SILC_LOG_DEBUG(("Encoding Key Agreement Payload"));
- buffer = silc_buffer_alloc(2 + len + 4);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(2 + len + 4);
+ if (!buffer)
+ return NULL;
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(len),
SILC_STR_UI_XNSTRING(hostname, len),
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(len),
SILC_STR_UI_XNSTRING(hostname, len),
diff --git
a/lib/silccore/silcchannel.c
b/lib/silccore/silcchannel.c
index ae6ac4be73493973807189e916b875809ddc6176..8fcc4c539be5cfbbb652a702f3f8fae962a9ee3f 100644
(file)
--- a/
lib/silccore/silcchannel.c
+++ b/
lib/silccore/silcchannel.c
@@
-46,35
+46,37
@@
SilcChannelPayload silc_channel_payload_parse(const unsigned char *payload,
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
- SilcChannelPayload new;
+ SilcChannelPayload new
p
;
int ret;
SILC_LOG_DEBUG(("Parsing channel payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
int ret;
SILC_LOG_DEBUG(("Parsing channel payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
/* Parse the Channel Payload. Ignore the padding. */
ret = silc_buffer_unformat(&buffer,
/* Parse the Channel Payload. Ignore the padding. */
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI16_NSTRING_ALLOC(&new->channel_name,
- &new->name_len),
- SILC_STR_UI16_NSTRING_ALLOC(&new->channel_id,
- &new->id_len),
- SILC_STR_UI_INT(&new->mode),
+ SILC_STR_UI16_NSTRING_ALLOC(&new
p
->channel_name,
+ &new
p
->name_len),
+ SILC_STR_UI16_NSTRING_ALLOC(&new
p
->channel_id,
+ &new
p
->id_len),
+ SILC_STR_UI_INT(&new
p
->mode),
SILC_STR_END);
if (ret == -1)
goto err;
SILC_STR_END);
if (ret == -1)
goto err;
- if ((new
->name_len < 1 || new
->name_len > buffer.len) ||
- (new
->id_len < 1 || new
->id_len > buffer.len)) {
+ if ((new
p->name_len < 1 || newp
->name_len > buffer.len) ||
+ (new
p->id_len < 1 || newp
->id_len > buffer.len)) {
SILC_LOG_ERROR(("Incorrect channel payload in packet, packet dropped"));
goto err;
}
SILC_LOG_ERROR(("Incorrect channel payload in packet, packet dropped"));
goto err;
}
- return new;
+ return new
p
;
err:
err:
- silc_channel_payload_free(new);
+ silc_channel_payload_free(new
p
);
return NULL;
}
return NULL;
}
@@
-85,7
+87,7
@@
SilcDList silc_channel_payload_parse_list(const unsigned char *payload,
{
SilcBufferStruct buffer;
SilcDList list;
{
SilcBufferStruct buffer;
SilcDList list;
- SilcChannelPayload new;
+ SilcChannelPayload new
p
;
int len, ret;
SILC_LOG_DEBUG(("Parsing channel payload list"));
int len, ret;
SILC_LOG_DEBUG(("Parsing channel payload list"));
@@
-94,29
+96,31
@@
SilcDList silc_channel_payload_parse_list(const unsigned char *payload,
list = silc_dlist_init();
while (buffer.len) {
list = silc_dlist_init();
while (buffer.len) {
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ goto err;
ret = silc_buffer_unformat(&buffer,
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI16_NSTRING_ALLOC(&new->channel_name,
- &new->name_len),
- SILC_STR_UI16_NSTRING_ALLOC(&new->channel_id,
- &new->id_len),
- SILC_STR_UI_INT(&new->mode),
+ SILC_STR_UI16_NSTRING_ALLOC(&new
p
->channel_name,
+ &new
p
->name_len),
+ SILC_STR_UI16_NSTRING_ALLOC(&new
p
->channel_id,
+ &new
p
->id_len),
+ SILC_STR_UI_INT(&new
p
->mode),
SILC_STR_END);
if (ret == -1)
goto err;
SILC_STR_END);
if (ret == -1)
goto err;
- if ((new
->name_len < 1 || new
->name_len > buffer.len) ||
- (new
->id_len < 1 || new
->id_len > buffer.len)) {
+ if ((new
p->name_len < 1 || newp
->name_len > buffer.len) ||
+ (new
p->id_len < 1 || newp
->id_len > buffer.len)) {
SILC_LOG_ERROR(("Incorrect channel payload in packet, packet dropped"));
goto err;
}
SILC_LOG_ERROR(("Incorrect channel payload in packet, packet dropped"));
goto err;
}
- len = 2 + new
->name_len + 2 + new
->id_len + 4;
+ len = 2 + new
p->name_len + 2 + newp
->id_len + 4;
if (buffer.len < len)
break;
silc_buffer_pull(&buffer, len);
if (buffer.len < len)
break;
silc_buffer_pull(&buffer, len);
- silc_dlist_add(list, new);
+ silc_dlist_add(list, new
p
);
}
return list;
}
return list;
@@
-138,8
+142,10
@@
SilcBuffer silc_channel_payload_encode(const unsigned char *channel_name,
SILC_LOG_DEBUG(("Encoding message payload"));
SILC_LOG_DEBUG(("Encoding message payload"));
- buffer = silc_buffer_alloc(2 + channel_name_len + 2 + channel_id_len + 4);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(2 + channel_name_len + 2 +
+ channel_id_len + 4);
+ if (!buffer)
+ return NULL;
/* Encode the Channel Payload */
silc_buffer_format(buffer,
/* Encode the Channel Payload */
silc_buffer_format(buffer,
@@
-260,10
+266,13
@@
bool silc_channel_message_payload_decrypt(unsigned char *data,
/* Allocate destination decryption buffer since we do not want to modify
the original data buffer, since we might want to call this function
many times for same payload. */
/* Allocate destination decryption buffer since we do not want to modify
the original data buffer, since we might want to call this function
many times for same payload. */
- if (hmac)
+ if (hmac)
{
dst = silc_calloc(data_len - iv_len, sizeof(*dst));
dst = silc_calloc(data_len - iv_len, sizeof(*dst));
- else
+ if (!dst)
+ return FALSE;
+ } else {
dst = data;
dst = data;
+ }
/* Decrypt the channel message */
silc_cipher_decrypt(cipher, data, dst, data_len - iv_len, iv);
/* Decrypt the channel message */
silc_cipher_decrypt(cipher, data, dst, data_len - iv_len, iv);
@@
-304,7
+313,7
@@
silc_channel_message_payload_parse(unsigned char *payload,
SilcHmac hmac)
{
SilcBufferStruct buffer;
SilcHmac hmac)
{
SilcBufferStruct buffer;
- SilcChannelMessagePayload new;
+ SilcChannelMessagePayload new
p
;
int ret;
SilcUInt32 iv_len, mac_len;
int ret;
SilcUInt32 iv_len, mac_len;
@@
-321,30
+330,32
@@
silc_channel_message_payload_parse(unsigned char *payload,
iv_len = silc_cipher_get_block_len(cipher);
mac_len = silc_hmac_len(hmac);
iv_len = silc_cipher_get_block_len(cipher);
mac_len = silc_hmac_len(hmac);
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
/* Parse the Channel Message Payload. Ignore the padding. */
ret = silc_buffer_unformat(&buffer,
/* Parse the Channel Message Payload. Ignore the padding. */
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI_SHORT(&new->flags),
- SILC_STR_UI16_NSTRING_ALLOC(&new->data,
- &new->data_len),
+ SILC_STR_UI_SHORT(&new
p
->flags),
+ SILC_STR_UI16_NSTRING_ALLOC(&new
p
->data,
+ &new
p
->data_len),
SILC_STR_UI16_NSTRING(NULL, NULL),
SILC_STR_UI16_NSTRING(NULL, NULL),
- SILC_STR_UI_XNSTRING(&new->mac, mac_len),
- SILC_STR_UI_XNSTRING(&new->iv, iv_len),
+ SILC_STR_UI_XNSTRING(&new
p
->mac, mac_len),
+ SILC_STR_UI_XNSTRING(&new
p
->iv, iv_len),
SILC_STR_END);
if (ret == -1)
goto err;
SILC_STR_END);
if (ret == -1)
goto err;
- if (new->data_len > buffer.len) {
+ if (new
p
->data_len > buffer.len) {
SILC_LOG_ERROR(("Incorrect channel message payload in packet, "
"packet dropped"));
goto err;
}
SILC_LOG_ERROR(("Incorrect channel message payload in packet, "
"packet dropped"));
goto err;
}
- return new;
+ return new
p
;
err:
err:
- silc_channel_message_payload_free(new);
+ silc_channel_message_payload_free(new
p
);
return NULL;
}
return NULL;
}
@@
-378,6
+389,8
@@
SilcBuffer silc_channel_message_payload_encode(SilcUInt16 flags,
/* Allocate channel payload buffer */
len += pad_len + iv_len;
buffer = silc_buffer_alloc(len);
/* Allocate channel payload buffer */
len += pad_len + iv_len;
buffer = silc_buffer_alloc(len);
+ if (!buffer)
+ return NULL;
/* Generate padding */
for (i = 0; i < pad_len; i++) pad[i] = silc_rng_global_get_byte();
/* Generate padding */
for (i = 0; i < pad_len; i++) pad[i] = silc_rng_global_get_byte();
@@
-482,40
+495,43
@@
silc_channel_key_payload_parse(const unsigned char *payload,
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
- SilcChannelKeyPayload new;
+ SilcChannelKeyPayload new
p
;
int ret;
SILC_LOG_DEBUG(("Parsing channel key payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
int ret;
SILC_LOG_DEBUG(("Parsing channel key payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
/* Parse the Channel Key Payload */
ret =
silc_buffer_unformat(&buffer,
/* Parse the Channel Key Payload */
ret =
silc_buffer_unformat(&buffer,
- SILC_STR_UI16_NSTRING_ALLOC(&new->id, &new->id_len),
- SILC_STR_UI16_NSTRING_ALLOC(&new->cipher,
- &new->cipher_len),
- SILC_STR_UI16_NSTRING_ALLOC(&new->key, &new->key_len),
+ SILC_STR_UI16_NSTRING_ALLOC(&newp->id, &newp->id_len),
+ SILC_STR_UI16_NSTRING_ALLOC(&newp->cipher,
+ &newp->cipher_len),
+ SILC_STR_UI16_NSTRING_ALLOC(&newp->key,
+ &newp->key_len),
SILC_STR_END);
if (ret == -1)
goto err;
SILC_STR_END);
if (ret == -1)
goto err;
- if (new
->id_len < 1 || new->key_len < 1 || new
->cipher_len < 1) {
+ if (new
p->id_len < 1 || newp->key_len < 1 || newp
->cipher_len < 1) {
SILC_LOG_ERROR(("Incorrect channel key payload in packet"));
goto err;
}
SILC_LOG_ERROR(("Incorrect channel key payload in packet"));
goto err;
}
- return new;
+ return new
p
;
err:
err:
- if (new->id)
- silc_free(new->id);
- if (new->cipher)
- silc_free(new->cipher);
- if (new->key)
- silc_free(new->key);
- silc_free(new);
+ if (new
p
->id)
+ silc_free(new
p
->id);
+ if (new
p
->cipher)
+ silc_free(new
p
->cipher);
+ if (new
p
->key)
+ silc_free(new
p
->key);
+ silc_free(new
p
);
return NULL;
}
return NULL;
}
@@
-537,9
+553,9
@@
SilcBuffer silc_channel_key_payload_encode(SilcUInt16 id_len,
/* Allocate channel payload buffer. Length is 2 + id + 2 + key +
2 + cipher */
len = 2 + id_len + 2 + key_len + 2 + cipher_len;
/* Allocate channel payload buffer. Length is 2 + id + 2 + key +
2 + cipher */
len = 2 + id_len + 2 + key_len + 2 + cipher_len;
- buffer = silc_buffer_alloc(len);
-
-
silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer))
;
+ buffer = silc_buffer_alloc
_size
(len);
+ if (!buffer)
+
return NULL
;
/* Encode the Channel Payload */
silc_buffer_format(buffer,
/* Encode the Channel Payload */
silc_buffer_format(buffer,
diff --git
a/lib/silccore/silccommand.c
b/lib/silccore/silccommand.c
index 50d96200eddc547736e9604514524af7479de95a..aaa190c2732e1a04b30b457386553f96a1ab1161 100644
(file)
--- a/
lib/silccore/silccommand.c
+++ b/
lib/silccore/silccommand.c
@@
-45,7
+45,7
@@
SilcCommandPayload silc_command_payload_parse(const unsigned char *payload,
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
- SilcCommandPayload new;
+ SilcCommandPayload new
p
;
unsigned char args_num;
SilcUInt16 p_len;
int ret;
unsigned char args_num;
SilcUInt16 p_len;
int ret;
@@
-53,42
+53,44
@@
SilcCommandPayload silc_command_payload_parse(const unsigned char *payload,
SILC_LOG_DEBUG(("Parsing command payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
SILC_LOG_DEBUG(("Parsing command payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
/* Parse the Command Payload */
ret = silc_buffer_unformat(&buffer,
SILC_STR_UI_SHORT(&p_len),
/* Parse the Command Payload */
ret = silc_buffer_unformat(&buffer,
SILC_STR_UI_SHORT(&p_len),
- SILC_STR_UI_CHAR(&new->cmd),
+ SILC_STR_UI_CHAR(&new
p
->cmd),
SILC_STR_UI_CHAR(&args_num),
SILC_STR_UI_CHAR(&args_num),
- SILC_STR_UI_SHORT(&new->ident),
+ SILC_STR_UI_SHORT(&new
p
->ident),
SILC_STR_END);
if (ret == -1) {
SILC_STR_END);
if (ret == -1) {
- silc_free(new);
+ silc_free(new
p
);
return NULL;
}
if (p_len != buffer.len) {
SILC_LOG_ERROR(("Incorrect command payload in packet, packet dropped"));
return NULL;
}
if (p_len != buffer.len) {
SILC_LOG_ERROR(("Incorrect command payload in packet, packet dropped"));
- silc_free(new);
+ silc_free(new
p
);
return NULL;
}
return NULL;
}
- if (new->cmd == 0) {
- silc_free(new);
+ if (new
p
->cmd == 0) {
+ silc_free(new
p
);
return NULL;
}
silc_buffer_pull(&buffer, SILC_COMMAND_PAYLOAD_LEN);
if (args_num) {
return NULL;
}
silc_buffer_pull(&buffer, SILC_COMMAND_PAYLOAD_LEN);
if (args_num) {
- new->args = silc_argument_payload_parse(buffer.data, buffer.len, args_num);
- if (!new->args) {
- silc_free(new);
+ new
p
->args = silc_argument_payload_parse(buffer.data, buffer.len, args_num);
+ if (!new
p
->args) {
+ silc_free(new
p
);
return NULL;
}
}
silc_buffer_push(&buffer, SILC_COMMAND_PAYLOAD_LEN);
return NULL;
}
}
silc_buffer_push(&buffer, SILC_COMMAND_PAYLOAD_LEN);
- return new;
+ return new
p
;
}
/* Encodes Command Payload returning it to SilcBuffer. */
}
/* Encodes Command Payload returning it to SilcBuffer. */
@@
-112,8
+114,9
@@
SilcBuffer silc_command_payload_encode(SilcCommand cmd,
}
len += SILC_COMMAND_PAYLOAD_LEN;
}
len += SILC_COMMAND_PAYLOAD_LEN;
- buffer = silc_buffer_alloc(len);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(len);
+ if (!buffer)
+ return NULL;
/* Create Command payload */
silc_buffer_format(buffer,
/* Create Command payload */
silc_buffer_format(buffer,
@@
-155,8
+158,12
@@
SilcBuffer silc_command_payload_encode_payload(SilcCommandPayload payload)
}
len += SILC_COMMAND_PAYLOAD_LEN;
}
len += SILC_COMMAND_PAYLOAD_LEN;
- buffer = silc_buffer_alloc(len);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(len);
+ if (!buffer) {
+ if (args)
+ silc_buffer_free(args);
+ return NULL;
+ }
/* Create Command payload */
silc_buffer_format(buffer,
/* Create Command payload */
silc_buffer_format(buffer,
@@
-212,13
+219,19
@@
SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
unsigned char *x;
SilcUInt32 x_len;
SilcUInt32 x_type;
unsigned char *x;
SilcUInt32 x_len;
SilcUInt32 x_type;
- SilcBuffer buffer;
+ SilcBuffer buffer
= NULL
;
int i, k = 0;
if (argc) {
argv = silc_calloc(argc, sizeof(unsigned char *));
int i, k = 0;
if (argc) {
argv = silc_calloc(argc, sizeof(unsigned char *));
+ if (!argv)
+ return NULL;
argv_lens = silc_calloc(argc, sizeof(SilcUInt32));
argv_lens = silc_calloc(argc, sizeof(SilcUInt32));
+ if (!argv_lens)
+ return NULL;
argv_types = silc_calloc(argc, sizeof(SilcUInt32));
argv_types = silc_calloc(argc, sizeof(SilcUInt32));
+ if (!argv_types)
+ return NULL;
for (i = 0, k = 0; i < argc; i++) {
x_type = va_arg(ap, SilcUInt32);
for (i = 0, k = 0; i < argc; i++) {
x_type = va_arg(ap, SilcUInt32);
@@
-229,6
+242,8
@@
SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
continue;
argv[k] = silc_memdup(x, x_len);
continue;
argv[k] = silc_memdup(x, x_len);
+ if (!argv[k])
+ goto out;
argv_lens[k] = x_len;
argv_types[k] = x_type;
k++;
argv_lens[k] = x_len;
argv_types[k] = x_type;
k++;
@@
-238,6
+253,7
@@
SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
buffer = silc_command_payload_encode(cmd, k, argv, argv_lens,
argv_types, ident);
buffer = silc_command_payload_encode(cmd, k, argv, argv_lens,
argv_types, ident);
+ out:
for (i = 0; i < k; i++)
silc_free(argv[i]);
silc_free(argv);
for (i = 0; i < k; i++)
silc_free(argv[i]);
silc_free(argv);
@@
-280,16
+296,33
@@
silc_command_reply_payload_encode_vap(SilcCommand cmd,
unsigned char *x;
SilcUInt32 x_len;
SilcUInt32 x_type;
unsigned char *x;
SilcUInt32 x_len;
SilcUInt32 x_type;
- SilcBuffer buffer;
+ SilcBuffer buffer
= NULL
;
int i, k;
argc++;
argv = silc_calloc(argc, sizeof(unsigned char *));
int i, k;
argc++;
argv = silc_calloc(argc, sizeof(unsigned char *));
+ if (!argv)
+ return NULL;
argv_lens = silc_calloc(argc, sizeof(SilcUInt32));
argv_lens = silc_calloc(argc, sizeof(SilcUInt32));
+ if (!argv_lens) {
+ silc_free(argv);
+ return NULL;
+ }
argv_types = silc_calloc(argc, sizeof(SilcUInt32));
argv_types = silc_calloc(argc, sizeof(SilcUInt32));
+ if (!argv_types) {
+ silc_free(argv_lens);
+ silc_free(argv);
+ return NULL;
+ }
SILC_PUT16_MSB(status, status_data);
argv[0] = silc_memdup(status_data, sizeof(status_data));
SILC_PUT16_MSB(status, status_data);
argv[0] = silc_memdup(status_data, sizeof(status_data));
+ if (!argv[0]) {
+ silc_free(argv_types);
+ silc_free(argv_lens);
+ silc_free(argv);
+ return NULL;
+ }
argv_lens[0] = sizeof(status_data);
argv_types[0] = 1;
argv_lens[0] = sizeof(status_data);
argv_types[0] = 1;
@@
-302,6
+335,8
@@
silc_command_reply_payload_encode_vap(SilcCommand cmd,
continue;
argv[k] = silc_memdup(x, x_len);
continue;
argv[k] = silc_memdup(x, x_len);
+ if (!argv[k])
+ goto out;
argv_lens[k] = x_len;
argv_types[k] = x_type;
k++;
argv_lens[k] = x_len;
argv_types[k] = x_type;
k++;
@@
-310,6
+345,7
@@
silc_command_reply_payload_encode_vap(SilcCommand cmd,
buffer = silc_command_payload_encode(cmd, k, argv, argv_lens,
argv_types, ident);
buffer = silc_command_payload_encode(cmd, k, argv, argv_lens,
argv_types, ident);
+ out:
for (i = 0; i < k; i++)
silc_free(argv[i]);
silc_free(argv);
for (i = 0; i < k; i++)
silc_free(argv[i]);
silc_free(argv);
diff --git
a/lib/silccore/silcid.c
b/lib/silccore/silcid.c
index 655601efffc5ce0ff65afd0b3b6cacc9da204b8c..870400638b721c0fdc712e5ccd983163b7768153 100644
(file)
--- a/
lib/silccore/silcid.c
+++ b/
lib/silccore/silcid.c
@@
-45,38
+45,40
@@
SilcIDPayload silc_id_payload_parse(const unsigned char *payload,
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
- SilcIDPayload new;
+ SilcIDPayload new
p
;
int ret;
SILC_LOG_DEBUG(("Parsing ID payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
int ret;
SILC_LOG_DEBUG(("Parsing ID payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
ret = silc_buffer_unformat(&buffer,
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI_SHORT(&new->type),
- SILC_STR_UI_SHORT(&new->len),
+ SILC_STR_UI_SHORT(&new
p
->type),
+ SILC_STR_UI_SHORT(&new
p
->len),
SILC_STR_END);
if (ret == -1)
goto err;
silc_buffer_pull(&buffer, 4);
SILC_STR_END);
if (ret == -1)
goto err;
silc_buffer_pull(&buffer, 4);
- if (new->len > buffer.len)
+ if (new
p
->len > buffer.len)
goto err;
ret = silc_buffer_unformat(&buffer,
goto err;
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI_XNSTRING_ALLOC(&new
->id, new
->len),
+ SILC_STR_UI_XNSTRING_ALLOC(&new
p->id, newp
->len),
SILC_STR_END);
if (ret == -1)
goto err;
silc_buffer_push(&buffer, 4);
SILC_STR_END);
if (ret == -1)
goto err;
silc_buffer_push(&buffer, 4);
- return new;
+ return new
p
;
err:
err:
- silc_free(new);
+ silc_free(new
p
);
return NULL;
}
return NULL;
}
@@
-143,8
+145,9
@@
SilcBuffer silc_id_payload_encode_data(const unsigned char *id,
type == SILC_ID_CLIENT ? "Client" :
type == SILC_ID_SERVER ? "Server" : "Channel"));
type == SILC_ID_CLIENT ? "Client" :
type == SILC_ID_SERVER ? "Server" : "Channel"));
- buffer = silc_buffer_alloc(4 + id_len);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(4 + id_len);
+ if (!buffer)
+ return NULL;
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(type),
SILC_STR_UI_SHORT(id_len),
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(type),
SILC_STR_UI_SHORT(id_len),
@@
-209,6
+212,8
@@
unsigned char *silc_id_id2str(const void *id, SilcIdType type)
case SILC_ID_SERVER:
server_id = (SilcServerID *)id;
ret_id = silc_calloc(id_len, sizeof(unsigned char));
case SILC_ID_SERVER:
server_id = (SilcServerID *)id;
ret_id = silc_calloc(id_len, sizeof(unsigned char));
+ if (!ret_id)
+ return NULL;
memcpy(ret_id, server_id->ip.data, server_id->ip.data_len);
SILC_PUT16_MSB(server_id->port, &ret_id[4]);
SILC_PUT16_MSB(server_id->rnd, &ret_id[6]);
memcpy(ret_id, server_id->ip.data, server_id->ip.data_len);
SILC_PUT16_MSB(server_id->port, &ret_id[4]);
SILC_PUT16_MSB(server_id->rnd, &ret_id[6]);
@@
-217,6
+222,8
@@
unsigned char *silc_id_id2str(const void *id, SilcIdType type)
case SILC_ID_CLIENT:
client_id = (SilcClientID *)id;
ret_id = silc_calloc(id_len, sizeof(unsigned char));
case SILC_ID_CLIENT:
client_id = (SilcClientID *)id;
ret_id = silc_calloc(id_len, sizeof(unsigned char));
+ if (!ret_id)
+ return NULL;
memcpy(ret_id, client_id->ip.data, client_id->ip.data_len);
ret_id[4] = client_id->rnd;
memcpy(&ret_id[5], client_id->hash, CLIENTID_HASH_LEN);
memcpy(ret_id, client_id->ip.data, client_id->ip.data_len);
ret_id[4] = client_id->rnd;
memcpy(&ret_id[5], client_id->hash, CLIENTID_HASH_LEN);
@@
-225,6
+232,8
@@
unsigned char *silc_id_id2str(const void *id, SilcIdType type)
case SILC_ID_CHANNEL:
channel_id = (SilcChannelID *)id;
ret_id = silc_calloc(id_len, sizeof(unsigned char));
case SILC_ID_CHANNEL:
channel_id = (SilcChannelID *)id;
ret_id = silc_calloc(id_len, sizeof(unsigned char));
+ if (!ret_id)
+ return NULL;
memcpy(ret_id, channel_id->ip.data, channel_id->ip.data_len);
SILC_PUT16_MSB(channel_id->port, &ret_id[4]);
SILC_PUT16_MSB(channel_id->rnd, &ret_id[6]);
memcpy(ret_id, channel_id->ip.data, channel_id->ip.data_len);
SILC_PUT16_MSB(channel_id->port, &ret_id[4]);
SILC_PUT16_MSB(channel_id->rnd, &ret_id[6]);
@@
-250,6
+259,8
@@
void *silc_id_str2id(const unsigned char *id, SilcUInt32 id_len, SilcIdType type
return NULL;
server_id = silc_calloc(1, sizeof(*server_id));
return NULL;
server_id = silc_calloc(1, sizeof(*server_id));
+ if (!server_id)
+ return NULL;
memcpy(server_id->ip.data, id, (id_len > ID_SERVER_LEN_PART + 4 ?
16 : 4));
server_id->ip.data_len = (id_len > ID_SERVER_LEN_PART + 4 ? 16 : 4);
memcpy(server_id->ip.data, id, (id_len > ID_SERVER_LEN_PART + 4 ?
16 : 4));
server_id->ip.data_len = (id_len > ID_SERVER_LEN_PART + 4 ? 16 : 4);
@@
-267,6
+278,8
@@
void *silc_id_str2id(const unsigned char *id, SilcUInt32 id_len, SilcIdType type
return NULL;
client_id = silc_calloc(1, sizeof(*client_id));
return NULL;
client_id = silc_calloc(1, sizeof(*client_id));
+ if (!client_id)
+ return NULL;
memcpy(client_id->ip.data, id, (id_len > ID_CLIENT_LEN_PART + 4 ?
16 : 4));
client_id->ip.data_len = (id_len > ID_CLIENT_LEN_PART + 4 ? 16 : 4);
memcpy(client_id->ip.data, id, (id_len > ID_CLIENT_LEN_PART + 4 ?
16 : 4));
client_id->ip.data_len = (id_len > ID_CLIENT_LEN_PART + 4 ? 16 : 4);
@@
-284,6
+297,8
@@
void *silc_id_str2id(const unsigned char *id, SilcUInt32 id_len, SilcIdType type
return NULL;
channel_id = silc_calloc(1, sizeof(*channel_id));
return NULL;
channel_id = silc_calloc(1, sizeof(*channel_id));
+ if (!channel_id)
+ return NULL;
memcpy(channel_id->ip.data, id, (id_len > ID_CHANNEL_LEN_PART + 4 ?
16 : 4));
channel_id->ip.data_len = (id_len > ID_CHANNEL_LEN_PART + 4 ? 16 : 4);
memcpy(channel_id->ip.data, id, (id_len > ID_CHANNEL_LEN_PART + 4 ?
16 : 4));
channel_id->ip.data_len = (id_len > ID_CHANNEL_LEN_PART + 4 ? 16 : 4);
diff --git
a/lib/silccore/silcidcache.c
b/lib/silccore/silcidcache.c
index a28c6833034bc19cc92c0d2073593b1612f6cb94..65ef13380bbf3194193cf07dcd3c965ef6e987e7 100644
(file)
--- a/
lib/silccore/silcidcache.c
+++ b/
lib/silccore/silcidcache.c
@@
-106,6
+106,8
@@
SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type,
SILC_LOG_DEBUG(("Allocating new cache"));
cache = silc_calloc(1, sizeof(*cache));
SILC_LOG_DEBUG(("Allocating new cache"));
cache = silc_calloc(1, sizeof(*cache));
+ if (!cache)
+ return NULL;
cache->id_table = silc_hash_table_alloc(count, silc_hash_id,
(void *)(SilcUInt32)id_type,
silc_hash_id_compare,
cache->id_table = silc_hash_table_alloc(count, silc_hash_id,
(void *)(SilcUInt32)id_type,
silc_hash_id_compare,
@@
-120,6
+122,17
@@
SilcIDCache silc_idcache_alloc(SilcUInt32 count, SilcIdType id_type,
cache->destructor = destructor;
cache->type = id_type;
cache->destructor = destructor;
cache->type = id_type;
+ if (!cache->id_table || !cache->name_table || !cache->context_table) {
+ if (cache->id_table)
+ silc_hash_table_free(cache->id_table);
+ if (cache->name_table)
+ silc_hash_table_free(cache->name_table);
+ if (cache->context_table)
+ silc_hash_table_free(cache->context_table);
+ silc_free(cache);
+ return NULL;
+ }
+
return cache;
}
return cache;
}
@@
-150,6
+163,8
@@
bool silc_idcache_add(SilcIDCache cache, char *name, void *id,
/* Allocate new cache entry */
c = silc_calloc(1, sizeof(*c));
/* Allocate new cache entry */
c = silc_calloc(1, sizeof(*c));
+ if (!c)
+ return FALSE;
c->id = id;
c->name = name;
c->expire = expire;
c->id = id;
c->name = name;
c->expire = expire;
@@
-380,6
+395,8
@@
bool silc_idcache_get_all(SilcIDCache cache, SilcIDCacheList *ret)
return TRUE;
list = silc_idcache_list_alloc();
return TRUE;
list = silc_idcache_list_alloc();
+ if (!list)
+ return FALSE;
silc_hash_table_foreach(cache->id_table, silc_idcache_get_all_foreach, list);
if (silc_idcache_list_count(list) == 0) {
silc_hash_table_foreach(cache->id_table, silc_idcache_get_all_foreach, list);
if (silc_idcache_list_count(list) == 0) {
@@
-400,6
+417,8
@@
bool silc_idcache_find_by_id(SilcIDCache cache, void *id,
SilcIDCacheList list;
list = silc_idcache_list_alloc();
SilcIDCacheList list;
list = silc_idcache_list_alloc();
+ if (!list)
+ return FALSE;
if (!ret)
return TRUE;
if (!ret)
return TRUE;
@@
-458,6
+477,8
@@
bool silc_idcache_find_by_name(SilcIDCache cache, char *name,
SilcIDCacheList list;
list = silc_idcache_list_alloc();
SilcIDCacheList list;
list = silc_idcache_list_alloc();
+ if (!list)
+ return FALSE;
if (!ret)
return TRUE;
if (!ret)
return TRUE;
@@
-493,6
+514,8
@@
static SilcIDCacheList silc_idcache_list_alloc()
SilcIDCacheList list;
list = silc_calloc(1, sizeof(*list));
SilcIDCacheList list;
list = silc_calloc(1, sizeof(*list));
+ if (!list)
+ return FALSE;
return list;
}
return list;
}
@@
-529,6
+552,8
@@
static void silc_idcache_list_add(SilcIDCacheList list, SilcIDCacheEntry cache)
i = list->cache_dyn_count;
list->cache_dyn = silc_realloc(list->cache_dyn,
sizeof(*list->cache_dyn) * (i + 5));
i = list->cache_dyn_count;
list->cache_dyn = silc_realloc(list->cache_dyn,
sizeof(*list->cache_dyn) * (i + 5));
+ if (!list->cache_dyn)
+ return;
/* NULL the reallocated area */
for (k = i; k < (i + 5); k++)
/* NULL the reallocated area */
for (k = i; k < (i + 5); k++)
diff --git
a/lib/silccore/silcnotify.c
b/lib/silccore/silcnotify.c
index 44552d564d1b2352030cb96b5f1dd4c819826eb3..549f7e0a9c3a507dcfbcdda90a614c14c768f438 100644
(file)
--- a/
lib/silccore/silcnotify.c
+++ b/
lib/silccore/silcnotify.c
@@
-40,19
+40,21
@@
SilcNotifyPayload silc_notify_payload_parse(const unsigned char *payload,
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
SilcUInt32 payload_len)
{
SilcBufferStruct buffer;
- SilcNotifyPayload new;
+ SilcNotifyPayload new
p
;
SilcUInt16 len;
int ret;
SILC_LOG_DEBUG(("Parsing Notify payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
SilcUInt16 len;
int ret;
SILC_LOG_DEBUG(("Parsing Notify payload"));
silc_buffer_set(&buffer, (unsigned char *)payload, payload_len);
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
ret = silc_buffer_unformat(&buffer,
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI_SHORT(&new->type),
+ SILC_STR_UI_SHORT(&new
p
->type),
SILC_STR_UI_SHORT(&len),
SILC_STR_UI_SHORT(&len),
- SILC_STR_UI_CHAR(&new->argc),
+ SILC_STR_UI_CHAR(&new
p
->argc),
SILC_STR_END);
if (ret == -1)
goto err;
SILC_STR_END);
if (ret == -1)
goto err;
@@
-60,17
+62,17
@@
SilcNotifyPayload silc_notify_payload_parse(const unsigned char *payload,
if (len > buffer.len)
goto err;
if (len > buffer.len)
goto err;
- if (new->argc) {
+ if (new
p
->argc) {
silc_buffer_pull(&buffer, 5);
silc_buffer_pull(&buffer, 5);
- new->args = silc_argument_payload_parse(buffer.data, buffer.len,
- new->argc);
+ new
p
->args = silc_argument_payload_parse(buffer.data, buffer.len,
+ new
p
->argc);
silc_buffer_push(&buffer, 5);
}
silc_buffer_push(&buffer, 5);
}
- return new;
+ return new
p
;
err:
err:
- silc_free(new);
+ silc_free(new
p
);
return NULL;
}
return NULL;
}
@@
-91,8
+93,19
@@
SilcBuffer silc_notify_payload_encode(SilcNotifyType type, SilcUInt32 argc,
if (argc) {
argv = silc_calloc(argc, sizeof(unsigned char *));
if (argc) {
argv = silc_calloc(argc, sizeof(unsigned char *));
+ if (!argv)
+ return NULL;
argv_lens = silc_calloc(argc, sizeof(SilcUInt32));
argv_lens = silc_calloc(argc, sizeof(SilcUInt32));
+ if (!argv_lens) {
+ silc_free(argv);
+ return NULL;
+ }
argv_types = silc_calloc(argc, sizeof(SilcUInt32));
argv_types = silc_calloc(argc, sizeof(SilcUInt32));
+ if (!argv_types) {
+ silc_free(argv_lens);
+ silc_free(argv);
+ return NULL;
+ }
for (i = 0, k = 0; i < argc; i++) {
x = va_arg(ap, unsigned char *);
for (i = 0, k = 0; i < argc; i++) {
x = va_arg(ap, unsigned char *);
@@
-102,6
+115,8
@@
SilcBuffer silc_notify_payload_encode(SilcNotifyType type, SilcUInt32 argc,
continue;
argv[k] = silc_memdup(x, x_len);
continue;
argv[k] = silc_memdup(x, x_len);
+ if (!argv[k])
+ return NULL;
argv_lens[k] = x_len;
argv_types[k] = i + 1;
k++;
argv_lens[k] = x_len;
argv_types[k] = i + 1;
k++;
@@
-118,8
+133,9
@@
SilcBuffer silc_notify_payload_encode(SilcNotifyType type, SilcUInt32 argc,
}
len += 5;
}
len += 5;
- buffer = silc_buffer_alloc(len);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(len);
+ if (!buffer)
+ return NULL;
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(type),
SILC_STR_UI_SHORT(len),
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(type),
SILC_STR_UI_SHORT(len),
@@
-148,8
+164,9
@@
SilcBuffer silc_notify_payload_encode_args(SilcNotifyType type,
int len;
len = 5 + (args ? args->len : 0);
int len;
len = 5 + (args ? args->len : 0);
- buffer = silc_buffer_alloc(len);
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+ buffer = silc_buffer_alloc_size(len);
+ if (!buffer)
+ return NULL;
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(type),
SILC_STR_UI_SHORT(len),
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(type),
SILC_STR_UI_SHORT(len),
diff --git
a/lib/silccore/silcpacket.c
b/lib/silccore/silcpacket.c
index 7f72922b5d6c4aac3de4ecbde37d0dfaa933c16e..c8e17e601a823988894829c2eefe7d3003c4a4e6 100644
(file)
--- a/
lib/silccore/silcpacket.c
+++ b/
lib/silccore/silcpacket.c
@@
-377,6
+377,8
@@
bool silc_packet_receive_process(SilcSocketConnection sock,
SILC_UNSET_INBUF_PENDING(sock);
parse_ctx = silc_calloc(1, sizeof(*parse_ctx));
SILC_UNSET_INBUF_PENDING(sock);
parse_ctx = silc_calloc(1, sizeof(*parse_ctx));
+ if (!parse_ctx)
+ return FALSE;
parse_ctx->packet = silc_packet_context_alloc();
parse_ctx->packet->buffer = silc_buffer_alloc(paddedlen + mac_len);
parse_ctx->packet->type = sock->inbuf->data[3];
parse_ctx->packet = silc_packet_context_alloc();
parse_ctx->packet->buffer = silc_buffer_alloc(paddedlen + mac_len);
parse_ctx->packet->type = sock->inbuf->data[3];
@@
-746,6
+748,8
@@
SilcPacketType silc_packet_parse_special(SilcPacketContext *ctx,
SilcPacketContext *silc_packet_context_alloc(void)
{
SilcPacketContext *ctx = silc_calloc(1, sizeof(*ctx));
SilcPacketContext *silc_packet_context_alloc(void)
{
SilcPacketContext *ctx = silc_calloc(1, sizeof(*ctx));
+ if (!ctx)
+ return NULL;
ctx->users++;
return ctx;
}
ctx->users++;
return ctx;
}
diff --git
a/lib/silccore/silcprivate.c
b/lib/silccore/silcprivate.c
index 26a064297028477ee2dba73f94da60fce0220509..fa9bfa9e926e9af2249344600b84efbdc507de4d 100644
(file)
--- a/
lib/silccore/silcprivate.c
+++ b/
lib/silccore/silcprivate.c
@@
-48,7
+48,7
@@
silc_private_message_payload_parse(unsigned char *payload,
SilcCipher cipher)
{
SilcBufferStruct buffer;
SilcCipher cipher)
{
SilcBufferStruct buffer;
- SilcPrivateMessagePayload new;
+ SilcPrivateMessagePayload new
p
;
int ret;
SILC_LOG_DEBUG(("Parsing private message payload"));
int ret;
SILC_LOG_DEBUG(("Parsing private message payload"));
@@
-60,29
+60,31
@@
silc_private_message_payload_parse(unsigned char *payload,
silc_cipher_decrypt(cipher, buffer.data, buffer.data,
buffer.len, cipher->iv);
silc_cipher_decrypt(cipher, buffer.data, buffer.data,
buffer.len, cipher->iv);
- new = silc_calloc(1, sizeof(*new));
+ newp = silc_calloc(1, sizeof(*newp));
+ if (!newp)
+ return NULL;
/* Parse the Private Message Payload. Ignore the padding. */
ret = silc_buffer_unformat(&buffer,
/* Parse the Private Message Payload. Ignore the padding. */
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI_SHORT(&new->flags),
- SILC_STR_UI16_NSTRING_ALLOC(&new->message,
- &new->message_len),
+ SILC_STR_UI_SHORT(&new
p
->flags),
+ SILC_STR_UI16_NSTRING_ALLOC(&new
p
->message,
+ &new
p
->message_len),
SILC_STR_END);
if (ret == -1) {
SILC_LOG_DEBUG(("Incorrect private message payload"));
goto err;
}
SILC_STR_END);
if (ret == -1) {
SILC_LOG_DEBUG(("Incorrect private message payload"));
goto err;
}
- if ((new
->message_len < 1 || new
->message_len > buffer.len)) {
+ if ((new
p->message_len < 1 || newp
->message_len > buffer.len)) {
SILC_LOG_DEBUG(("Incorrect private message payload in packet, "
"packet dropped"));
goto err;
}
SILC_LOG_DEBUG(("Incorrect private message payload in packet, "
"packet dropped"));
goto err;
}
- return new;
+ return new
p
;
err:
err:
- silc_private_message_payload_free(new);
+ silc_private_message_payload_free(new
p
);
return NULL;
}
return NULL;
}
@@
-114,10
+116,11
@@
SilcBuffer silc_private_message_payload_encode(SilcUInt16 flags,
}
/* Allocate private message payload buffer */
}
/* Allocate private message payload buffer */
- buffer = silc_buffer_alloc(len);
+ buffer = silc_buffer_alloc_size(len);
+ if (!buffer)
+ return NULL;
/* Encode the Channel Message Payload */
/* Encode the Channel Message Payload */
- silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(flags),
SILC_STR_UI_SHORT(data_len),
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(flags),
SILC_STR_UI_SHORT(data_len),
diff --git
a/lib/silcutil/silcbuffer.h
b/lib/silcutil/silcbuffer.h
index 8d39ec81ce0650f9f9e518cd2828271882a5cee9..b495296e613240dfeefec9282789a15ab2ab7743 100644
(file)
--- a/
lib/silcutil/silcbuffer.h
+++ b/
lib/silcutil/silcbuffer.h
@@
-134,9
+134,13
@@
SilcBuffer silc_buffer_alloc(SilcUInt32 len)
/* Allocate new SilcBuffer */
sb = (SilcBuffer)silc_calloc(1, sizeof(*sb));
/* Allocate new SilcBuffer */
sb = (SilcBuffer)silc_calloc(1, sizeof(*sb));
+ if (!sb)
+ return NULL;
/* Allocate the actual data area */
sb->head = (unsigned char *)silc_calloc(len, sizeof(*sb->head));
/* Allocate the actual data area */
sb->head = (unsigned char *)silc_calloc(len, sizeof(*sb->head));
+ if (!sb->head)
+ return NULL;
/* Set pointers to the new buffer */
sb->truelen = len;
/* Set pointers to the new buffer */
sb->truelen = len;
@@
-366,6
+370,20
@@
unsigned char *silc_buffer_put_tail(SilcBuffer sb,
return (unsigned char *)memcpy(sb->tail, data, len);
}
return (unsigned char *)memcpy(sb->tail, data, len);
}
+/* Allocates `len' bytes size buffer and moves the tail area automaticlly
+ `len' bytes so that the buffer is ready to use without calling the
+ silc_buffer_pull_tail. */
+
+static inline
+SilcBuffer silc_buffer_alloc_size(SilcUInt32 len)
+{
+ SilcBuffer sb = silc_buffer_alloc(len);
+ if (!sb)
+ return NULL;
+ silc_buffer_pull_tail(sb, len);
+ return sb;
+}
+
/* Clears and initialiazes the buffer to the state as if it was just
allocated by silc_buffer_alloc. */
/* Clears and initialiazes the buffer to the state as if it was just
allocated by silc_buffer_alloc. */
@@
-387,8
+405,9
@@
SilcBuffer silc_buffer_copy(SilcBuffer sb)
{
SilcBuffer sb_new;
{
SilcBuffer sb_new;
- sb_new = silc_buffer_alloc(sb->len);
- silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
+ sb_new = silc_buffer_alloc_size(sb->len);
+ if (!sb_new)
+ return NULL;
silc_buffer_put(sb_new, sb->data, sb->len);
return sb_new;
silc_buffer_put(sb_new, sb->data, sb->len);
return sb_new;
@@
-403,8
+422,9
@@
SilcBuffer silc_buffer_clone(SilcBuffer sb)
{
SilcBuffer sb_new;
{
SilcBuffer sb_new;
- sb_new = silc_buffer_alloc(sb->truelen);
- silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
+ sb_new = silc_buffer_alloc_size(sb->truelen);
+ if (!sb_new)
+ return NULL;
silc_buffer_put(sb_new, sb->head, sb->truelen);
sb_new->data = sb_new->head + (sb->data - sb->head);
sb_new->tail = sb_new->data + sb->len;
silc_buffer_put(sb_new, sb->head, sb->truelen);
sb_new->data = sb_new->head + (sb->data - sb->head);
sb_new->tail = sb_new->data + sb->len;
@@
-428,8
+448,9
@@
SilcBuffer silc_buffer_realloc(SilcBuffer sb, SilcUInt32 newsize)
if (newsize <= sb->truelen)
return sb;
if (newsize <= sb->truelen)
return sb;
- sb_new = silc_buffer_alloc(newsize);
- silc_buffer_pull_tail(sb_new, SILC_BUFFER_END(sb_new));
+ sb_new = silc_buffer_alloc_size(newsize);
+ if (!sb_new)
+ return NULL;
silc_buffer_put(sb_new, sb->head, sb->truelen);
sb_new->data = sb_new->head + (sb->data - sb->head);
sb_new->tail = sb_new->data + sb->len;
silc_buffer_put(sb_new, sb->head, sb->truelen);
sb_new->data = sb_new->head + (sb->data - sb->head);
sb_new->tail = sb_new->data + sb->len;