perl plugin: Fixed a possible buffer overflow in get_module_name().
[collectd.git] / src / perl.c
index bcf7bb1..f2cb7b6 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include "collectd.h"
-#include "common.h"
 
 #include "configfile.h"
 
@@ -41,6 +40,7 @@
 
 /* ... while we want the definition found in plugin.h. */
 #include "plugin.h"
+#include "common.h"
 
 #define PLUGIN_INIT     0
 #define PLUGIN_READ     1
@@ -333,7 +333,7 @@ static char *get_module_name (char *buf, size_t buf_len, const char *module) {
                status = snprintf (buf, buf_len, "%s::%s", base_name, module);
        if ((status < 0) || (status >= buf_len))
                return (NULL);
-       buf[buf_len] = '\0';
+       buf[buf_len - 1] = '\0';
        return (buf);
 } /* char *get_module_name */