diff options
author | Bart Polot <bart@net.in.tum.de> | 2012-07-05 13:54:59 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2012-07-05 13:54:59 +0000 |
commit | 06fcd88b725111a2d404888210f8dbe3b848a44b (patch) | |
tree | adfcefce12785ff986126f51f4b90c7a327cde76 /src/mesh | |
parent | 890bf7063f06825cf0de54102d75bc83568257bc (diff) | |
download | gnunet-06fcd88b725111a2d404888210f8dbe3b848a44b.tar.gz gnunet-06fcd88b725111a2d404888210f8dbe3b848a44b.zip |
- fixed bug for offset calculation, added debug statements
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/mesh_block_lib.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/mesh/mesh_block_lib.c b/src/mesh/mesh_block_lib.c index 3ab5d5a47..8e06e9f53 100644 --- a/src/mesh/mesh_block_lib.c +++ b/src/mesh/mesh_block_lib.c | |||
@@ -94,25 +94,50 @@ GNUNET_MESH_regex_block_iterate (const struct MeshRegexBlock *block, | |||
94 | char *aux; | 94 | char *aux; |
95 | 95 | ||
96 | offset = sizeof (struct MeshRegexBlock); | 96 | offset = sizeof (struct MeshRegexBlock); |
97 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
98 | "* Start iterating block of size %u, off %u\n", | ||
99 | size, offset); | ||
97 | if (offset > size) // Is it safe to access the regex block? | 100 | if (offset > size) // Is it safe to access the regex block? |
101 | { | ||
102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
103 | "* Block is smaller than struct MeshRegexBlock, END\n"); | ||
98 | return GNUNET_SYSERR; | 104 | return GNUNET_SYSERR; |
105 | } | ||
99 | n = ntohl (block->n_proof); | 106 | n = ntohl (block->n_proof); |
100 | offset =+ n; | 107 | offset += n; |
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
109 | "* Proof length: %u, off %u\n", n, offset); | ||
101 | if (offset > size) // Is it safe to access the regex proof? | 110 | if (offset > size) // Is it safe to access the regex proof? |
111 | { | ||
112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
113 | "* Block is smaller than Block + proof, END\n"); | ||
102 | return GNUNET_SYSERR; | 114 | return GNUNET_SYSERR; |
115 | } | ||
103 | aux = (char *) &block[1]; // Skip regex block | 116 | aux = (char *) &block[1]; // Skip regex block |
104 | aux = &aux[n]; // Skip regex proof | 117 | aux = &aux[n]; // Skip regex proof |
105 | n = ntohl (block->n_edges); | 118 | n = ntohl (block->n_edges); |
106 | for (i = 0; i < n; n++) // aux always points at the end of the previous block | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Edges: %u\n", n); |
120 | for (i = 0; i < n; i++) // aux always points at the end of the previous block | ||
107 | { | 121 | { |
108 | offset += sizeof (struct MeshRegexEdge); | 122 | offset += sizeof (struct MeshRegexEdge); |
123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Edge %u, off %u\n", i, offset); | ||
109 | if (offset > size) // Is it safe to access the next edge block? | 124 | if (offset > size) // Is it safe to access the next edge block? |
125 | { | ||
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
127 | "* Size not enough for MeshRegexEdge, END\n"); | ||
110 | return GNUNET_SYSERR; | 128 | return GNUNET_SYSERR; |
129 | } | ||
111 | edge = (struct MeshRegexEdge *) aux; | 130 | edge = (struct MeshRegexEdge *) aux; |
112 | n_token = ntohl (edge->n_token); | 131 | n_token = ntohl (edge->n_token); |
113 | offset += n_token; | 132 | offset += n_token; |
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
134 | "* Token lenght %u, off %u\n", n_token, offset); | ||
114 | if (offset > size) // Is it safe to access the edge token? | 135 | if (offset > size) // Is it safe to access the edge token? |
136 | { | ||
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
138 | "* Size not enough for edge token, END\n"); | ||
115 | return GNUNET_SYSERR; | 139 | return GNUNET_SYSERR; |
140 | } | ||
116 | aux = (char *) &edge[1]; // Skip edge block | 141 | aux = (char *) &edge[1]; // Skip edge block |
117 | if (NULL != iterator) | 142 | if (NULL != iterator) |
118 | if (GNUNET_NO == iterator (iter_cls, aux, n_token, &edge->key)) | 143 | if (GNUNET_NO == iterator (iter_cls, aux, n_token, &edge->key)) |
@@ -120,7 +145,15 @@ GNUNET_MESH_regex_block_iterate (const struct MeshRegexBlock *block, | |||
120 | aux = &aux[n_token]; // Skip edge token | 145 | aux = &aux[n_token]; // Skip edge token |
121 | } | 146 | } |
122 | // The total size should be exactly the size of (regex + all edges) blocks | 147 | // The total size should be exactly the size of (regex + all edges) blocks |
123 | return (offset == size) ? GNUNET_OK : GNUNET_SYSERR; | 148 | if (offset == size) |
149 | { | ||
150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
151 | "* Block processed, END OK\n"); | ||
152 | return GNUNET_OK; | ||
153 | } | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
155 | "* Size %u, read %u END KO\n", size, offset); | ||
156 | return GNUNET_SYSERR; | ||
124 | } | 157 | } |
125 | 158 | ||
126 | #if 0 /* keep Emacsens' auto-indent happy */ | 159 | #if 0 /* keep Emacsens' auto-indent happy */ |