Skip to content
Browse files

Validate namespace kind, fix an uninitialized pointer

nsNameAndKindImpl constructor now validates the kind argument.

http://en.calameo.com player defines the empty namespace with a
namespace kind 0, which is not documented as legal value.
  • Loading branch information...
1 parent 5e88ff1 commit ea0347d7215f1517dc369551b1b9e6604a06bf4e @aajanki aajanki committed Feb 23, 2013
Showing with 52 additions and 9 deletions.
  1. +50 −7 src/swftypes.cpp
  2. +2 −2 src/swftypes.h
View
57 src/swftypes.cpp
@@ -209,27 +209,32 @@ std::ostream& lightspark::operator<<(std::ostream& s, const nsNameAndKind& r)
const char* prefix;
switch(r.getImpl().kind)
{
- case 0x08:
+ case NAMESPACE:
prefix="ns:";
break;
- case 0x16:
+ case PACKAGE_NAMESPACE:
prefix="pakns:";
break;
- case 0x17:
+ case PACKAGE_INTERNAL_NAMESPACE:
prefix="pakintns:";
break;
- case 0x18:
+ case PROTECTED_NAMESPACE:
prefix="protns:";
break;
- case 0x19:
+ case EXPLICIT_NAMESPACE:
prefix="explns:";
break;
- case 0x1a:
+ case STATIC_PROTECTED_NAMESPACE:
prefix="staticprotns:";
break;
- case 0x05:
+ case PRIVATE_NAMESPACE:
prefix="privns:";
break;
+ default:
+ //Not reached
+ assert("Unexpected namespace kind" && false);
+ prefix="";
+ break;
}
s << prefix << r.getImpl().name;
return s;
@@ -1423,6 +1428,44 @@ const nsNameAndKindImpl& nsNameAndKind::getImpl() const
return getSys()->getNamespaceFromUniqueId(nsRealId);
}
+nsNameAndKindImpl::nsNameAndKindImpl(const tiny_string& _name, NS_KIND _kind, uint32_t b)
+ : name(_name),kind(_kind),baseId(b)
+{
+ if (kind != NAMESPACE &&
+ kind != PACKAGE_NAMESPACE &&
+ kind != PACKAGE_INTERNAL_NAMESPACE &&
+ kind != PROTECTED_NAMESPACE &&
+ kind != EXPLICIT_NAMESPACE &&
+ kind != STATIC_PROTECTED_NAMESPACE &&
+ kind != PRIVATE_NAMESPACE)
+ {
+ //I have seen empty namespace with kind 0. For other
+ //namespaces we should not get here.
+ if (!name.empty())
+ LOG(LOG_ERROR, "Invalid namespace kind, converting to public namespace");
+ kind = NAMESPACE;
+ }
+}
+
+nsNameAndKindImpl::nsNameAndKindImpl(const char* _name, NS_KIND _kind, uint32_t b)
+ : name(_name),kind(_kind),baseId(b)
+{
+ if (kind != NAMESPACE &&
+ kind != PACKAGE_NAMESPACE &&
+ kind != PACKAGE_INTERNAL_NAMESPACE &&
+ kind != PROTECTED_NAMESPACE &&
+ kind != EXPLICIT_NAMESPACE &&
+ kind != STATIC_PROTECTED_NAMESPACE &&
+ kind != PRIVATE_NAMESPACE)
+ {
+ //I have seen empty namespace with kind 0. For other
+ //namespaces we should not get here.
+ if (!name.empty())
+ LOG(LOG_ERROR, "Invalid namespace kind, converting to public namespace");
+ kind = NAMESPACE;
+ }
+}
+
RGB::RGB(const tiny_string& colorstr):Red(0),Green(0),Blue(0)
{
if (colorstr.empty())
View
4 src/swftypes.h
@@ -292,8 +292,8 @@ struct nsNameAndKindImpl
tiny_string name;
NS_KIND kind;
uint32_t baseId;
- nsNameAndKindImpl(const tiny_string& _name, NS_KIND _kind, uint32_t b=-1):name(_name),kind(_kind),baseId(b){}
- nsNameAndKindImpl(const char* _name, NS_KIND _kind, uint32_t b=-1):name(_name),kind(_kind),baseId(b){}
+ nsNameAndKindImpl(const tiny_string& _name, NS_KIND _kind, uint32_t b=-1);
+ nsNameAndKindImpl(const char* _name, NS_KIND _kind, uint32_t b=-1);
bool operator<(const nsNameAndKindImpl& r) const
{
if(kind==r.kind)

0 comments on commit ea0347d

Please sign in to comment.
Something went wrong with that request. Please try again.