Mercurial > hg > orthanc-python
diff Sources/RestCallbacks.cpp @ 45:ee76cced46a5
Fix issue #185 (segfaults on non-UTF8 special characters in request URI)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Aug 2020 18:13:10 +0200 |
parents | fd58eb5749ed |
children | 664a12539073 |
line wrap: on
line diff
--- a/Sources/RestCallbacks.cpp Wed Jul 08 15:22:12 2020 +0200 +++ b/Sources/RestCallbacks.cpp Mon Aug 03 18:13:10 2020 +0200 @@ -19,7 +19,7 @@ #include "RestCallbacks.h" -#include "PythonObject.h" +#include "PythonString.h" #include "Autogenerated/sdk.h" #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" @@ -90,9 +90,11 @@ /** * Construct the arguments tuple (output, uri) **/ + PythonString str(lock, uri); + PythonObject args2(lock, PyTuple_New(2)); PyTuple_SetItem(args2.GetPyObject(), 0, pInst); - PyTuple_SetItem(args2.GetPyObject(), 1, PyUnicode_FromString(uri)); + PyTuple_SetItem(args2.GetPyObject(), 1, str.Release()); // No need to decrement refcount with "PyTuple_SetItem()" /** @@ -120,16 +122,21 @@ default: ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); } - + PythonObject kw(lock, PyDict_New()); - PyDict_SetItemString(kw.GetPyObject(), "method", PyUnicode_FromString(method)); + + { + PythonString str(lock, method); + PyDict_SetItemString(kw.GetPyObject(), "method", str.Release()); + } { PythonObject groups(lock, PyTuple_New(request->groupsCount)); for (uint32_t i = 0; i < request->groupsCount; i++) { - PyTuple_SetItem(groups.GetPyObject(), i, PyUnicode_FromString(request->groups[i])); + PythonString str(lock, request->groups[i]); + PyTuple_SetItem(groups.GetPyObject(), i, str.Release()); } PyDict_SetItemString(kw.GetPyObject(), "groups", groups.Release()); @@ -141,8 +148,8 @@ for (uint32_t i = 0; i < request->getCount; i++) { - PyDict_SetItemString(get.GetPyObject(), request->getKeys[i], - PyUnicode_FromString(request->getValues[i])); + PythonString value(lock, request->getValues[i]); + PyDict_SetItemString(get.GetPyObject(), request->getKeys[i], value.Release()); } PyDict_SetItemString(kw.GetPyObject(), "get", get.Release()); @@ -153,8 +160,8 @@ for (uint32_t i = 0; i < request->headersCount; i++) { - PyDict_SetItemString(headers.GetPyObject(), request->headersKeys[i], - PyUnicode_FromString(request->headersValues[i])); + PythonString value(lock, request->headersValues[i]); + PyDict_SetItemString(headers.GetPyObject(), request->headersKeys[i], value.Release()); } PyDict_SetItemString(kw.GetPyObject(), "headers", headers.Release());