~britco/nginx/master

« back to all changes in this revision

Viewing changes to src/http/ngx_http_parse.c

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry, Kartik Mistry, Michael Lustfield
  • Date: 2010-11-27 21:04:02 UTC
  • mfrom: (1.3.8 upstream)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20101127210402-14sgjpe6r3jup8a9
Tags: 0.8.53-1
[Kartik Mistry]
* debian/control:
  + Added Michael Lustfield as co-maintainer
* nginx.conf:
  + No need to use regex in gzip_disable for msie6, Thanks to António P. P.
    Almeida <appa@perusio.net> (Closes: #592147)
* conf/sites-available/default:
  + Fixed typo for "include fastcgi", Thanks to Mostafa Ghadamyari
    <nginx@gigfa.com> (Closes: #593142, #593143)
* debian/patches/fix_reloading_ipv6.diff:
  + Removed, merged upstream
* debian/init.d:
  + Added fix to control nginx by user in a simple way by setting DAEMON
    variable to an invalid name in /etc/default/nginx. Patch by Toni Mueller
    <support@oeko.net> (Closes: #594598)
* debian/NEWS.Debian:
  + Updated news for 0.8.x as stable branch

[Michael Lustfield]
* New upstream release (Closes: #602970)
  + 0.8.x branch is declared stable by upstream now
* Add a UFW profile set:
  + debian/nginx.ufw.profile: Added.
  + debian/control: nginx: Suggests ufw.
  + debian/dirs: Add 'etc/ufw/applications.d'
  + debian/rules: Add install rule for the nginx UFW profile.
* Moved debian/dirs to debian/nginx.dirs
* Added types_hash_max_size to nginx.conf
* Install simple default index.html file (Closes: #581416)
  + debian/dirs: Add 'usr/share/nginx/www'.
  + debian/nginx.install: Add 'html/* usr/share/nginx/www'.
* debian/patches/nginx-echo.diff:
  + Added Echo module
* Added files for nginx.docs
  - /usr/share/doc/nginx/
    + debian/help/docs/fcgiwrap
    + debian/help/docs/php
    + debian/help/docs/support-irc
    + debian/help/docs/upstream
* Added files for nginx.examples
  - /usr/share/doc/nginx/examples/
    + debian/help/docs/drupal
    + debian/help/docs/http
    + debian/help/docs/mail
    + debian/help/docs/mailman
    + debian/help/docs/nginx.conf
    + debian/help/docs/virtual_hosts
    + debian/help/docs/wordpress
* debian/conf/:
  + Removed excess spaces
  + Added tabs where appropriate
  + Added SCRIPT_FILENAME to fastcgi_params

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
        sw_schema_slash_slash,
113
113
        sw_host,
114
114
        sw_port,
 
115
        sw_host_http_09,
115
116
        sw_after_slash_in_uri,
116
117
        sw_check_uri,
 
118
        sw_check_uri_http_09,
117
119
        sw_uri,
118
120
        sw_http_09,
119
121
        sw_http_H,
208
210
                        r->method = NGX_HTTP_MKCOL;
209
211
                    }
210
212
 
 
213
                    if (ngx_str5cmp(m, 'P', 'A', 'T', 'C', 'H')) {
 
214
                        r->method = NGX_HTTP_PATCH;
 
215
                    }
 
216
 
211
217
                    if (ngx_str5cmp(m, 'T', 'R', 'A', 'C', 'E')) {
212
218
                        r->method = NGX_HTTP_TRACE;
213
219
                    }
266
272
        /* space* before URI */
267
273
        case sw_spaces_before_uri:
268
274
 
269
 
            if (ch == '/' ){
 
275
            if (ch == '/') {
270
276
                r->uri_start = p;
271
277
                state = sw_after_slash_in_uri;
272
278
                break;
353
359
                 */
354
360
                r->uri_start = r->schema_end + 1;
355
361
                r->uri_end = r->schema_end + 2;
356
 
                state = sw_http_09;
 
362
                state = sw_host_http_09;
357
363
                break;
358
364
            default:
359
365
                return NGX_HTTP_PARSE_INVALID_REQUEST;
379
385
                 */
380
386
                r->uri_start = r->schema_end + 1;
381
387
                r->uri_end = r->schema_end + 2;
382
 
                state = sw_http_09;
383
 
                break;
384
 
            default:
385
 
                return NGX_HTTP_PARSE_INVALID_REQUEST;
386
 
            }
387
 
            break;
 
388
                state = sw_host_http_09;
 
389
                break;
 
390
            default:
 
391
                return NGX_HTTP_PARSE_INVALID_REQUEST;
 
392
            }
 
393
            break;
 
394
 
 
395
        /* space+ after "http://host[:port] " */
 
396
        case sw_host_http_09:
 
397
            switch (ch) {
 
398
            case ' ':
 
399
                break;
 
400
            case CR:
 
401
                r->http_minor = 9;
 
402
                state = sw_almost_done;
 
403
                break;
 
404
            case LF:
 
405
                r->http_minor = 9;
 
406
                goto done;
 
407
            case 'H':
 
408
                r->http_protocol.data = p;
 
409
                state = sw_http_H;
 
410
                break;
 
411
            default:
 
412
                return NGX_HTTP_PARSE_INVALID_REQUEST;
 
413
            }
 
414
            break;
 
415
 
388
416
 
389
417
        /* check "/.", "//", "%", and "\" (Win32) in URI */
390
418
        case sw_after_slash_in_uri:
397
425
            switch (ch) {
398
426
            case ' ':
399
427
                r->uri_end = p;
400
 
                state = sw_http_09;
 
428
                state = sw_check_uri_http_09;
401
429
                break;
402
430
            case CR:
403
431
                r->uri_end = p;
462
490
                break;
463
491
            case ' ':
464
492
                r->uri_end = p;
465
 
                state = sw_http_09;
 
493
                state = sw_check_uri_http_09;
466
494
                break;
467
495
            case CR:
468
496
                r->uri_end = p;
499
527
            }
500
528
            break;
501
529
 
 
530
        /* space+ after URI */
 
531
        case sw_check_uri_http_09:
 
532
            switch (ch) {
 
533
            case ' ':
 
534
                break;
 
535
            case CR:
 
536
                r->http_minor = 9;
 
537
                state = sw_almost_done;
 
538
                break;
 
539
            case LF:
 
540
                r->http_minor = 9;
 
541
                goto done;
 
542
            case 'H':
 
543
                r->http_protocol.data = p;
 
544
                state = sw_http_H;
 
545
                break;
 
546
            default:
 
547
                r->space_in_uri = 1;
 
548
                state = sw_check_uri;
 
549
                break;
 
550
            }
 
551
            break;
 
552
 
 
553
 
502
554
        /* URI */
503
555
        case sw_uri:
504
556
 
545
597
                state = sw_http_H;
546
598
                break;
547
599
            default:
548
 
                return NGX_HTTP_PARSE_INVALID_REQUEST;
 
600
                r->space_in_uri = 1;
 
601
                state = sw_uri;
 
602
                break;
549
603
            }
550
604
            break;
551
605
 
1187
1241
            if (ch >= '0' && ch <= '9') {
1188
1242
                ch = (u_char) ((decoded << 4) + ch - '0');
1189
1243
 
1190
 
                if (ch == '%') {
 
1244
                if (ch == '%' || ch == '#') {
1191
1245
                    state = sw_usual;
1192
1246
                    *u++ = ch;
1193
1247
                    ch = *p++;
1194
1248
                    break;
1195
 
                }
1196
 
 
1197
 
                if (ch == '#') {
1198
 
                    *u++ = ch;
1199
 
                    ch = *p++;
1200
1249
 
1201
1250
                } else if (ch == '\0') {
1202
1251
                    return NGX_HTTP_PARSE_INVALID_REQUEST;
1211
1260
                ch = (u_char) ((decoded << 4) + c - 'a' + 10);
1212
1261
 
1213
1262
                if (ch == '?') {
 
1263
                    state = sw_usual;
1214
1264
                    *u++ = ch;
1215
1265
                    ch = *p++;
 
1266
                    break;
1216
1267
 
1217
1268
                } else if (ch == '+') {
1218
1269
                    r->plus_in_uri = 1;
1267
1318
 
1268
1319
 
1269
1320
ngx_int_t
 
1321
ngx_http_parse_status_line(ngx_http_request_t *r, ngx_buf_t *b,
 
1322
    ngx_http_status_t *status)
 
1323
{
 
1324
    u_char   ch;
 
1325
    u_char  *p;
 
1326
    enum {
 
1327
        sw_start = 0,
 
1328
        sw_H,
 
1329
        sw_HT,
 
1330
        sw_HTT,
 
1331
        sw_HTTP,
 
1332
        sw_first_major_digit,
 
1333
        sw_major_digit,
 
1334
        sw_first_minor_digit,
 
1335
        sw_minor_digit,
 
1336
        sw_status,
 
1337
        sw_space_after_status,
 
1338
        sw_status_text,
 
1339
        sw_almost_done
 
1340
    } state;
 
1341
 
 
1342
    state = r->state;
 
1343
 
 
1344
    for (p = b->pos; p < b->last; p++) {
 
1345
        ch = *p;
 
1346
 
 
1347
        switch (state) {
 
1348
 
 
1349
        /* "HTTP/" */
 
1350
        case sw_start:
 
1351
            switch (ch) {
 
1352
            case 'H':
 
1353
                state = sw_H;
 
1354
                break;
 
1355
            default:
 
1356
                return NGX_ERROR;
 
1357
            }
 
1358
            break;
 
1359
 
 
1360
        case sw_H:
 
1361
            switch (ch) {
 
1362
            case 'T':
 
1363
                state = sw_HT;
 
1364
                break;
 
1365
            default:
 
1366
                return NGX_ERROR;
 
1367
            }
 
1368
            break;
 
1369
 
 
1370
        case sw_HT:
 
1371
            switch (ch) {
 
1372
            case 'T':
 
1373
                state = sw_HTT;
 
1374
                break;
 
1375
            default:
 
1376
                return NGX_ERROR;
 
1377
            }
 
1378
            break;
 
1379
 
 
1380
        case sw_HTT:
 
1381
            switch (ch) {
 
1382
            case 'P':
 
1383
                state = sw_HTTP;
 
1384
                break;
 
1385
            default:
 
1386
                return NGX_ERROR;
 
1387
            }
 
1388
            break;
 
1389
 
 
1390
        case sw_HTTP:
 
1391
            switch (ch) {
 
1392
            case '/':
 
1393
                state = sw_first_major_digit;
 
1394
                break;
 
1395
            default:
 
1396
                return NGX_ERROR;
 
1397
            }
 
1398
            break;
 
1399
 
 
1400
        /* the first digit of major HTTP version */
 
1401
        case sw_first_major_digit:
 
1402
            if (ch < '1' || ch > '9') {
 
1403
                return NGX_ERROR;
 
1404
            }
 
1405
 
 
1406
            state = sw_major_digit;
 
1407
            break;
 
1408
 
 
1409
        /* the major HTTP version or dot */
 
1410
        case sw_major_digit:
 
1411
            if (ch == '.') {
 
1412
                state = sw_first_minor_digit;
 
1413
                break;
 
1414
            }
 
1415
 
 
1416
            if (ch < '0' || ch > '9') {
 
1417
                return NGX_ERROR;
 
1418
            }
 
1419
 
 
1420
            break;
 
1421
 
 
1422
        /* the first digit of minor HTTP version */
 
1423
        case sw_first_minor_digit:
 
1424
            if (ch < '0' || ch > '9') {
 
1425
                return NGX_ERROR;
 
1426
            }
 
1427
 
 
1428
            state = sw_minor_digit;
 
1429
            break;
 
1430
 
 
1431
        /* the minor HTTP version or the end of the request line */
 
1432
        case sw_minor_digit:
 
1433
            if (ch == ' ') {
 
1434
                state = sw_status;
 
1435
                break;
 
1436
            }
 
1437
 
 
1438
            if (ch < '0' || ch > '9') {
 
1439
                return NGX_ERROR;
 
1440
            }
 
1441
 
 
1442
            break;
 
1443
 
 
1444
        /* HTTP status code */
 
1445
        case sw_status:
 
1446
            if (ch == ' ') {
 
1447
                break;
 
1448
            }
 
1449
 
 
1450
            if (ch < '0' || ch > '9') {
 
1451
                return NGX_ERROR;
 
1452
            }
 
1453
 
 
1454
            status->code = status->code * 10 + ch - '0';
 
1455
 
 
1456
            if (++status->count == 3) {
 
1457
                state = sw_space_after_status;
 
1458
                status->start = p - 2;
 
1459
            }
 
1460
 
 
1461
            break;
 
1462
 
 
1463
        /* space or end of line */
 
1464
        case sw_space_after_status:
 
1465
            switch (ch) {
 
1466
            case ' ':
 
1467
                state = sw_status_text;
 
1468
                break;
 
1469
            case '.':                    /* IIS may send 403.1, 403.2, etc */
 
1470
                state = sw_status_text;
 
1471
                break;
 
1472
            case CR:
 
1473
                state = sw_almost_done;
 
1474
                break;
 
1475
            case LF:
 
1476
                goto done;
 
1477
            default:
 
1478
                return NGX_ERROR;
 
1479
            }
 
1480
            break;
 
1481
 
 
1482
        /* any text until end of line */
 
1483
        case sw_status_text:
 
1484
            switch (ch) {
 
1485
            case CR:
 
1486
                state = sw_almost_done;
 
1487
 
 
1488
                break;
 
1489
            case LF:
 
1490
                goto done;
 
1491
            }
 
1492
            break;
 
1493
 
 
1494
        /* end of status line */
 
1495
        case sw_almost_done:
 
1496
            status->end = p - 1;
 
1497
            switch (ch) {
 
1498
            case LF:
 
1499
                goto done;
 
1500
            default:
 
1501
                return NGX_ERROR;
 
1502
            }
 
1503
        }
 
1504
    }
 
1505
 
 
1506
    b->pos = p;
 
1507
    r->state = state;
 
1508
 
 
1509
    return NGX_AGAIN;
 
1510
 
 
1511
done:
 
1512
 
 
1513
    b->pos = p + 1;
 
1514
 
 
1515
    if (status->end == NULL) {
 
1516
        status->end = p;
 
1517
    }
 
1518
 
 
1519
    r->state = sw_start;
 
1520
 
 
1521
    return NGX_OK;
 
1522
}
 
1523
 
 
1524
 
 
1525
ngx_int_t
1270
1526
ngx_http_parse_unsafe_uri(ngx_http_request_t *r, ngx_str_t *uri,
1271
1527
    ngx_str_t *args, ngx_uint_t *flags)
1272
1528
{