Browse Source

core: parser - safety check and clean log messages for disposition header

Daniel-Constantin Mierla 9 years ago
parent
commit
8086de823e
1 changed files with 17 additions and 21 deletions
  1. 17 21
      parser/parse_disposition.c

+ 17 - 21
parser/parse_disposition.c

@@ -52,6 +52,11 @@ int parse_disposition( str *s, struct disposition *disp)
 	char *tmp;
 	char *end;
 
+	if(s==NULL || s->s==NULL || s->len<=0) {
+		LM_ERR("invalid parameters\n");
+		return -1;
+	}
+
 	state = saved_state = FIND_TYPE;
 	end = s->s + s->len;
 	disp_p = 0;
@@ -114,8 +119,7 @@ int parse_disposition( str *s, struct disposition *disp)
 						state=F_CRLF;
 						break;
 					default:
-						LOG(L_ERR,"ERROR:parse_disposition: unexpected "
-							"char [%c] in status %d: <<%.*s>> .\n",
+						LM_ERR("unexpected char [%c] in status %d: <<%.*s>>.\n",
 							*tmp,state, (int)(tmp-s->s), s->s);
 						goto error;
 				}
@@ -143,15 +147,13 @@ int parse_disposition( str *s, struct disposition *disp)
 						state=F_CR;
 						break;
 					default:
-						LOG(L_ERR,"ERROR:parse_disposition: unexpected "
-							"char [%c] in status %d: <<%.*s>> .\n",
+						LM_ERR("unexpected char [%c] in status %d: <<%.*s>>.\n",
 							*tmp,state, (int)(tmp-s->s), ZSW(s->s));
 						goto error;
 				}
 				break;
 			case 0:
-				LOG(L_ERR,"ERROR:parse_disposition: unexpected "
-					"char [%c] in status %d: <<%.*s>> .\n",
+				LM_ERR("nexpected char [%c] in status %d: <<%.*s>>.\n",
 					*tmp,state, (int)(tmp-s->s), ZSW(s->s));
 				goto error;
 				break;
@@ -180,8 +182,7 @@ int parse_disposition( str *s, struct disposition *disp)
 						state = FIND_PARAM;
 						break;
 					default:
-						LOG(L_ERR,"ERROR:parse_disposition: unexpected "
-							"char [%c] in status %d: <<%.*s>> .\n",
+						LM_ERR("unexpected char [%c] in status %d: <<%.*s>>.\n",
 							*tmp,state, (int)(tmp-s->s), ZSW(s->s));
 						goto error;
 				}
@@ -202,8 +203,7 @@ int parse_disposition( str *s, struct disposition *disp)
 						state = FIND_VAL;
 						break;
 					default:
-						LOG(L_ERR,"ERROR:parse_disposition: unexpected "
-							"char [%c] in status %d: <<%.*s>> .\n",
+						LM_ERR("unexpected char [%c] in status %d: <<%.*s>>.\n",
 							*tmp,state, (int)(tmp-s->s), ZSW(s->s));
 						goto error;
 				}
@@ -222,8 +222,7 @@ int parse_disposition( str *s, struct disposition *disp)
 						state = END_VAL;
 						break;
 					default:
-						LOG(L_ERR,"ERROR:parse_disposition: unexpected "
-							"char [%c] in status %d: <<%.*s>> .\n",
+						LM_ERR("unexpected char [%c] in status %d: <<%.*s>>.\n",
 							*tmp,state, (int)(tmp-s->s), ZSW(s->s));
 						goto error;
 				}
@@ -241,8 +240,7 @@ int parse_disposition( str *s, struct disposition *disp)
 						state = SKIP_QUOTED_VAL;
 						break;
 					default:
-						LOG(L_ERR,"ERROR:parse_disposition: unexpected "
-							"char [%c] in status %d: <<%.*s>> .\n",
+						LM_ERR("unexpected char [%c] in status %d: <<%.*s>>.\n",
 							*tmp,state, (int)(tmp-s->s), ZSW(s->s));
 						goto error;
 				}
@@ -270,8 +268,7 @@ int parse_disposition( str *s, struct disposition *disp)
 					case QUOTED_VAL:
 						break;
 					default:
-						LOG(L_ERR,"ERROR:parse_disposition: unexpected "
-							"char [%c] in status %d: <<%.*s>> .\n",
+						LM_ERR("unexpected char [%c] in status %d: <<%.*s>>.\n",
 							*tmp,state, (int)(tmp-s->s), ZSW(s->s));
 						goto error;
 				}
@@ -290,8 +287,7 @@ int parse_disposition( str *s, struct disposition *disp)
 						new_p=(struct disposition_param*)pkg_malloc
 							(sizeof(struct disposition_param));
 						if (new_p==0) {
-							LOG(L_ERR,"ERROR:parse_disposition: no more "
-								"pkg mem\n");
+							LM_ERR("no more pkg mem\n");
 							goto error;
 						}
 						memset(new_p,0,sizeof(struct disposition_param));
@@ -331,7 +327,7 @@ int parse_disposition( str *s, struct disposition *disp)
 			disp_p->body.len = tmp - disp_p->body.s;
 			break;
 		default:
-			LOG(L_ERR,"ERROR:parse_disposition: wrong final state (%d)\n",
+			LM_ERR("wrong final state (%d)\n",
 				state);
 			goto error;
 	}
@@ -375,7 +371,7 @@ int parse_content_disposition( struct sip_msg *msg )
 		if (parse_headers(msg, HDR_CONTENTDISPOSITION_F, 0)==-1)
 			goto error;
 		if (msg->content_disposition==0) {
-			DBG("DEBUG:parse_content_disposition: hdr not found\n");
+			DBG("hdr not found\n");
 			return 1;
 		}
 	}
@@ -389,7 +385,7 @@ int parse_content_disposition( struct sip_msg *msg )
 	/* parse the body */
 	disp = (struct disposition*)pkg_malloc(sizeof(struct disposition));
 	if (disp==0) {
-		LOG(L_ERR,"ERROR:parse_content_disposition: no more pkg memory\n");
+		LM_ERR("no more pkg memory\n");
 		goto error;
 	}
 	memset(disp,0,sizeof(struct disposition));