diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-06-03 21:22:50 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-06-03 21:22:50 +0200 |
commit | a00a49bf58c502ab860adaa6b01541c0e7e3e645 (patch) | |
tree | e9ece2ebffd1d0df735763fe5ebdfb2d334a496f /src/reclaim/json_reclaim.c | |
parent | 34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e (diff) | |
download | gnunet-a00a49bf58c502ab860adaa6b01541c0e7e3e645.tar.gz gnunet-a00a49bf58c502ab860adaa6b01541c0e7e3e645.zip |
RECLAIM: Various fixes (coverity)
Diffstat (limited to 'src/reclaim/json_reclaim.c')
-rw-r--r-- | src/reclaim/json_reclaim.c | 106 |
1 files changed, 70 insertions, 36 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index 3ba4300bb..222cf1dbf 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -55,24 +55,37 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
55 | 55 | ||
56 | GNUNET_assert (NULL != root); | 56 | GNUNET_assert (NULL != root); |
57 | 57 | ||
58 | if (!json_is_object (root)) { | 58 | if (! json_is_object (root)) |
59 | { | ||
59 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
60 | "Error json is not array nor object!\n"); | 61 | "Error json is not array nor object!\n"); |
61 | return GNUNET_SYSERR; | 62 | return GNUNET_SYSERR; |
62 | } | 63 | } |
63 | // interpret single attribute | 64 | // interpret single attribute |
64 | unpack_state = | 65 | unpack_state = json_unpack (root, |
65 | json_unpack (root, "{s:s, s?s, s:s, s:s!}", "name", &name_str, "id", | 66 | "{s:s, s?s, s:s, s:s!}", |
66 | &id_str, "type", &type_str, "value", &val_str); | 67 | "name", |
68 | &name_str, | ||
69 | "id", | ||
70 | &id_str, | ||
71 | "type", | ||
72 | &type_str, | ||
73 | "value", | ||
74 | &val_str); | ||
67 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || | 75 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || |
68 | (NULL == type_str)) { | 76 | (NULL == type_str)) |
77 | { | ||
69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
70 | "Error json object has a wrong format!\n"); | 79 | "Error json object has a wrong format!\n"); |
71 | return GNUNET_SYSERR; | 80 | return GNUNET_SYSERR; |
72 | } | 81 | } |
73 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); | 82 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); |
74 | if (GNUNET_SYSERR == (GNUNET_RECLAIM_ATTRIBUTE_string_to_value ( | 83 | if (GNUNET_SYSERR == |
75 | type, val_str, (void **)&data, &data_size))) { | 84 | (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, |
85 | val_str, | ||
86 | (void **) &data, | ||
87 | &data_size))) | ||
88 | { | ||
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); | 89 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); |
77 | return GNUNET_SYSERR; | 90 | return GNUNET_SYSERR; |
78 | } | 91 | } |
@@ -80,10 +93,12 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
80 | if ((NULL == id_str) || (0 == strlen (id_str))) | 93 | if ((NULL == id_str) || (0 == strlen (id_str))) |
81 | attr->id = 0; | 94 | attr->id = 0; |
82 | else | 95 | else |
83 | GNUNET_STRINGS_string_to_data (id_str, strlen (id_str), &attr->id, | 96 | GNUNET_STRINGS_string_to_data (id_str, |
97 | strlen (id_str), | ||
98 | &attr->id, | ||
84 | sizeof (uint64_t)); | 99 | sizeof (uint64_t)); |
85 | 100 | ||
86 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr = attr; | 101 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr; |
87 | return GNUNET_OK; | 102 | return GNUNET_OK; |
88 | } | 103 | } |
89 | 104 | ||
@@ -97,8 +112,9 @@ static void | |||
97 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) | 112 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) |
98 | { | 113 | { |
99 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; | 114 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; |
100 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr; | 115 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr; |
101 | if (NULL != *attr) { | 116 | if (NULL != *attr) |
117 | { | ||
102 | GNUNET_free (*attr); | 118 | GNUNET_free (*attr); |
103 | *attr = NULL; | 119 | *attr = NULL; |
104 | } | 120 | } |
@@ -114,12 +130,12 @@ struct GNUNET_JSON_Specification | |||
114 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | 130 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) |
115 | { | 131 | { |
116 | struct GNUNET_JSON_Specification ret = {.parser = &parse_attr, | 132 | struct GNUNET_JSON_Specification ret = {.parser = &parse_attr, |
117 | .cleaner = &clean_attr, | 133 | .cleaner = &clean_attr, |
118 | .cls = NULL, | 134 | .cls = NULL, |
119 | .field = NULL, | 135 | .field = NULL, |
120 | .ptr = attr, | 136 | .ptr = attr, |
121 | .ptr_size = 0, | 137 | .ptr_size = 0, |
122 | .size_ptr = NULL}; | 138 | .size_ptr = NULL}; |
123 | *attr = NULL; | 139 | *attr = NULL; |
124 | return ret; | 140 | return ret; |
125 | } | 141 | } |
@@ -142,44 +158,61 @@ parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
142 | 158 | ||
143 | GNUNET_assert (NULL != root); | 159 | GNUNET_assert (NULL != root); |
144 | 160 | ||
145 | if (!json_is_object (root)) { | 161 | if (! json_is_object (root)) |
162 | { | ||
146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
147 | "Error json is not array nor object!\n"); | 164 | "Error json is not array nor object!\n"); |
148 | return GNUNET_SYSERR; | 165 | return GNUNET_SYSERR; |
149 | } | 166 | } |
150 | // interpret single ticket | 167 | // interpret single ticket |
151 | unpack_state = json_unpack (root, "{s:s, s:s, s:s!}", "rnd", &rnd_str, | 168 | unpack_state = json_unpack (root, |
152 | "audience", &aud_str, "identity", &id_str); | 169 | "{s:s, s:s, s:s!}", |
153 | if (0 != unpack_state) { | 170 | "rnd", |
171 | &rnd_str, | ||
172 | "audience", | ||
173 | &aud_str, | ||
174 | "identity", | ||
175 | &id_str); | ||
176 | if (0 != unpack_state) | ||
177 | { | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
155 | "Error json object has a wrong format!\n"); | 179 | "Error json object has a wrong format!\n"); |
156 | return GNUNET_SYSERR; | 180 | return GNUNET_SYSERR; |
157 | } | 181 | } |
158 | ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket); | 182 | ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket); |
159 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, strlen (rnd_str), | 183 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, |
184 | strlen (rnd_str), | ||
160 | &ticket->rnd, | 185 | &ticket->rnd, |
161 | sizeof (uint64_t))) { | 186 | sizeof (uint64_t))) |
187 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); |
163 | GNUNET_free (ticket); | 189 | GNUNET_free (ticket); |
164 | return GNUNET_SYSERR; | 190 | return GNUNET_SYSERR; |
165 | } | 191 | } |
166 | GNUNET_STRINGS_string_to_data (id_str, strlen (id_str), &ticket->identity, | 192 | if (GNUNET_OK != |
167 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 193 | GNUNET_STRINGS_string_to_data (id_str, |
194 | strlen (id_str), | ||
195 | &ticket->identity, | ||
196 | sizeof ( | ||
197 | struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
168 | { | 198 | { |
169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); |
170 | GNUNET_free (ticket); | 200 | GNUNET_free (ticket); |
171 | return GNUNET_SYSERR; | 201 | return GNUNET_SYSERR; |
172 | } | 202 | } |
173 | 203 | ||
174 | GNUNET_STRINGS_string_to_data (aud_str, strlen (aud_str), &ticket->audience, | 204 | if (GNUNET_OK != |
175 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 205 | GNUNET_STRINGS_string_to_data (aud_str, |
206 | strlen (aud_str), | ||
207 | &ticket->audience, | ||
208 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
176 | { | 209 | { |
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); |
178 | GNUNET_free (ticket); | 211 | GNUNET_free (ticket); |
179 | return GNUNET_SYSERR; | 212 | return GNUNET_SYSERR; |
180 | } | 213 | } |
181 | 214 | ||
182 | *(struct GNUNET_RECLAIM_Ticket **)spec->ptr = ticket; | 215 | *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket; |
183 | return GNUNET_OK; | 216 | return GNUNET_OK; |
184 | } | 217 | } |
185 | 218 | ||
@@ -193,8 +226,9 @@ static void | |||
193 | clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) | 226 | clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) |
194 | { | 227 | { |
195 | struct GNUNET_RECLAIM_Ticket **ticket; | 228 | struct GNUNET_RECLAIM_Ticket **ticket; |
196 | ticket = (struct GNUNET_RECLAIM_Ticket **)spec->ptr; | 229 | ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr; |
197 | if (NULL != *ticket) { | 230 | if (NULL != *ticket) |
231 | { | ||
198 | GNUNET_free (*ticket); | 232 | GNUNET_free (*ticket); |
199 | *ticket = NULL; | 233 | *ticket = NULL; |
200 | } | 234 | } |
@@ -210,12 +244,12 @@ struct GNUNET_JSON_Specification | |||
210 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) | 244 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) |
211 | { | 245 | { |
212 | struct GNUNET_JSON_Specification ret = {.parser = &parse_ticket, | 246 | struct GNUNET_JSON_Specification ret = {.parser = &parse_ticket, |
213 | .cleaner = &clean_ticket, | 247 | .cleaner = &clean_ticket, |
214 | .cls = NULL, | 248 | .cls = NULL, |
215 | .field = NULL, | 249 | .field = NULL, |
216 | .ptr = ticket, | 250 | .ptr = ticket, |
217 | .ptr_size = 0, | 251 | .ptr_size = 0, |
218 | .size_ptr = NULL}; | 252 | .size_ptr = NULL}; |
219 | *ticket = NULL; | 253 | *ticket = NULL; |
220 | return ret; | 254 | return ret; |
221 | } | 255 | } |