gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r10408: Fix to SharedObject name.


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10408: Fix to SharedObject name.
Date: Thu, 11 Dec 2008 09:35:24 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10408
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2008-12-11 09:35:24 +0100
message:
  Fix to SharedObject name.
modified:
  libcore/asobj/AsBroadcaster.h
  libcore/asobj/SharedObject.cpp
  libcore/asobj/XMLSocket_as.cpp
  testsuite/actionscript.all/SharedObject.as
    ------------------------------------------------------------
    revno: 10407.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2008-12-11 09:18:23 +0100
    message:
      Test and validate SOL names. Clean up some code.
    modified:
      libcore/asobj/AsBroadcaster.h
      libcore/asobj/SharedObject.cpp
      libcore/asobj/XMLSocket_as.cpp
      testsuite/actionscript.all/SharedObject.as
=== modified file 'libcore/asobj/AsBroadcaster.h'
--- a/libcore/asobj/AsBroadcaster.h     2008-10-20 09:11:19 +0000
+++ b/libcore/asobj/AsBroadcaster.h     2008-12-11 08:18:23 +0000
@@ -41,7 +41,7 @@
        /// can call this internally.
        ///
        /// The AsBroadcaster_init will take care of registering
-       /// the _global.AsBroadcaster object and it's 'initialize'
+       /// the _global.AsBroadcaster object and its 'initialize'
        /// method for user-defined broadcasters initialization
        ///
        static void initialize(as_object& obj);

=== modified file 'libcore/asobj/SharedObject.cpp'
--- a/libcore/asobj/SharedObject.cpp    2008-12-10 10:06:17 +0000
+++ b/libcore/asobj/SharedObject.cpp    2008-12-11 08:18:23 +0000
@@ -21,13 +21,11 @@
 #include "gnashconfig.h" // USE_SOL_READ_ONLY
 #endif
 
-#include "GnashSystemIOHeaders.h"
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <boost/tokenizer.hpp>
 #include <boost/scoped_array.hpp>
 #include <boost/shared_ptr.hpp>
-#include <cerrno>
 
 #include "SimpleBuffer.h"
 #include "as_value.h"
@@ -54,7 +52,6 @@
 #define BUFFERED_AMF_SOL
 
 namespace {
-//gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
 gnash::RcInitFile& rcfile = gnash::RcInitFile::getDefaultInstance();
 }
 
@@ -62,10 +59,6 @@
 
 namespace gnash {
 
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 64
-#endif
-
 // Forward declarations
 namespace {
 
@@ -90,6 +83,7 @@
     as_object* getSharedObjectInterface();
     void attachSharedObjectStaticInterface(as_object& o);
     bool createDirForFile(const std::string& filespec);
+    bool validateName(const std::string& solName);
 }
 
 // Serializer helper
@@ -493,7 +487,7 @@
     assert (!objName.empty());
 
     // already warned about it at construction time
-    if (_solSafeDir.empty()) return 0; 
+    if (_solSafeDir.empty()) return 0;
 
     if (rcfile.getSOLLocalDomain() && !_baseDomain.empty()) 
     {
@@ -502,6 +496,9 @@
         return 0;
     }
 
+    // Check that the name is valid; if not, return null
+    if (!validateName(objName)) return 0;
+
     // The 'root' argument, otherwise known as localPath, specifies where
     // in the SWF path the SOL should be stored. It cannot be outside this
     // path.
@@ -885,6 +882,23 @@
     return as_value(obj.get()); // will keep alive
 }
 
