return GNUNET_SYSERR;
if (IDNA_SUCCESS !=
- (rc = idna_to_ascii_8z (name, &idna_start, IDNA_ALLOW_UNASSIGNED)))
+ (rc = idna_to_ascii_8z (name,
+ &idna_start,
+ IDNA_ALLOW_UNASSIGNED)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Failed to convert UTF-8 name `%s' to DNS IDNA format: %s\n"),
goto fail; /* segment too long or empty */
}
dst[pos++] = (char) (uint8_t) len;
- GNUNET_memcpy (&dst[pos], idna_name, len);
+ GNUNET_memcpy (&dst[pos],
+ idna_name,
+ len);
pos += len;
idna_name += len + 1; /* also skip dot */
}
size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg);
uint32_t rd_count = ntohl (lookup_msg->rd_count);
struct GNUNET_GNSRECORD_Data rd[rd_count];
-
+
(void) cls;
if (GNUNET_SYSERR ==
GNUNET_GNSRECORD_records_deserialize (mlen,
return;
proc = lr->lookup_proc;
proc_cls = lr->proc_cls;
-
+
GNUNET_assert (GNUNET_OK ==
GNUNET_GNSRECORD_records_deserialize (mlen,
(const char*) &lookup_msg[1],
void __attribute__ ((destructor))
GNSRECORD_fini ()
{
- unsigned int i;
struct Plugin *plugin;
- for (i = 0; i < num_plugins; i++)
+ for (unsigned int i = 0; i < num_plugins; i++)
{
plugin = gns_plugins[i];
GNUNET_break (NULL ==
const void *data,
size_t data_size)
{
- unsigned int i;
struct Plugin *plugin;
char *ret;
init ();
- for (i = 0; i < num_plugins; i++)
+ for (unsigned int i = 0; i < num_plugins; i++)
{
plugin = gns_plugins[i];
if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
void **data,
size_t *data_size)
{
- unsigned int i;
struct Plugin *plugin;
init ();
- for (i = 0; i < num_plugins; i++)
+ for (unsigned int i = 0; i < num_plugins; i++)
{
plugin = gns_plugins[i];
if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
const char *
GNUNET_GNSRECORD_number_to_typename (uint32_t type)
{
- unsigned int i;
struct Plugin *plugin;
const char * ret;
if (GNUNET_GNSRECORD_TYPE_ANY == type)
return "ANY";
init ();
- for (i = 0; i < num_plugins; i++)
+ for (unsigned int i = 0; i < num_plugins; i++)
{
plugin = gns_plugins[i];
if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
/*
This file is part of GNUnet.
- Copyright (C) 2009-2013 GNUnet e.V.
+ Copyright (C) 2009-2013, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey;
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
struct GNUNET_CRYPTO_SymmetricSessionKey skey;
- struct GNUNET_GNSRECORD_Data rdc[rd_count];
+ struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL(rd_count)];
uint32_t rd_count_nbo;
struct GNUNET_TIME_Absolute now;
GNUNET_CRYPTO_ecdsa_key_get_public (key,
&line->pkey);
}
+#undef CSIZE
return block_create (key,
&line->pkey,
expire,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- derive_block_aes_key (&iv, &skey, label, zone_key);
+ derive_block_aes_key (&iv,
+ &skey,
+ label,
+ zone_key);
{
char payload[payload_len];
uint32_t rd_count;
GNUNET_break (payload_len ==
GNUNET_CRYPTO_symmetric_decrypt (&block[1], payload_len,
- &skey, &iv,
- payload));
+ &skey, &iv,
+ payload));
GNUNET_memcpy (&rd_count,
- payload,
- sizeof (uint32_t));
+ payload,
+ sizeof (uint32_t));
rd_count = ntohl (rd_count);
if (rd_count > 2048)
{
return GNUNET_SYSERR;
}
{
- struct GNUNET_GNSRECORD_Data rd[rd_count];
+ struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
unsigned int j;
struct GNUNET_TIME_Absolute now;
continue;
if (rd[i].expiration_time < now.abs_value_us)
include_record = GNUNET_NO; /* Shadow record is expired */
- if ((rd[k].record_type == rd[i].record_type)
- && (rd[k].expiration_time >= now.abs_value_us)
- && (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
+ if ( (rd[k].record_type == rd[i].record_type) &&
+ (rd[k].expiration_time >= now.abs_value_us) &&
+ (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) )
+ {
include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
+ break;
+ }
}
if (GNUNET_YES == include_record)
{
rec.record_type = htonl (rd[i].record_type);
rec.flags = htonl (rd[i].flags);
if (off + sizeof (rec) > dest_size)
+ {
+ GNUNET_break (0);
return -1;
+ }
GNUNET_memcpy (&dest[off],
&rec,
sizeof (rec));
off += sizeof (rec);
if (off + rd[i].data_size > dest_size)
+ {
+ GNUNET_break (0);
return -1;
+ }
GNUNET_memcpy (&dest[off],
rd[i].data,
rd[i].data_size);
off += rd[i].data_size;
+#if GNUNET_EXTRA_LOGGING
+ {
+ char *str;
+
+ str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
+ rd[i].data,
+ rd[i].data_size);
+ if (NULL == str)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (str);
+ }
+#endif
}
return off;
}
for (unsigned int i=0;i<rd_count;i++)
{
if (off + sizeof (rec) > len)
+ {
+ GNUNET_break_op (0);
return GNUNET_SYSERR;
+ }
GNUNET_memcpy (&rec,
&src[off],
sizeof (rec));
dest[i].flags = ntohl (rec.flags);
off += sizeof (rec);
if (off + dest[i].data_size > len)
+ {
+ GNUNET_break_op (0);
return GNUNET_SYSERR;
+ }
dest[i].data = &src[off];
off += dest[i].data_size;
+#if GNUNET_EXTRA_LOGGING
+ {
+ char *str;
+
+ str = GNUNET_GNSRECORD_value_to_string (dest[i].record_type,
+ dest[i].data,
+ dest[i].data_size);
+ if (NULL == str)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (str);
+ }
+#endif
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Deserialized record %u with flags %d and expiration time %llu\n",
i,
uint64_t latest_expiration;
size_t req;
char *data;
- int record_offset;
size_t data_offset;
(*rdc_res) = 1 + rd2_length;
if (0 == 1 + rd2_length)
{
+ GNUNET_break (0);
(*rd_res) = NULL;
return;
}
- req = 0;
- for (unsigned int c=0; c< 1; c++)
- req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size;
+ req = sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd->data_size;
for (unsigned int c=0; c< rd2_length; c++)
req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size;
(*rd_res) = GNUNET_malloc (req);
latest_expiration = rd2[c].expiration_time;
(*rd_res)[c] = rd2[c];
(*rd_res)[c].data = (void *) &data[data_offset];
- GNUNET_memcpy ((void *) (*rd_res)[c].data,
+ GNUNET_memcpy (&data[data_offset],
rd2[c].data,
rd2[c].data_size);
data_offset += (*rd_res)[c].data_size;
}
/* append nick */
- record_offset = rd2_length;
- (*rd_res)[record_offset] = *nick_rd;
- (*rd_res)[record_offset].expiration_time = latest_expiration;
- (*rd_res)[record_offset].data = (void *) &data[data_offset];
- GNUNET_memcpy ((void *) (*rd_res)[record_offset].data,
+ (*rd_res)[rd2_length] = *nick_rd;
+ (*rd_res)[rd2_length].expiration_time = latest_expiration;
+ (*rd_res)[rd2_length].data = (void *) &data[data_offset];
+ GNUNET_memcpy ((void *) (*rd_res)[rd2_length].data,
nick_rd->data,
nick_rd->data_size);
- data_offset += (*rd_res)[record_offset].data_size;
+ data_offset += (*rd_res)[rd2_length].data_size;
GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset);
}
}
name_len = strlen (name) + 1;
- rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res);
+ rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count,
+ res);
env = GNUNET_MQ_msg_extra (zir_msg,
name_len + rd_ser_len,
GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
rd_public_count = 0;
now = GNUNET_TIME_absolute_get ();
for (unsigned int i=0;i<rd_count;i++)
- if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
- {
- rd_public[rd_public_count] = rd[i];
- if (rd_public[rd_public_count].expiration_time < now.abs_value_us)
- {
- /* record already expired, skip it */
- continue;
- }
- rd_public_count++;
- }
+ {
+ if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
+ continue;
+ if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
+ (rd[i].expiration_time < now.abs_value_us) )
+ continue; /* record already expired, skip it */
+ rd_public[rd_public_count++] = rd[i];
+ }
return rd_public_count;
}
rd_public_count = 0;
now = GNUNET_TIME_absolute_get ();
for (unsigned int i=0;i<rd_count;i++)
- if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
+ {
+ if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
+ continue;
+ if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
+ (rd[i].expiration_time < now.abs_value_us) )
+ continue; /* record already expired, skip it */
+ if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
{
- rd_public[rd_public_count] = rd[i];
- if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
- {
- /* GNUNET_GNSRECORD_block_create will convert to absolute time;
- we just need to adjust our iteration frequency */
- min_relative_record_time.rel_value_us =
- GNUNET_MIN (rd_public[rd_public_count].expiration_time,
- min_relative_record_time.rel_value_us);
- }
- else if (rd_public[rd_public_count].expiration_time < now.abs_value_us)
- {
- /* record already expired, skip it */
- continue;
- }
- rd_public_count++;
+ /* GNUNET_GNSRECORD_block_create will convert to absolute time;
+ we just need to adjust our iteration frequency */
+ min_relative_record_time.rel_value_us =
+ GNUNET_MIN (rd[i].expiration_time,
+ min_relative_record_time.rel_value_us);
}
+ rd_public[rd_public_count++] = rd[i];
+ }
return rd_public_count;
}