]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[fdxhook] Fixed some empty vector dereferences
authorFrancis Dupont <fdupont@isc.org>
Thu, 23 Jun 2016 17:48:34 +0000 (19:48 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 23 Jun 2016 17:48:34 +0000 (19:48 +0200)
src/hooks/external/lua/loption.cc
src/hooks/external/lua/lpkt4.cc
src/hooks/external/ocaml/dso.c
src/hooks/external/ocaml/opt.c
src/hooks/external/python/poption.cc
src/hooks/external/python/ppkt4.cc

index d36222c001beafe18202d3d74f1d8ab9cb5cd5ec..e4923c6c3e2ff9fefa6f2b5bf67b6999adf5db8e 100644 (file)
@@ -115,7 +115,11 @@ int toBinary(lua_State* L) {
     l_option* const self =
         static_cast<l_option*>(luaL_checkudata(L, 1, LUA_KEAOPTION));
     vector<uint8_t> bin = self->object->toBinary(true);
-    lua_pushlstring(L, reinterpret_cast<char*>(&bin[0]), bin.size());
+    char* ptr = NULL;
+    if (!bin.empty()) {
+        ptr = reinterpret_cast<char*>(&bin[0]);
+    }
+    lua_pushlstring(L, ptr, bin.size());
     return (1);
 }
 
@@ -148,7 +152,11 @@ int getData(lua_State* L) {
     l_option* const self =
         static_cast<l_option*>(luaL_checkudata(L, 1, LUA_KEAOPTION));
     const OptionBuffer& data = self->object->getData();
-    lua_pushlstring(L, reinterpret_cast<const char*>(&data[0]), data.size());
+    const char* ptr = NULL;
+    if (!data.empty()) {
+        ptr = reinterpret_cast<const char*>(&data[0]);
+    }
+    lua_pushlstring(L, ptr, data.size());
     return (1);
 }
 
index 448a6c467d81355959f4120239d7e45750ab1058..18c35155171c4b8b1ffddc533f460267cfff5ee0 100644 (file)
@@ -250,7 +250,11 @@ int getHWAddr(lua_State* L) {
     if (hwaddr) {
         bin = hwaddr->hwaddr_;
     }
-    lua_pushlstring(L, reinterpret_cast<char*>(&bin[0]), bin.size());
+    char* ptr = NULL;
+    if (!bin.empty()) {
+        ptr = reinterpret_cast<char*>(&bin[0]);
+    }
+    lua_pushlstring(L, ptr, bin.size());
     return (1);
 }
 
index 7fe21eace8491e5109977a3092aa26064cabb881..b42ad1a94bbccf3c9b709128bd159b756d87520b 100644 (file)
@@ -51,7 +51,11 @@ int load(LibraryHandle& handle) {
     }
     // Start ocaml
     char* argv[2];
-    argv[0] = &progname[0];
+    if (!progname.empty()) {
+        argv[0] = &progname[0];
+    } else {
+        argv[0] = NULL;
+    }
     argv[1] = NULL;
     caml_startup(argv);
     
index 01040c22633ef7f0c710e7a5ce8c5f7b1133ef8a..2776e28ecebb4c235ded61af020119a64fadf24b 100644 (file)
@@ -83,7 +83,9 @@ extern "C" CAMLprim value opt_factory(value u, value typ, value bytes) {
     uint16_t type = static_cast<uint16_t>(Int_val(typ));
     OptionBuffer data;
     data.resize(static_cast<size_t>(caml_string_length(bytes)));
-    memmove(&data[0], String_val(bytes), data.size());
+    if (!data.empty()) {
+        memmove(&data[0], String_val(bytes), data.size());
+    }
     result = caml_alloc_custom(opt_ops, sizeof(oc_opt), 0, 1);
     oc_opt* const self = static_cast<oc_opt*>(Data_custom_val(result));
     self->object.reset(new Option(universe, type, data));
@@ -123,7 +125,9 @@ extern "C" CAMLprim value opt_toBinary(value opt) {
     oc_opt* const self = static_cast<oc_opt*>(Data_custom_val(opt));
     vector<uint8_t> bin = self->object->toBinary(true);
     result = caml_alloc_string(static_cast<mlsize_t>(bin.size()));
-    memmove(String_val(result), &bin[0], bin.size());
+    if (!bin.empty()) {
+        memmove(String_val(result), &bin[0], bin.size());
+    }
     CAMLreturn (result);
 }
 
@@ -151,7 +155,9 @@ extern "C" CAMLprim value opt_getData(value opt) {
     oc_opt* const self = static_cast<oc_opt*>(Data_custom_val(opt));
     vector<uint8_t> data = self->object->getData();
     result = caml_alloc_string(static_cast<mlsize_t>(data.size()));
-    memmove(String_val(result), &data[0], data.size());
+    if (!data.empty()) {
+        memmove(String_val(result), &data[0], data.size());
+    }
     CAMLreturn (result);
 }
 
@@ -195,7 +201,9 @@ extern "C" CAMLprim value opt_setData(value opt, value bytes) {
     oc_opt* const self = static_cast<oc_opt*>(Data_custom_val(opt));
     vector<uint8_t> data;
     data.resize(static_cast<size_t>(caml_string_length(bytes)));
-    memmove(&data[0], String_val(bytes), data.size());
+    if (!data.empty()) {
+        memmove(&data[0], String_val(bytes), data.size());
+    }
     self->object->setData(data.begin(), data.end());
     CAMLreturn (Val_unit);
 }
index 5dc456c39fcb21bc22fcb91449f3b54287447cde..fbc7bd48e28e1590401c127c267497c63bd9253f 100644 (file)
@@ -106,8 +106,12 @@ toBinary(PyObject* obj, PyObject* args) {
 
     py_option* const self = static_cast<py_option*>(obj);
     vector<uint8_t> bin = self->object->toBinary(ih != 0);
-    return (PyBytes_FromStringAndSize(reinterpret_cast<char*>(&bin[0]),
-                                      static_cast<Py_ssize_t>(bin.size())));
+    char* ptr = NULL;
+    if (!bin.empty()) {
+        ptr = reinterpret_cast<char*>(&bin[0]);
+    }
+    Py_ssize_t sz = static_cast<Py_ssize_t>(bin.size());
+    return (PyBytes_FromStringAndSize(ptr, sz));
 }
 
 // getType() method
@@ -136,8 +140,12 @@ PyObject*
 getData(PyObject* obj) {
     py_option* const self = static_cast<py_option*>(obj);
     const OptionBuffer& data = self->object->getData();
-    return (PyBytes_FromStringAndSize(reinterpret_cast<const char*>(&data[0]),
-                                      static_cast<Py_ssize_t>(data.size())));
+    const char* ptr = NULL;
+    if (!data.empty()) {
+        ptr = reinterpret_cast<const char*>(&data[0]);
+    }
+    Py_ssize_t sz = static_cast<Py_ssize_t>(data.size());
+    return (PyBytes_FromStringAndSize(ptr, sz));
 }
 
 // addOption(OptionPtr opt) method
index 90b90a1f12eb9e16ad1e0cb32a5d0287e6fe691a..5ff290ac861428203430b9eecbd9ab42c48f2b35 100644 (file)
@@ -231,8 +231,12 @@ getHWAddr(PyObject* obj) {
     if (hwaddr) {
         bin = hwaddr->hwaddr_;
     }
-    return (PyBytes_FromStringAndSize(reinterpret_cast<char*>(&bin[0]),
-                                      static_cast<Py_ssize_t>(bin.size())));
+    char* ptr = NULL;
+    if (!bin.empty()) {
+        ptr = reinterpret_cast<char*>(&bin[0]);
+    }
+    Py_ssize_t sz = static_cast<Py_ssize_t>(bin.size());
+    return (PyBytes_FromStringAndSize(ptr, sz));
 }
 
 // Method table