+/// Return true if the name is a valid SOL name.
+//
+/// The official docs claim that '%' is also an invalid character,
+/// but that is incorrect (see actionscript.all/SharedObject.as)
+bool
+validateName(const std::string& solName)
+{
+    // A double forward slash isn't allowed
+    std::string::size_type pos = solName.find("//");
+    if (pos != std::string::npos) return false;
+
+    // These characters are also illegal
+    pos = solName.find_first_of(",~;\"'<&>?#:\\ ");
+
+    return (pos == std::string::npos);
+}
+
 as_object*
 readSOL(VM& vm, const std::string& filespec)
 {

=== modified file 'libcore/asobj/XMLSocket_as.cpp'
--- a/libcore/asobj/XMLSocket_as.cpp    2008-11-21 15:15:25 +0000
+++ b/libcore/asobj/XMLSocket_as.cpp    2008-12-11 08:18:23 +0000
@@ -91,8 +91,6 @@
        /// Return the as_function with given name, converting case if needed
        boost::intrusive_ptr<as_function> getEventHandler(const std::string& 
name);
 
-    bool _data;
-
     MessageList _messages;
 
     std::string _remainder;
@@ -102,8 +100,7 @@
   
 XMLSocket_as::XMLSocket_as()
     :
-    as_object(getXMLSocketInterface()),
-    _data(false)
+    as_object(getXMLSocketInterface())
 {
     attachXMLSocketProperties(*this);
 }
@@ -131,8 +128,6 @@
 void
 XMLSocket_as::close()
 {
-    GNASH_REPORT_FUNCTION;
-
     assert(_connected);
 
     closeNet();
@@ -264,11 +259,13 @@
     log_debug(_("XMLSocket.connect(%s) called"), ss.str());
 #endif
 
-    boost::intrusive_ptr<XMLSocket_as> ptr = 
ensureType<XMLSocket_as>(fn.this_ptr);
+    boost::intrusive_ptr<XMLSocket_as> ptr =
+        ensureType<XMLSocket_as>(fn.this_ptr);
 
     if (ptr->connected())
     {
-        log_error(_("XMLSocket.connect() called while already connected, 
ignored"));
+        log_error(_("XMLSocket.connect() called while already "
+                    "connected, ignored"));
     }
     
     as_value hostval = fn.arg(0);
@@ -277,9 +274,10 @@
     
     if (!ptr->connect(host, port))
     {
-        return as_value(false);
         // onConnect(false) should not be called here, but rather
         // only if a failure occurs after the initial connection.
+        log_error(_("XMLSocket.connect(): connection failed"));
+        return as_value(false);
     }
 
     // Actually, if first-stage connection was successful, we
@@ -291,7 +289,7 @@
     // The same applies to onConnect(false), which will never
     // be called at the moment.
     //
-    log_debug(_("XMLSocket.connect(): tring to call onConnect"));
+    log_debug(_("XMLSocket.connect(): trying to call onConnect"));
     ptr->callMethod(NSV::PROP_ON_CONNECT, true);
            
 
@@ -299,10 +297,12 @@
     log_debug(_("Setting up timer for calling XMLSocket.onData()"));
 
     std::auto_ptr<Timer> timer(new Timer);
-    boost::intrusive_ptr<builtin_function> ondata_handler = new 
builtin_function(&xmlsocket_inputChecker, NULL);
+    boost::intrusive_ptr<builtin_function> ondata_handler =
+        new builtin_function(&xmlsocket_inputChecker, NULL);
     // just make sure it's expired at every frame iteration (20 FPS used here)
     unsigned interval = 50;
-    timer->setInterval(*ondata_handler, interval, 
boost::dynamic_pointer_cast<as_object>(ptr));
+    timer->setInterval(*ondata_handler, interval,
+            boost::dynamic_pointer_cast<as_object>(ptr));
 
     VM& vm = ptr->getVM();
     vm.getRoot().add_interval_timer(timer, true);

=== modified file 'testsuite/actionscript.all/SharedObject.as'
--- a/testsuite/actionscript.all/SharedObject.as        2008-12-10 10:06:17 
+0000
+++ b/testsuite/actionscript.all/SharedObject.as        2008-12-11 08:18:23 
+0000
@@ -85,6 +85,9 @@
 // public data that gets written
 #if OUTPUT_VERSION > 5
 check(so.hasOwnProperty("data"));
+check(!so.data.hasOwnProperty("toString"));
+check(!so.data.hasOwnProperty("valueOf"));
+check_equals(typeof(so.data.valueOf), "function");
 #endif
 
 so.data.gain = 50.0;
@@ -104,10 +107,60 @@
 so.data.tmp = "custom value";
 so2 = SharedObject.getLocal("level1/level2/settings", "/");
 check_equals(so2.data.tmp, "custom value");
+check_equals(so2.data.toString(), "[object Object]");
 check_equals(so, so2);
 
+// Check SOL names validity.
 so2bis = SharedObject.getLocal("level1//level2/settings", "/");
-xcheck_equals(typeof(so2bis), 'null'); // invalid path
+check_equals(typeof(so2bis), 'null'); // invalid path
+so2bis = SharedObject.getLocal("a");
+check_equals(typeof(so2bis), 'object'); 
+so2bis = SharedObject.getLocal("a~");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a ");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a'");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("%");
+check_equals(typeof(so2bis), 'object'); 
+so2bis = SharedObject.getLocal("a%");
+check_equals(typeof(so2bis), 'object'); 
+so2bis = SharedObject.getLocal("a&");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a\\");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a;");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a:");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a\"");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a,");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a>");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a<");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a#");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a?");
+check_equals(typeof(so2bis), 'null'); 
+so2bis = SharedObject.getLocal("a(");
+check_equals(typeof(so2bis), 'object'); 
+so2bis = SharedObject.getLocal("a)");
+check_equals(typeof(so2bis), 'object'); 
+so2bis = SharedObject.getLocal("a{");
+check_equals(typeof(so2bis), 'object'); 
+so2bis = SharedObject.getLocal("a}");
+check_equals(typeof(so2bis), 'object'); 
+so2bis = SharedObject.getLocal("a$");
+check_equals(typeof(so2bis), 'object'); 
+so2bis = SharedObject.getLocal("a!");
+check_equals(typeof(so2bis), 'object'); 
+so2bis = SharedObject.getLocal("ΓΌ");
+check_equals(typeof(so2bis), 'object');
+so2bis = SharedObject.getLocal("a*");
+check_equals(typeof(so2bis), 'object'); 
 
 so2bis = SharedObject.getLocal("level1/./level2/settings", "/");
 check_equals(typeof(so2bis), 'object'); // valid path
@@ -296,12 +349,12 @@
 // END OF TESTS
 //------------------------------------------
 
-check_totals(88);
+check_totals(116);
 
 #else
 
 // SWF5 totals
-check_totals(17);
+check_totals(42);
 
 #endif
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]