From 8256fc1b42490765ebc1cd1e4ed4557261ca2312 Mon Sep 17 00:00:00 2001 From: "U-SLAVA-DFB8FF805\\Slava" Date: Mon, 19 May 2008 19:53:39 -0500 Subject: [PATCH 1/4] Fix windows.com load errors --- extra/windows/com/com-tests.factor | 2 +- extra/windows/com/wrapper/wrapper-docs.factor | 3 ++- extra/windows/com/wrapper/wrapper.factor | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) mode change 100644 => 100755 extra/windows/com/com-tests.factor mode change 100644 => 100755 extra/windows/com/wrapper/wrapper-docs.factor diff --git a/extra/windows/com/com-tests.factor b/extra/windows/com/com-tests.factor old mode 100644 new mode 100755 index e2685db1d0..abba8874d6 --- a/extra/windows/com/com-tests.factor +++ b/extra/windows/com/com-tests.factor @@ -1,7 +1,7 @@ USING: kernel windows.com windows.com.syntax windows.ole32 alien alien.syntax tools.test libc alien.c-types arrays.lib namespaces arrays continuations accessors math windows.com.wrapper -windows.com.wrapper.private ; +windows.com.wrapper.private destructors ; IN: windows.com.tests COM-INTERFACE: ISimple IUnknown {216fb341-0eb2-44b1-8edb-60b76e353abc} diff --git a/extra/windows/com/wrapper/wrapper-docs.factor b/extra/windows/com/wrapper/wrapper-docs.factor old mode 100644 new mode 100755 index 51a3549047..89b199a38b --- a/extra/windows/com/wrapper/wrapper-docs.factor +++ b/extra/windows/com/wrapper/wrapper-docs.factor @@ -1,5 +1,6 @@ USING: help.markup help.syntax io kernel math quotations -multiline alien windows.com windows.com.syntax continuations ; +multiline alien windows.com windows.com.syntax continuations +destructors ; IN: windows.com.wrapper HELP: diff --git a/extra/windows/com/wrapper/wrapper.factor b/extra/windows/com/wrapper/wrapper.factor index ae5f03a594..5b7bb63590 100755 --- a/extra/windows/com/wrapper/wrapper.factor +++ b/extra/windows/com/wrapper/wrapper.factor @@ -2,7 +2,7 @@ USING: alien alien.c-types windows.com.syntax windows.com.syntax.private windows.com continuations kernel sequences.lib namespaces windows.ole32 libc assocs accessors arrays sequences quotations combinators -math combinators.lib words compiler.units ; +math combinators.lib words compiler.units destructors ; IN: windows.com.wrapper TUPLE: com-wrapper vtbls freed? ; From 6df45b864b991359aa43fd862342d4e107d9dda8 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 19 May 2008 20:43:28 -0500 Subject: [PATCH 2/4] Fix potential DoS attack --- .../unix/sockets/secure/secure-tests.factor | 85 +++++++------------ extra/io/unix/sockets/secure/secure.factor | 14 +-- 2 files changed, 38 insertions(+), 61 deletions(-) diff --git a/extra/io/unix/sockets/secure/secure-tests.factor b/extra/io/unix/sockets/secure/secure-tests.factor index c68b497493..5b8fd5ac23 100644 --- a/extra/io/unix/sockets/secure/secure-tests.factor +++ b/extra/io/unix/sockets/secure/secure-tests.factor @@ -2,85 +2,60 @@ IN: io.sockets.secure.tests USING: accessors kernel namespaces io io.sockets io.sockets.secure io.encodings.ascii io.streams.duplex classes words destructors threads tools.test -concurrency.promises byte-arrays ; +concurrency.promises byte-arrays locals ; \ must-infer { 1 0 } [ [ ] with-secure-context ] must-infer-as [ ] [ "port" set ] unit-test -[ ] [ +: with-test-context + + "resource:extra/openssl/test/server.pem" >>key-file + "resource:extra/openssl/test/root.pem" >>ca-file + "resource:extra/openssl/test/dh1024.pem" >>dh-file + "password" >>password + swap with-secure-context ; + +:: server-test ( quot -- ) [ - - "resource:extra/openssl/test/server.pem" >>key-file - "resource:extra/openssl/test/root.pem" >>ca-file - "resource:extra/openssl/test/dh1024.pem" >>dh-file - "password" >byte-array >>password [ "127.0.0.1" 0 ascii [ dup addr>> addrspec>> port>> "port" get fulfill accept [ - class word-name write + quot call ] curry with-stream ] with-disposal - ] with-secure-context - ] "SSL server test" spawn drop -] unit-test + ] with-test-context + ] "SSL server test" spawn drop ; -[ "secure" ] [ +: client-test [ "127.0.0.1" "port" get ?promise ascii drop contents - ] with-secure-context -] unit-test + ] with-secure-context ; + +[ ] [ [ class word-name write ] server-test ] unit-test + +[ "secure" ] [ client-test ] unit-test ! Now, see what happens if the server closes the connection prematurely -! [ ] [ "port" set ] unit-test -! -! [ ] [ -! [ -! -! "resource:extra/openssl/test/server.pem" >>key-file -! "resource:extra/openssl/test/root.pem" >>ca-file -! "resource:extra/openssl/test/dh1024.pem" >>dh-file -! "password" >byte-array >>password -! [ -! "127.0.0.1" 0 ascii [ -! dup addr>> addrspec>> port>> "port" get fulfill -! accept drop -! [ -! dup in>> stream>> handle>> f >>connected drop -! "hello" over stream-write dup stream-flush -! ] with-disposal -! ] with-disposal -! ] with-secure-context -! ] "SSL server test" spawn drop -! ] unit-test +[ ] [ "port" set ] unit-test -! [ -! [ -! "127.0.0.1" "port" get ?promise ascii drop contents -! ] with-secure-context -! ] [ \ premature-close = ] must-fail-with +[ ] [ + [ + drop + input-stream get stream>> handle>> f >>connected drop + "hello" write flush + ] server-test +] unit-test + +[ client-test ] [ premature-close? ] must-fail-with ! Now, try validating the certificate. This should fail because its ! actually an invalid certificate [ ] [ "port" set ] unit-test -[ ] [ - [ - - "resource:extra/openssl/test/server.pem" >>key-file - "resource:extra/openssl/test/root.pem" >>ca-file - "resource:extra/openssl/test/dh1024.pem" >>dh-file - "password" >>password - [ - "127.0.0.1" 0 ascii [ - dup addr>> addrspec>> port>> "port" get fulfill - accept drop dispose - ] with-disposal - ] with-secure-context - ] "SSL server test" spawn drop -] unit-test +[ ] [ [ drop ] server-test ] unit-test [ [ diff --git a/extra/io/unix/sockets/secure/secure.factor b/extra/io/unix/sockets/secure/secure.factor index 9feeb90690..35f72a5d16 100755 --- a/extra/io/unix/sockets/secure/secure.factor +++ b/extra/io/unix/sockets/secure/secure.factor @@ -125,12 +125,14 @@ M: secure (accept) { { 1 [ drop f ] } { 0 [ - dup handle>> SSL_want - { - { SSL_NOTHING [ dup handle>> SSL_shutdown check-shutdown-response ] } - { SSL_READING [ drop +input+ ] } - { SSL_WRITING [ drop +output+ ] } - } case + dup handle>> dup f 0 SSL_read 2dup SSL_get_error + { + { SSL_ERROR_ZERO_RETURN [ 2drop dup handle>> SSL_shutdown check-shutdown-response ] } + { SSL_ERROR_WANT_READ [ 3drop +input+ ] } + { SSL_ERROR_WANT_WRITE [ 3drop +output+ ] } + { SSL_ERROR_SYSCALL [ syscall-error ] } + { SSL_ERROR_SSL [ (ssl-error) ] } + } case ] } { -1 [ handle>> -1 SSL_get_error From e9ee2dc654fb55c8060696fb04f8e79d931b8892 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Mon, 19 May 2008 21:28:32 -0500 Subject: [PATCH 3/4] sequences-docs: Fix typo --- core/sequences/sequences-docs.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index 8b15f5b980..351ba89692 100755 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -821,8 +821,8 @@ HELP: 3append HELP: subseq { $values { "from" "a non-negative integer" } { "to" "a non-negative integer" } { "seq" sequence } { "subseq" "a new sequence" } } -{ $description "Outputs a new sequence consisting of all elements starting from and including " { $snippet "m" } ", and up to but not including " { $snippet "n" } "." } -{ $errors "Throws an error if " { $snippet "m" } " or " { $snippet "n" } " is out of bounds." } ; +{ $description "Outputs a new sequence consisting of all elements starting from and including " { $snippet "from" } ", and up to but not including " { $snippet "to" } "." } +{ $errors "Throws an error if " { $snippet "from" } " or " { $snippet "to" } " is out of bounds." } ; HELP: clone-like { $values { "seq" sequence } { "exemplar" sequence } { "newseq" "a new sequence" } } From 75eded700dc4912a162204117db1fb6ee88b4cc0 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Mon, 19 May 2008 21:30:55 -0500 Subject: [PATCH 4/4] io.binary-docs: fix typo --- core/io/binary/binary-docs.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/io/binary/binary-docs.factor b/core/io/binary/binary-docs.factor index edf65491fe..507571c044 100644 --- a/core/io/binary/binary-docs.factor +++ b/core/io/binary/binary-docs.factor @@ -6,12 +6,12 @@ ARTICLE: "stream-binary" "Working with binary data" $nl "There are two ways to order the bytes making up an integer; " { $emphasis "little endian" } " byte order outputs the least significant byte first, and the most significant byte last, whereas " { $emphasis "big endian" } " is the other way around." $nl -"Consider the hexadecimal integer "{ $snippet "HEX: cafebabe" } ". Big endian byte order yields the following sequence of bytes:" +"Consider the hexadecimal integer "{ $snippet "HEX: cafebabe" } ". Little endian byte order yields the following sequence of bytes:" { $table { "Byte:" "1" "2" "3" "4" } { "Value:" { $snippet "be" } { $snippet "ba" } { $snippet "fe" } { $snippet "ca" } } } -"Compare this with little endian byte order:" +"Compare this with big endian byte order:" { $table { "Byte:" "1" "2" "3" "4" } { "Value:" { $snippet "ca" } { $snippet "fe" } { $snippet "ba" } { $snippet "be" } }