Overview
Comment: | Make using -[tryReadLine] + OFStreamObserver safe.
This makes it impossible for the developer to accidentally create a DoS. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
535c2d5d9bc4d7c65853b74c44025684 |
User & Date: | js on 2011-09-19 16:22:23 |
Other Links: | manifest | tags |
Context
2011-09-19
| ||
16:34 |
Rename -[allocMemoryForNItems:withSize:] and friends. It is now -[allocMemoryForNItems:ofSize:]. check-in: f173477bef user: js tags: trunk | |
16:22 | Make using -[tryReadLine] + OFStreamObserver safe. check-in: 535c2d5d9b user: js tags: trunk | |
13:07 |
Rename -[bindToPort:onHost:] to -[bindToHost:port:]. This way it's consistent with -[connectToHost:port]. check-in: b8517c63ca user: js tags: trunk | |
Changes
Modified src/OFStream.h from [d46e5522c2] to [3697389637].
︙ | |||
33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | + | @interface OFStream: OFObject { char *cache; char *writeBuffer; size_t cacheLength, writeBufferLength; BOOL buffersWrites; BOOL blocking; BOOL waitingForDelimiter; } #ifdef OF_HAVE_PROPERTIES @property (assign, getter=isBlocking) BOOL blocking; #endif /** |
︙ | |||
799 800 801 802 803 804 805 806 | 800 801 802 803 804 805 806 807 808 809 810 811 | + + + + | */ - (int)fileDescriptor; /** * \brief Closes the stream. */ - (void)close; /// \cond internal - (BOOL)_isWaitingForDelimiter; /// \endcond @end |
Modified src/OFStream.m from [69277f1386] to [d011dc479a].
︙ | |||
503 504 505 506 507 508 509 | 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | - + - - + | } @finally { [self freeMemory: buffer]; } return ret; } |
︙ | |||
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | + - + + + + | memcpy(newCache, cache + i + 1, cacheLength - i - 1); [self freeMemory: cache]; cache = newCache; cacheLength -= i + 1; waitingForDelimiter = NO; return ret; } } } /* Read and see if we get a newline or \0 */ buffer = [self allocMemoryWithSize: of_pagesize]; @try { if ([self _isAtEndOfStream]) { |
︙ | |||
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | + + - + - - - - - - - - - - - - + - - + | memcpy(newCache, buffer + i + 1, bufferLength - i - 1); [self freeMemory: cache]; cache = newCache; cacheLength = bufferLength - i - 1; waitingForDelimiter = NO; return ret; } } /* There was no newline or \0 */ cache = [self resizeMemory: cache toSize: cacheLength + bufferLength]; /* * It's possible that cacheLen + len is 0 and thus cache was * set to NULL by resizeMemory:toSize:. */ if (cache != NULL) memcpy(cache + cacheLength, buffer, bufferLength); cacheLength += bufferLength; } @finally { [self freeMemory: buffer]; } waitingForDelimiter = YES; return nil; } - (OFString*)readLine { return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)readLineWithEncoding: (of_string_encoding_t)encoding { OFString *line = nil; |
︙ | |||
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | + - + + + + | memcpy(newCache, cache + i + 1, cacheLength - i - 1); [self freeMemory: cache]; cache = newCache; cacheLength -= i + 1; waitingForDelimiter = NO; return ret; } } } /* Read and see if we get a delimiter or \0 */ buffer = [self allocMemoryWithSize: of_pagesize]; @try { if ([self _isAtEndOfStream]) { |
︙ | |||
790 791 792 793 794 795 796 797 798 799 800 801 802 803 | 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 | + | memcpy(newCache, buffer + i + 1, bufferLength - i - 1); [self freeMemory: cache]; cache = newCache; cacheLength = bufferLength - i - 1; waitingForDelimiter = NO; return ret; } } /* Neither the delimiter nor \0 was found */ cache = [self resizeMemory: cache toSize: cacheLength + bufferLength]; |
︙ | |||
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 | 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | + - - - - - - + + - - - - - - - - - | bufferLength); cacheLength += bufferLength; } @finally { [self freeMemory: buffer]; } waitingForDelimiter = YES; return nil; } - (OFString*)readTillDelimiter: (OFString*)delimiter { return [self readTillDelimiter: delimiter withEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)readTillDelimiter: (OFString*)delimiter withEncoding: (of_string_encoding_t)encoding { OFString *ret = nil; |
︙ | |||
1400 1401 1402 1403 1404 1405 1406 1407 | 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 | + + + + + | } - (void)close { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - (BOOL)_isWaitingForDelimiter { return waitingForDelimiter; } @end |
Modified src/OFStreamObserver.h from [753eef6385] to [aece4ad798].
︙ | |||
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | + + + + + + + | @protocol OFStreamObserverDelegate #endif #ifdef OF_HAVE_OPTIONAL_PROTOCOLS @optional #endif /** * \brief This callback is called when a stream did get ready for reading. * * NOTE: When -[tryReadLine] or -[tryReadTillDelimiter:] has been called on the * the stream, this callback will not be called again until new data has * been received, even though there is still data in the cache. The reason * for this is to prevent spinning in a loop when there is an incomplete * string in the cache. Once the string is complete, the callback will be * called again if there is data in the cache. * * \param stream The stream which did become ready for reading */ - (void)streamIsReadyForReading: (OFStream*)stream; /** * \brief This callback is called when a stream did get ready for writing. |
︙ |
Modified src/OFStreamObserver.m from [26a8940bc6] to [332048c7be].
︙ | |||
352 353 354 355 356 357 358 | 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | - + + | OFStream **cArray = [readStreams cArray]; size_t i, count = [readStreams count]; BOOL foundInCache = NO; pool = [[OFAutoreleasePool alloc] init]; for (i = 0; i < count; i++) { |
︙ |