comparison src/http/v3/ngx_http_v3_parse.c @ 8464:fdb8edc8e496 quic

HTTP/3: limited prefixed integer size by 62 bits.
author Roman Arutyunyan <arut@nginx.com>
date Fri, 03 Jul 2020 09:26:12 +0300
parents 2576485b93d4
children 5611bbb852ce
comparison
equal deleted inserted replaced
8463:2576485b93d4 8464:fdb8edc8e496
117 break; 117 break;
118 118
119 case sw_value: 119 case sw_value:
120 120
121 st->value += (uint64_t) (ch & 0x7f) << st->shift; 121 st->value += (uint64_t) (ch & 0x7f) << st->shift;
122
123 if (st->shift == 56
124 && ((ch & 0x80) || (st->value & 0xc000000000000000)))
125 {
126 ngx_log_error(NGX_LOG_INFO, c->log, 0,
127 "client exceeded integer size limit");
128 return NGX_HTTP_V3_ERR_EXCESSIVE_LOAD;
129 }
130
122 if (ch & 0x80) { 131 if (ch & 0x80) {
123 st->shift += 7; 132 st->shift += 7;
124 break; 133 break;
125 } 134 }
126 135
279 288
280 /* fall through */ 289 /* fall through */
281 290
282 case sw_req_insert_count: 291 case sw_req_insert_count:
283 292
284 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 8, ch) != NGX_DONE) { 293 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 8, ch);
285 break; 294 if (rc != NGX_DONE) {
295 return rc;
286 } 296 }
287 297
288 st->insert_count = st->pint.value; 298 st->insert_count = st->pint.value;
289 st->state = sw_delta_base; 299 st->state = sw_delta_base;
290 break; 300 break;
296 306
297 /* fall through */ 307 /* fall through */
298 308
299 case sw_read_delta_base: 309 case sw_read_delta_base:
300 310
301 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { 311 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch);
302 break; 312 if (rc != NGX_DONE) {
313 return rc;
303 } 314 }
304 315
305 st->delta_base = st->pint.value; 316 st->delta_base = st->pint.value;
306 goto done; 317 goto done;
307 } 318 }
519 530
520 /* fall through */ 531 /* fall through */
521 532
522 case sw_index: 533 case sw_index:
523 534
524 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch) != NGX_DONE) { 535 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch);
525 break; 536 if (rc != NGX_DONE) {
537 return rc;
526 } 538 }
527 539
528 st->index = st->pint.value; 540 st->index = st->pint.value;
529 goto done; 541 goto done;
530 } 542 }
576 588
577 /* fall through */ 589 /* fall through */
578 590
579 case sw_index: 591 case sw_index:
580 592
581 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 4, ch) != NGX_DONE) { 593 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 4, ch);
582 break; 594 if (rc != NGX_DONE) {
595 return rc;
583 } 596 }
584 597
585 st->index = st->pint.value; 598 st->index = st->pint.value;
586 st->state = sw_value_len; 599 st->state = sw_value_len;
587 break; 600 break;
593 606
594 /* fall through */ 607 /* fall through */
595 608
596 case sw_read_value_len: 609 case sw_read_value_len:
597 610
598 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { 611 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch);
599 break; 612 if (rc != NGX_DONE) {
613 return rc;
600 } 614 }
601 615
602 st->literal.length = st->pint.value; 616 st->literal.length = st->pint.value;
603 if (st->literal.length == 0) { 617 if (st->literal.length == 0) {
604 goto done; 618 goto done;
671 685
672 /* fall through */ 686 /* fall through */
673 687
674 case sw_name_len: 688 case sw_name_len:
675 689
676 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 3, ch) != NGX_DONE) { 690 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 3, ch);
677 break; 691 if (rc != NGX_DONE) {
692 return rc;
678 } 693 }
679 694
680 st->literal.length = st->pint.value; 695 st->literal.length = st->pint.value;
681 if (st->literal.length == 0) { 696 if (st->literal.length == 0) {
682 return NGX_ERROR; 697 return NGX_ERROR;
708 723
709 /* fall through */ 724 /* fall through */
710 725
711 case sw_read_value_len: 726 case sw_read_value_len:
712 727
713 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { 728 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch);
714 break; 729 if (rc != NGX_DONE) {
730 return rc;
715 } 731 }
716 732
717 st->literal.length = st->pint.value; 733 st->literal.length = st->pint.value;
718 if (st->literal.length == 0) { 734 if (st->literal.length == 0) {
719 goto done; 735 goto done;
771 787
772 /* fall through */ 788 /* fall through */
773 789
774 case sw_index: 790 case sw_index:
775 791
776 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 4, ch) != NGX_DONE) { 792 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 4, ch);
777 break; 793 if (rc != NGX_DONE) {
794 return rc;
778 } 795 }
779 796
780 st->index = st->pint.value; 797 st->index = st->pint.value;
781 goto done; 798 goto done;
782 } 799 }
823 840
824 /* fall through */ 841 /* fall through */
825 842
826 case sw_index: 843 case sw_index:
827 844
828 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 3, ch) != NGX_DONE) { 845 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 3, ch);
829 break; 846 if (rc != NGX_DONE) {
847 return rc;
830 } 848 }
831 849
832 st->index = st->pint.value; 850 st->index = st->pint.value;
833 st->state = sw_value_len; 851 st->state = sw_value_len;
834 break; 852 break;
840 858
841 /* fall through */ 859 /* fall through */
842 860
843 case sw_read_value_len: 861 case sw_read_value_len:
844 862
845 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { 863 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch);
846 break; 864 if (rc != NGX_DONE) {
865 return rc;
847 } 866 }
848 867
849 st->literal.length = st->pint.value; 868 st->literal.length = st->pint.value;
850 if (st->literal.length == 0) { 869 if (st->literal.length == 0) {
851 goto done; 870 goto done;
1186 1205
1187 goto done; 1206 goto done;
1188 1207
1189 case sw_capacity: 1208 case sw_capacity:
1190 1209
1191 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch) != NGX_DONE) { 1210 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch);
1192 break; 1211 if (rc != NGX_DONE) {
1212 return rc;
1193 } 1213 }
1194 1214
1195 rc = ngx_http_v3_set_capacity(c, st->pint.value); 1215 rc = ngx_http_v3_set_capacity(c, st->pint.value);
1196 if (rc != NGX_OK) { 1216 if (rc != NGX_OK) {
1197 return rc; 1217 return rc;
1199 1219
1200 goto done; 1220 goto done;
1201 1221
1202 case sw_duplicate: 1222 case sw_duplicate:
1203 1223
1204 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch) != NGX_DONE) { 1224 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch);
1205 break; 1225 if (rc != NGX_DONE) {
1226 return rc;
1206 } 1227 }
1207 1228
1208 rc = ngx_http_v3_duplicate(c, st->pint.value); 1229 rc = ngx_http_v3_duplicate(c, st->pint.value);
1209 if (rc != NGX_OK) { 1230 if (rc != NGX_OK) {
1210 return rc; 1231 return rc;
1249 1270
1250 /* fall through */ 1271 /* fall through */
1251 1272
1252 case sw_name_index: 1273 case sw_name_index:
1253 1274
1254 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch) != NGX_DONE) { 1275 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch);
1255 break; 1276 if (rc != NGX_DONE) {
1277 return rc;
1256 } 1278 }
1257 1279
1258 st->index = st->pint.value; 1280 st->index = st->pint.value;
1259 st->state = sw_value_len; 1281 st->state = sw_value_len;
1260 break; 1282 break;
1266 1288
1267 /* fall through */ 1289 /* fall through */
1268 1290
1269 case sw_read_value_len: 1291 case sw_read_value_len:
1270 1292
1271 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { 1293 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch);
1272 break; 1294 if (rc != NGX_DONE) {
1295 return rc;
1273 } 1296 }
1274 1297
1275 st->literal.length = st->pint.value; 1298 st->literal.length = st->pint.value;
1276 if (st->literal.length == 0) { 1299 if (st->literal.length == 0) {
1277 goto done; 1300 goto done;
1341 1364
1342 /* fall through */ 1365 /* fall through */
1343 1366
1344 case sw_name_len: 1367 case sw_name_len:
1345 1368
1346 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch) != NGX_DONE) { 1369 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch);
1347 break; 1370 if (rc != NGX_DONE) {
1371 return rc;
1348 } 1372 }
1349 1373
1350 st->literal.length = st->pint.value; 1374 st->literal.length = st->pint.value;
1351 if (st->literal.length == 0) { 1375 if (st->literal.length == 0) {
1352 return NGX_ERROR; 1376 return NGX_ERROR;
1378 1402
1379 /* fall through */ 1403 /* fall through */
1380 1404
1381 case sw_read_value_len: 1405 case sw_read_value_len:
1382 1406
1383 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { 1407 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch);
1384 break; 1408 if (rc != NGX_DONE) {
1409 return rc;
1385 } 1410 }
1386 1411
1387 st->literal.length = st->pint.value; 1412 st->literal.length = st->pint.value;
1388 if (st->literal.length == 0) { 1413 if (st->literal.length == 0) {
1389 goto done; 1414 goto done;
1463 1488
1464 switch (st->state) { 1489 switch (st->state) {
1465 1490
1466 case sw_ack_header: 1491 case sw_ack_header:
1467 1492
1468 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch) != NGX_DONE) { 1493 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch);
1469 break; 1494 if (rc != NGX_DONE) {
1495 return rc;
1470 } 1496 }
1471 1497
1472 rc = ngx_http_v3_ack_header(c, st->pint.value); 1498 rc = ngx_http_v3_ack_header(c, st->pint.value);
1473 if (rc != NGX_OK) { 1499 if (rc != NGX_OK) {
1474 return rc; 1500 return rc;
1476 1502
1477 goto done; 1503 goto done;
1478 1504
1479 case sw_cancel_stream: 1505 case sw_cancel_stream:
1480 1506
1481 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch) != NGX_DONE) { 1507 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch);
1482 break; 1508 if (rc != NGX_DONE) {
1509 return rc;
1483 } 1510 }
1484 1511
1485 rc = ngx_http_v3_cancel_stream(c, st->pint.value); 1512 rc = ngx_http_v3_cancel_stream(c, st->pint.value);
1486 if (rc != NGX_OK) { 1513 if (rc != NGX_OK) {
1487 return rc; 1514 return rc;
1489 1516
1490 goto done; 1517 goto done;
1491 1518
1492 case sw_inc_insert_count: 1519 case sw_inc_insert_count:
1493 1520
1494 if (ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch) != NGX_DONE) { 1521 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch);
1495 break; 1522 if (rc != NGX_DONE) {
1523 return rc;
1496 } 1524 }
1497 1525
1498 rc = ngx_http_v3_inc_insert_count(c, st->pint.value); 1526 rc = ngx_http_v3_inc_insert_count(c, st->pint.value);
1499 if (rc != NGX_OK) { 1527 if (rc != NGX_OK) {
1500 return rc; 1528 return rc;