| 1179 | } |
| 1180 | |
| 1181 | static int sip_validate_hdrs(struct sip_msg *msg) |
| 1182 | { |
| 1183 | struct disposition *disp; |
| 1184 | struct hdr_field* hf, *hf2; |
| 1185 | struct to_body *to; |
| 1186 | content_t * cont; |
| 1187 | struct via_body *via_b; |
| 1188 | str str_aux; |
| 1189 | char *s_aux, *e_aux; |
| 1190 | unsigned u_aux; |
| 1191 | int i_aux; |
| 1192 | struct sip_uri uri, uri2; |
| 1193 | |
| 1194 | #define CHECK_HDR_EMPTY() \ |
| 1195 | do { \ |
| 1196 | str_aux = hf->body; \ |
| 1197 | trim_len( str_aux.len , str_aux.s , hf->body ); \ |
| 1198 | if (str_aux.len <= 0) { \ |
| 1199 | LM_DBG("header '%.*s' has invalid value %d\n", \ |
| 1200 | hf->name.len, hf->name.s, str_aux.len); \ |
| 1201 | goto failed; \ |
| 1202 | } \ |
| 1203 | } while (0) |
| 1204 | |
| 1205 | #define CHECK_HDR_FUNC(_f, _o) \ |
| 1206 | do { \ |
| 1207 | if (_f(_o) < 0) { \ |
| 1208 | LM_DBG("cannot parse '%.*s' header\n", \ |
| 1209 | hf->name.len, hf->name.s); \ |
| 1210 | goto failed; \ |
| 1211 | } \ |
| 1212 | } while (0) |
| 1213 | |
| 1214 | /* skip via, cseq, to and content length |
| 1215 | * = we can be sure that they have been properly parsed = |
| 1216 | * = because otherwise the code wouldn't reach here = |
| 1217 | * = but in 'parse_msg'*/ |
| 1218 | |
| 1219 | for (hf = msg->headers; hf; hf = hf->next) { |
| 1220 | /* try to eliminate errors fast */ |
| 1221 | if (hf->type == HDR_ERROR_T) { |
| 1222 | LM_DBG("header %.*s could not be properly parsed\n", |
| 1223 | hf->name.len, hf->name.s); |
| 1224 | goto failed; |
| 1225 | } |
| 1226 | /* was successfully parsed previously */ |
| 1227 | if (hf->parsed) |
| 1228 | continue; |
| 1229 | |
| 1230 | /* try to manually parse them */ |
| 1231 | switch (hf->type) { |
| 1232 | case HDR_CONTENTTYPE_T: |
| 1233 | if (!(cont = pkg_malloc(sizeof (content_t)))) { |
| 1234 | LM_ERR("Unable to allocate memory\n"); |
| 1235 | goto failed; |
| 1236 | } |
| 1237 | memset(cont, 0, sizeof (content_t)); |
| 1238 |
no test coverage detected