Skip to content

Commit ba31dfa

Browse files
committed
pi_http: avoid POST argument OOB access
Reported-by: Haruto Kimura (Stella) (cherry picked from commit 3ac1244805d96ab5e717a9c5e6c1c3af453efb18)
1 parent 245c8ad commit ba31dfa

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

modules/httpd/httpd_proc.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,18 @@ static MHD_RET post_iterator (void *cls,
290290
LM_DBG("[%.*s]->[%.*s]\n", key_len, key, (int)size, value);
291291

292292
kv = (str_str_t*)slinkedl_append(pr->p_list,
293-
sizeof(str_str_t) + key_len + size);
293+
sizeof(str_str_t) + key_len + size + 1);
294+
if (!kv) {
295+
LM_ERR("oom\n");
296+
pr->status = -1; return MHD_NO;
297+
}
294298
p = (char*)(kv + 1);
295299
kv->key.len = key_len; kv->key.s = p;
296300
memcpy(p, key, key_len);
297301
p += key_len;
298302
kv->val.len = size; kv->val.s = p;
299303
memcpy(p, value, size);
304+
p[size] = '\0';
300305
LM_DBG("inserting element pr=[%p] pp=[%p] p_list=[%p]\n",
301306
pr, pr->pp, pr->p_list);
302307

@@ -567,14 +572,19 @@ MHD_RET answer_to_connection (void *cls, struct MHD_Connection *connection,
567572
/* Save the entire body as the '1' key */
568573
kv = (str_str_t*)slinkedl_append(pr->p_list,
569574
sizeof(str_str_t) + 1 +
570-
*upload_data_size);
575+
*upload_data_size + 1);
576+
if (!kv) {
577+
LM_ERR("oom\n");
578+
goto mhd_no;
579+
}
571580
p = (char*)(kv + 1);
572581
kv->key.len = 1; kv->key.s = p;
573582
memcpy(p, "1", 1);
574583
p += 1;
575584
kv->val.len = *upload_data_size;
576585
kv->val.s = p;
577586
memcpy(p, upload_data, *upload_data_size);
587+
p[*upload_data_size] = '\0';
578588
break;
579589
default:
580590
LM_ERR("Unhandled data for ContentType [%d]\n",

modules/pi_http/http_fnc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,7 +2510,7 @@ int getVal(db_val_t *val, db_type_t val_type, db_key_t key, ph_db_table_t *table
25102510
struct sip_uri uri;
25112511
char c;
25122512

2513-
for(i=0;i<=table->cols_size;i++){
2513+
for(i=0;i<table->cols_size;i++){
25142514
if(table->cols[i].type==val_type &&
25152515
table->cols[i].field.len==key->len &&
25162516
strncmp(table->cols[i].field.s,key->s,key->len)==0){
@@ -3230,4 +3230,3 @@ int ph_run_pi_cmd(int mod, int cmd,
32303230
if(q_vals) pkg_free(q_vals);
32313231
return 0;
32323232
}
3233-

0 commit comments

Comments
 (0)