Skip to content
This repository has been archived by the owner on Feb 16, 2025. It is now read-only.

cpp: malformed key names not rejected #2583

Closed
markus2330 opened this issue Apr 4, 2019 · 4 comments
Closed

cpp: malformed key names not rejected #2583

markus2330 opened this issue Apr 4, 2019 · 4 comments

Comments

@markus2330
Copy link
Contributor

markus2330 commented Apr 4, 2019

Steps to Reproduce the Problem

import kdb
k = kdb.Key("abc")
k.name="abc"

Expected Result

That for both ways to assign the key's name an exception is raised that "abc" is not a valid keyname.

Actual Result

k = kdb.Key("abc")
#> <kdb.Key; proxy of <Swig Object of type 'kdb::Key *' at 0x7f9ec38b2c90> >
k.name
#> ''
k.name="abc"
#> segfault

System Information

  • Elektra Version: master
@manuelm manuelm changed the title python: malformed key names not rejected cpp: malformed key names not rejected Oct 31, 2019
@manuelm
Copy link
Contributor

manuelm commented Oct 31, 2019

I've modified the title as this is no python nor swig issue. A possible fix, feel free to commit this:

--- a/src/bindings/cpp/include/key.hpp
+++ b/src/bindings/cpp/include/key.hpp
@@ -604,6 +604,7 @@ inline Key::Key (const char * keyName, ...)
        va_end (ap);
 
        if (!key) throw std::bad_alloc ();
+       if (ckdb::keyGetUnescapedNameSize (key) <= 0) throw KeyInvalidName ();
 
        operator++ ();
 }
@@ -628,6 +629,7 @@ inline Key::Key (const std::string keyName, ...)
        va_end (ap);
 
        if (!key) throw std::bad_alloc ();
+       if (ckdb::keyGetUnescapedNameSize (key) <= 0) throw KeyInvalidName ();
 
        operator++ ();
 }
@@ -645,6 +647,7 @@ inline Key::Key (const char * keyName, va_list ap)
        key = ckdb::keyVNew (keyName, ap);
 
        if (!key) throw std::bad_alloc ();
+       if (ckdb::keyGetUnescapedNameSize (key) <= 0) throw KeyInvalidName ();
 
        operator++ ();
 }

@markus2330
Copy link
Contributor Author

Thank you! Can you please add this commit to your PR?

@manuelm
Copy link
Contributor

manuelm commented Oct 31, 2019

@markus2330 As expected changing the ctor to throw on invalid names makes tests fail on other places. Can you or someone else please take over ea8a01e. I feel like I've already invested enough time in this.

@markus2330
Copy link
Contributor Author

Actually this problem will solve itself once #3115 is merged. Because then keyNew will fail with malformed key names.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants