The following issues were found
collectors/python.d.plugin/python_modules/urllib3/util/connection.py
12 issues
Line: 4
Column: 1
# SPDX-License-Identifier: MIT
from __future__ import absolute_import
import socket
from .wait import wait_for_read
from .selectors import HAS_SELECT, SelectorError
def is_connection_dropped(conn): # Platform-specific
"""
Reported by Pylint.
Line: 5
Column: 1
from __future__ import absolute_import
import socket
from .wait import wait_for_read
from .selectors import HAS_SELECT, SelectorError
def is_connection_dropped(conn): # Platform-specific
"""
Returns True if the connection is dropped and should be closed.
Reported by Pylint.
Line: 37
Column: 40
# library test suite. Added to its signature is only `socket_options`.
# One additional modification is that we avoid binding to IPv6 servers
# discovered in DNS if the system doesn't have IPv6 functionality.
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None, socket_options=None):
"""Connect to *address* and return the socket object.
Convenience function. Connect to *address* (a 2-tuple ``(host,
port)``) and return the socket object. Passing the optional
Reported by Pylint.
Line: 62
Column: 30
family = allowed_gai_family()
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
sock = socket.socket(af, socktype, proto)
# If provided, set socket level options before connecting.
Reported by Pylint.
Line: 70
Column: 31
# If provided, set socket level options before connecting.
_set_socket_options(sock, socket_options)
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
sock.settimeout(timeout)
if source_address:
sock.bind(source_address)
sock.connect(sa)
return sock
Reported by Pylint.
Line: 123
Column: 16
sock = socket.socket(socket.AF_INET6)
sock.bind((host, 0))
has_ipv6 = True
except Exception:
pass
if sock:
sock.close()
return has_ipv6
Reported by Pylint.
Line: 1
Column: 1
# SPDX-License-Identifier: MIT
from __future__ import absolute_import
import socket
from .wait import wait_for_read
from .selectors import HAS_SELECT, SelectorError
def is_connection_dropped(conn): # Platform-specific
"""
Reported by Pylint.
Line: 37
Column: 1
# library test suite. Added to its signature is only `socket_options`.
# One additional modification is that we avoid binding to IPv6 servers
# discovered in DNS if the system doesn't have IPv6 functionality.
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None, socket_options=None):
"""Connect to *address* and return the socket object.
Convenience function. Connect to *address* (a 2-tuple ``(host,
port)``) and return the socket object. Passing the optional
Reported by Pylint.
Line: 62
Column: 9
family = allowed_gai_family()
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
sock = socket.socket(af, socktype, proto)
# If provided, set socket level options before connecting.
Reported by Pylint.
Line: 62
Column: 41
family = allowed_gai_family()
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
sock = socket.socket(af, socktype, proto)
# If provided, set socket level options before connecting.
Reported by Pylint.
database/rrdset.c
12 issues
Line: 704
Column: 9
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
char config_section[RRD_ID_LENGTH_MAX + 1];
if(host == localhost)
strcpy(config_section, fullid);
else
snprintfz(config_section, RRD_ID_LENGTH_MAX, "%s/%s", host->machine_guid, fullid);
// ------------------------------------------------------------------------
// get the options from the config, we need to create it
Reported by FlawFinder.
Line: 835
Column: 5
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
if(st->current_entry >= st->entries) st->current_entry = 0;
strcpy(st->cache_filename, fullfilename);
strcpy(st->magic, RRDSET_MAGIC);
strcpy(st->id, fullid);
st->hash = simple_hash(st->id);
Reported by FlawFinder.
Line: 836
Column: 5
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
if(st->current_entry >= st->entries) st->current_entry = 0;
strcpy(st->cache_filename, fullfilename);
strcpy(st->magic, RRDSET_MAGIC);
strcpy(st->id, fullid);
st->hash = simple_hash(st->id);
st->cache_dir = cache_dir;
Reported by FlawFinder.
Line: 838
Column: 5
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
strcpy(st->cache_filename, fullfilename);
strcpy(st->magic, RRDSET_MAGIC);
strcpy(st->id, fullid);
st->hash = simple_hash(st->id);
st->cache_dir = cache_dir;
st->chart_type = rrdset_type_id(config_get(st->config_section, "chart type", rrdset_type_name(chart_type)));
Reported by FlawFinder.
Line: 106
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
inline RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id) {
debug(D_RRD_CALLS, "rrdset_find_bytype() for chart '%s.%s' in host '%s'", type, id, host->hostname);
char buf[RRD_ID_LENGTH_MAX + 1];
strncpyz(buf, type, RRD_ID_LENGTH_MAX - 1);
strcat(buf, ".");
int len = (int) strlen(buf);
strncpyz(&buf[len], id, (size_t) (RRD_ID_LENGTH_MAX - len));
Reported by FlawFinder.
Line: 147
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
debug(D_RRD_CALLS, "rrdset_set_name() old: '%s', new: '%s'", st->name?st->name:"", name);
char b[CONFIG_MAX_VALUE + 1];
char n[RRD_ID_LENGTH_MAX + 1];
snprintfz(n, RRD_ID_LENGTH_MAX, "%s.%s", st->type, name);
rrdset_strncpyz_name(b, n, CONFIG_MAX_VALUE);
Reported by FlawFinder.
Line: 148
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
debug(D_RRD_CALLS, "rrdset_set_name() old: '%s', new: '%s'", st->name?st->name:"", name);
char b[CONFIG_MAX_VALUE + 1];
char n[RRD_ID_LENGTH_MAX + 1];
snprintfz(n, RRD_ID_LENGTH_MAX, "%s.%s", st->type, name);
rrdset_strncpyz_name(b, n, CONFIG_MAX_VALUE);
if(rrdset_index_find_name(host, b, 0)) {
Reported by FlawFinder.
Line: 545
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
// ------------------------------------------------------------------------
// check if it already exists
char fullid[RRD_ID_LENGTH_MAX + 1];
snprintfz(fullid, RRD_ID_LENGTH_MAX, "%s.%s", type, id);
int changed_from_archived_to_active = 0;
RRDSET *st = rrdset_find_on_create(host, fullid);
if (st) {
Reported by FlawFinder.
Line: 697
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
return st;
}
char fullfilename[FILENAME_MAX + 1];
// ------------------------------------------------------------------------
// compose the config_section for this chart
char config_section[RRD_ID_LENGTH_MAX + 1];
Reported by FlawFinder.
Line: 702
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
// ------------------------------------------------------------------------
// compose the config_section for this chart
char config_section[RRD_ID_LENGTH_MAX + 1];
if(host == localhost)
strcpy(config_section, fullid);
else
snprintfz(config_section, RRD_ID_LENGTH_MAX, "%s/%s", host->machine_guid, fullid);
Reported by FlawFinder.
collectors/python.d.plugin/python_modules/third_party/ordereddict.py
12 issues
Line: 5
Column: 1
#
# SPDX-License-Identifier: MIT
from UserDict import DictMixin
class OrderedDict(dict, DictMixin):
def __init__(self, *args, **kwds):
Reported by Pylint.
Line: 56
Column: 19
if not self:
raise KeyError('dictionary is empty')
if last:
key = reversed(self).next()
else:
key = iter(self).next()
value = self.pop(key)
return key, value
Reported by Pylint.
Line: 10
Column: 5
class OrderedDict(dict, DictMixin):
def __init__(self, *args, **kwds):
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
try:
self.__end
except AttributeError:
Reported by Pylint.
Line: 34
Column: 20
def __delitem__(self, key):
dict.__delitem__(self, key)
key, prev, next = self.__map.pop(key)
prev[2] = next
next[1] = prev
def __iter__(self):
end = self.__end
Reported by Pylint.
Line: 67
Column: 21
tmp = self.__map, self.__end
del self.__map, self.__end
inst_dict = vars(self).copy()
self.__map, self.__end = tmp
if inst_dict:
return self.__class__, (items,), inst_dict
return self.__class__, (items,)
def keys(self):
Reported by Pylint.
Line: 67
Column: 9
tmp = self.__map, self.__end
del self.__map, self.__end
inst_dict = vars(self).copy()
self.__map, self.__end = tmp
if inst_dict:
return self.__class__, (items,), inst_dict
return self.__class__, (items,)
def keys(self):
Reported by Pylint.
Line: 1
Column: 1
# Copyright (c) 2009 Raymond Hettinger
#
# SPDX-License-Identifier: MIT
from UserDict import DictMixin
class OrderedDict(dict, DictMixin):
Reported by Pylint.
Line: 8
Column: 1
from UserDict import DictMixin
class OrderedDict(dict, DictMixin):
def __init__(self, *args, **kwds):
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
try:
Reported by Pylint.
Line: 93
Column: 5
return self.__class__(self)
@classmethod
def fromkeys(cls, iterable, value=None):
d = cls()
for key in iterable:
d[key] = value
return d
Reported by Pylint.
Line: 94
Column: 9
@classmethod
def fromkeys(cls, iterable, value=None):
d = cls()
for key in iterable:
d[key] = value
return d
def __eq__(self, other):
Reported by Pylint.
tests/profile/benchmark-registry.c
12 issues
Line: 100
Column: 17
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
fprintf(stderr, "\n%u random users accessing a random server, out of the %u servers\n", users, machines);
now = time(NULL);
for(u = 0; u < users ; u++) {
uint32_t tu = random() * users / RAND_MAX;
uint32_t tm = random() * machines / RAND_MAX;
PERSON *p = registry_request_access(users_guids[tu], machines_guids[tm], machines_urls[tm], "test", now);
if(p->guid != users_guids[tu])
Reported by FlawFinder.
Line: 101
Column: 17
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
now = time(NULL);
for(u = 0; u < users ; u++) {
uint32_t tu = random() * users / RAND_MAX;
uint32_t tm = random() * machines / RAND_MAX;
PERSON *p = registry_request_access(users_guids[tu], machines_guids[tm], machines_urls[tm], "test", now);
if(p->guid != users_guids[tu])
fprintf(stderr, "ERROR: expected to get user guid '%s' but git '%s'", users_guids[tu], p->guid);
Reported by FlawFinder.
Line: 114
Column: 17
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
fprintf(stderr, "\n%u random users accessing a random server, out of %u servers\n", users, machines2);
now = time(NULL);
for(u = 0; u < users ; u++) {
uint32_t tu = random() * users / RAND_MAX;
uint32_t tm = random() * machines2 / RAND_MAX;
PERSON *p = registry_request_access(users_guids[tu], machines_guids[tm], machines_urls[tm], "test", now);
if(p->guid != users_guids[tu])
Reported by FlawFinder.
Line: 115
Column: 17
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
now = time(NULL);
for(u = 0; u < users ; u++) {
uint32_t tu = random() * users / RAND_MAX;
uint32_t tm = random() * machines2 / RAND_MAX;
PERSON *p = registry_request_access(users_guids[tu], machines_guids[tm], machines_urls[tm], "test", now);
if(p->guid != users_guids[tu])
fprintf(stderr, "ERROR: expected to get user guid '%s' but git '%s'", users_guids[tu], p->guid);
Reported by FlawFinder.
Line: 131
Column: 18
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
users * 2, machines2);
now = time(NULL);
for (u = 0; u < users * 2; u++) {
uint32_t tu = random() * users / RAND_MAX;
uint32_t tm = random() * machines2 / RAND_MAX;
char *url = machines_urls[tm];
char buf[FILENAME_MAX + 1];
if (random() % 10000 == 1234) {
Reported by FlawFinder.
Line: 132
Column: 18
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
now = time(NULL);
for (u = 0; u < users * 2; u++) {
uint32_t tu = random() * users / RAND_MAX;
uint32_t tm = random() * machines2 / RAND_MAX;
char *url = machines_urls[tm];
char buf[FILENAME_MAX + 1];
if (random() % 10000 == 1234) {
snprintfz(buf, FILENAME_MAX, "http://random.%ld.netdata.rocks/", random());
Reported by FlawFinder.
Line: 136
Column: 8
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
char *url = machines_urls[tm];
char buf[FILENAME_MAX + 1];
if (random() % 10000 == 1234) {
snprintfz(buf, FILENAME_MAX, "http://random.%ld.netdata.rocks/", random());
url = buf;
}
else if (random() % 1000 == 123)
url = machines_urls[random() * machines2 / RAND_MAX];
Reported by FlawFinder.
Line: 137
Column: 70
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
char *url = machines_urls[tm];
char buf[FILENAME_MAX + 1];
if (random() % 10000 == 1234) {
snprintfz(buf, FILENAME_MAX, "http://random.%ld.netdata.rocks/", random());
url = buf;
}
else if (random() % 1000 == 123)
url = machines_urls[random() * machines2 / RAND_MAX];
Reported by FlawFinder.
Line: 140
Column: 13
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
snprintfz(buf, FILENAME_MAX, "http://random.%ld.netdata.rocks/", random());
url = buf;
}
else if (random() % 1000 == 123)
url = machines_urls[random() * machines2 / RAND_MAX];
PERSON *p = registry_request_access(users_guids[tu], machines_guids[tm], url, "test", now);
if (p->guid != users_guids[tu])
Reported by FlawFinder.
Line: 141
Column: 25
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
url = buf;
}
else if (random() % 1000 == 123)
url = machines_urls[random() * machines2 / RAND_MAX];
PERSON *p = registry_request_access(users_guids[tu], machines_guids[tm], url, "test", now);
if (p->guid != users_guids[tu])
fprintf(stderr, "ERROR: expected to get user guid '%s' but git '%s'", users_guids[tu], p->guid);
Reported by FlawFinder.
collectors/python.d.plugin/openldap/openldap.chart.py
12 issues
Line: 13
Column: 1
except ImportError:
HAS_LDAP = False
from bases.FrameworkServices.SimpleService import SimpleService
DEFAULT_SERVER = 'localhost'
DEFAULT_PORT = '389'
DEFAULT_TLS = False
DEFAULT_CERT_CHECK = True
Reported by Pylint.
Line: 1
Column: 1
# -*- coding: utf-8 -*-
# Description: openldap netdata python.d module
# Author: Manolis Kartsonakis (ekartsonakis)
# SPDX-License-Identifier: GPL-3.0+
try:
import ldap
HAS_LDAP = True
Reported by Pylint.
Line: 34
Column: 1
CHARTS = {
'total_connections': {
'options': [None, 'Total Connections', 'connections/s', 'ldap', 'openldap.total_connections', 'line'],
'lines': [
['total_connections', 'connections', 'incremental']
]
},
'bytes_sent': {
Reported by Pylint.
Line: 46
Column: 1
]
},
'operations': {
'options': [None, 'Operations Status', 'ops/s', 'ldap', 'openldap.operations_status', 'line'],
'lines': [
['completed_operations', 'completed', 'incremental'],
['initiated_operations', 'initiated', 'incremental']
]
},
Reported by Pylint.
Line: 135
Column: 1
}
class Service(SimpleService):
def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.server = configuration.get('server', DEFAULT_SERVER)
Reported by Pylint.
Line: 135
Column: 1
}
class Service(SimpleService):
def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.server = configuration.get('server', DEFAULT_SERVER)
Reported by Pylint.
Line: 151
Column: 5
self.alive = False
self.conn = None
def disconnect(self):
if self.conn:
self.conn.unbind()
self.conn = None
self.alive = False
Reported by Pylint.
Line: 157
Column: 5
self.conn = None
self.alive = False
def connect(self):
try:
if self.use_tls:
self.conn = ldap.initialize('ldaps://%s:%s' % (self.server, self.port))
else:
self.conn = ldap.initialize('ldap://%s:%s' % (self.server, self.port))
Reported by Pylint.
Line: 180
Column: 5
self.alive = True
return True
def reconnect(self):
self.disconnect()
return self.connect()
def check(self):
if not HAS_LDAP:
Reported by Pylint.
Line: 184
Column: 5
self.disconnect()
return self.connect()
def check(self):
if not HAS_LDAP:
self.error("'python-ldap' package is needed")
return None
return self.connect() and self.get_data()
Reported by Pylint.
collectors/python.d.plugin/spigotmc/spigotmc.chart.py
12 issues
Line: 10
Column: 1
import re
import socket
from bases.FrameworkServices.SimpleService import SimpleService
from third_party import mcrcon
# Update only every 5 seconds because collection takes in excess of
# 100ms sometimes, and most people won't care about second-by-second data.
update_every = 5
Reported by Pylint.
Line: 11
Column: 1
import socket
from bases.FrameworkServices.SimpleService import SimpleService
from third_party import mcrcon
# Update only every 5 seconds because collection takes in excess of
# 100ms sometimes, and most people won't care about second-by-second data.
update_every = 5
Reported by Pylint.
Line: 1
Column: 1
# -*- coding: utf-8 -*-
# Description: spigotmc netdata python.d module
# Author: Austin S. Hemmelgarn (Ferroin)
# SPDX-License-Identifier: GPL-3.0-or-later
import platform
import re
import socket
Reported by Pylint.
Line: 15
Column: 1
# Update only every 5 seconds because collection takes in excess of
# 100ms sometimes, and most people won't care about second-by-second data.
update_every = 5
PRECISION = 100
COMMAND_TPS = 'tps'
COMMAND_LIST = 'list'
Reported by Pylint.
Line: 64
Column: 1
)
class Service(SimpleService):
def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.host = self.configuration.get('host', 'localhost')
Reported by Pylint.
Line: 75
Column: 5
self.console = mcrcon.MCRcon()
self.alive = True
def check(self):
if platform.system() != 'Linux':
self.error('Only supported on Linux.')
return False
try:
self.connect()
Reported by Pylint.
Line: 88
Column: 5
return self._get_data()
def connect(self):
self.console.connect(self.host, self.port, self.password)
def reconnect(self):
self.error('try reconnect.')
try:
Reported by Pylint.
Line: 91
Column: 5
def connect(self):
self.console.connect(self.host, self.port, self.password)
def reconnect(self):
self.error('try reconnect.')
try:
try:
self.console.disconnect()
except mcrcon.MCRconException:
Reported by Pylint.
Line: 106
Column: 5
return False
return True
def is_alive(self):
if any(
[
not self.alive,
self.console.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_INFO, 0) != 1
]
Reported by Pylint.
Line: 116
Column: 5
return self.reconnect()
return True
def _get_data(self):
if not self.is_alive():
return None
data = {}
Reported by Pylint.
web/api/formatters/json/json.c
12 issues
Line: 19
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
//info("RRD2JSON(): %s: BEGIN", r->st->id);
int row_annotations = 0, dates, dates_with_new = 0;
char kq[2] = "", // key quote
sq[2] = "", // string quote
pre_label[101] = "", // before each label
post_label[101] = "", // after each label
pre_date[101] = "", // the beginning of line, to the date
post_date[101] = "", // closing the date
Reported by FlawFinder.
Line: 50
Column: 9
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
snprintfz(post_label, 100, "%s,%spattern%s:%s%s,%stype%s:%snumber%s}", sq, kq, kq, sq, sq, kq, kq, sq, sq);
snprintfz(pre_value, 100, ",{%sv%s:", kq, kq);
strcpy(post_value, "}");
strcpy(post_line, "]}");
snprintfz(data_begin, 100, "\n ],\n %srows%s:\n [\n", kq, kq);
strcpy(finish, "\n ]\n}");
snprintfz(overflow_annotation, 200, ",{%sv%s:%sRESET OR OVERFLOW%s},{%sv%s:%sThe counters have been wrapped.%s}", kq, kq, sq, sq, kq, kq, sq, sq);
snprintfz(normal_annotation, 200, ",{%sv%s:null},{%sv%s:null}", kq, kq, kq, kq);
Reported by FlawFinder.
Line: 52
Column: 9
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
strcpy(post_value, "}");
strcpy(post_line, "]}");
snprintfz(data_begin, 100, "\n ],\n %srows%s:\n [\n", kq, kq);
strcpy(finish, "\n ]\n}");
snprintfz(overflow_annotation, 200, ",{%sv%s:%sRESET OR OVERFLOW%s},{%sv%s:%sThe counters have been wrapped.%s}", kq, kq, sq, sq, kq, kq, sq, sq);
snprintfz(normal_annotation, 200, ",{%sv%s:null},{%sv%s:null}", kq, kq, kq, kq);
buffer_sprintf(wb, "{\n %scols%s:\n [\n", kq, kq);
Reported by FlawFinder.
Line: 79
Column: 13
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
dates_with_new = 0;
}
if( options & RRDR_OPTION_OBJECTSROWS )
strcpy(pre_date, " { ");
else
strcpy(pre_date, " [ ");
strcpy(pre_label, ", \"");
strcpy(post_label, "\"");
strcpy(pre_value, ", ");
Reported by FlawFinder.
Line: 81
Column: 13
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
if( options & RRDR_OPTION_OBJECTSROWS )
strcpy(pre_date, " { ");
else
strcpy(pre_date, " [ ");
strcpy(pre_label, ", \"");
strcpy(post_label, "\"");
strcpy(pre_value, ", ");
if( options & RRDR_OPTION_OBJECTSROWS )
strcpy(post_line, "}");
Reported by FlawFinder.
Line: 82
Column: 9
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
strcpy(pre_date, " { ");
else
strcpy(pre_date, " [ ");
strcpy(pre_label, ", \"");
strcpy(post_label, "\"");
strcpy(pre_value, ", ");
if( options & RRDR_OPTION_OBJECTSROWS )
strcpy(post_line, "}");
else
Reported by FlawFinder.
Line: 84
Column: 9
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
strcpy(pre_date, " [ ");
strcpy(pre_label, ", \"");
strcpy(post_label, "\"");
strcpy(pre_value, ", ");
if( options & RRDR_OPTION_OBJECTSROWS )
strcpy(post_line, "}");
else
strcpy(post_line, "]");
snprintfz(data_begin, 100, "],\n %sdata%s:\n [\n", kq, kq);
Reported by FlawFinder.
Line: 90
Column: 9
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
else
strcpy(post_line, "]");
snprintfz(data_begin, 100, "],\n %sdata%s:\n [\n", kq, kq);
strcpy(finish, "\n ]\n}");
buffer_sprintf(wb, "{\n %slabels%s: [", kq, kq);
buffer_sprintf(wb, "%stime%s", sq, sq);
}
Reported by FlawFinder.
Line: 49
Column: 9
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
snprintfz(pre_label, 100, ",\n {%sid%s:%s%s,%slabel%s:%s", kq, kq, sq, sq, kq, kq, sq);
snprintfz(post_label, 100, "%s,%spattern%s:%s%s,%stype%s:%snumber%s}", sq, kq, kq, sq, sq, kq, kq, sq, sq);
snprintfz(pre_value, 100, ",{%sv%s:", kq, kq);
strcpy(post_value, "}");
strcpy(post_line, "]}");
snprintfz(data_begin, 100, "\n ],\n %srows%s:\n [\n", kq, kq);
strcpy(finish, "\n ]\n}");
snprintfz(overflow_annotation, 200, ",{%sv%s:%sRESET OR OVERFLOW%s},{%sv%s:%sThe counters have been wrapped.%s}", kq, kq, sq, sq, kq, kq, sq, sq);
Reported by FlawFinder.
Line: 83
Column: 9
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
else
strcpy(pre_date, " [ ");
strcpy(pre_label, ", \"");
strcpy(post_label, "\"");
strcpy(pre_value, ", ");
if( options & RRDR_OPTION_OBJECTSROWS )
strcpy(post_line, "}");
else
strcpy(post_line, "]");
Reported by FlawFinder.
collectors/python.d.plugin/fail2ban/fail2ban.chart.py
11 issues
Line: 11
Column: 1
from collections import defaultdict
from glob import glob
from bases.FrameworkServices.LogService import LogService
ORDER = [
'jails_bans',
'jails_in_jail',
]
Reported by Pylint.
Line: 1
Column: 1
# -*- coding: utf-8 -*-
# Description: fail2ban log netdata python.d module
# Author: ilyam8
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import re
from collections import defaultdict
from glob import glob
Reported by Pylint.
Line: 24
Column: 5
Chart definitions creating
"""
ch = {
ORDER[0]: {
'options': [None, 'Jails Ban Rate', 'bans/s', 'bans', 'jail.bans', 'line'],
'lines': []
},
ORDER[1]: {
Reported by Pylint.
Line: 59
Column: 1
# 2018-09-12 11:45:53,715 fail2ban.actions[25029]: WARNING [ssh] Unban 195.201.88.33
# 2018-09-12 11:45:58,727 fail2ban.actions[25029]: WARNING [ssh] Ban 217.59.246.27
# 2018-09-12 11:45:58,727 fail2ban.actions[25029]: WARNING [ssh] Restore Ban 217.59.246.27
RE_DATA = re.compile(r'\[(?P<jail>[A-Za-z-_0-9]+)\] (?P<action>Unban|Ban|Restore Ban) (?P<ip>[a-f0-9.:]+)')
DEFAULT_JAILS = [
'ssh',
]
Reported by Pylint.
Line: 66
Column: 1
]
class Service(LogService):
def __init__(self, configuration=None, name=None):
LogService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = dict()
self.log_path = self.configuration.get('log_path', '/var/log/fail2ban.log')
Reported by Pylint.
Line: 66
Column: 1
]
class Service(LogService):
def __init__(self, configuration=None, name=None):
LogService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = dict()
self.log_path = self.configuration.get('log_path', '/var/log/fail2ban.log')
Reported by Pylint.
Line: 84
Column: 1
:return: bool
"""
if not self.conf_path.endswith(('.conf', '.local')):
self.error('{0} is a wrong conf path name, must be *.conf or *.local'.format(self.conf_path))
return False
if not os.access(self.log_path, os.R_OK):
self.error('{0} is not readable'.format(self.log_path))
return False
Reported by Pylint.
Line: 125
Column: 27
if match['jail'] not in self.monitoring_jails:
continue
jail, action, ip = match['jail'], match['action'], match['ip']
if action == 'Ban' or action == 'Restore Ban':
self.data[jail] += 1
if ip not in self.banned_ips[jail]:
self.banned_ips[jail].add(ip)
Reported by Pylint.
Line: 127
Column: 16
jail, action, ip = match['jail'], match['action'], match['ip']
if action == 'Ban' or action == 'Restore Ban':
self.data[jail] += 1
if ip not in self.banned_ips[jail]:
self.banned_ips[jail].add(ip)
self.data['{0}_in_jail'.format(jail)] += 1
else:
Reported by Pylint.
Line: 157
Column: 39
self.error('{0} is not readable or not exist'.format(file_path))
return list()
with open(file_path, 'rt') as f:
lines = f.readlines()
raw = ' '.join(line for line in lines if line.startswith(('[', 'enabled')))
match = RE_JAILS.findall(raw)
# Result: [('ssh', 'true'), ('dropbear', 'true'), ('pam-generic', 'true'), ...]
Reported by Pylint.
collectors/python.d.plugin/samba/samba.chart.py
11 issues
Line: 22
Column: 1
import re
import os
from bases.FrameworkServices.ExecutableService import ExecutableService
from bases.collection import find_binary
disabled_by_default = True
update_every = 5
Reported by Pylint.
Line: 23
Column: 1
import os
from bases.FrameworkServices.ExecutableService import ExecutableService
from bases.collection import find_binary
disabled_by_default = True
update_every = 5
Reported by Pylint.
Line: 117
Column: 13
return False
if os.getuid() == 0:
self.command = ' '.join([smbstatus_binary, '-P'])
return ExecutableService.check(self)
sudo_binary = find_binary(SUDO)
if not sudo_binary:
self.error("can't locate '{0}' binary".format(SUDO))
Reported by Pylint.
Line: 130
Column: 9
if not (allowed and allowed[0].strip() == smbstatus):
self.error("not allowed to run sudo for command '{0}'".format(smbstatus))
return False
self.command = ' '.join([sudo_binary, '-n', smbstatus_binary, '-P'])
return ExecutableService.check(self)
def _get_data(self):
"""
Format data received from shell command
Reported by Pylint.
Line: 1
Column: 1
# -*- coding: utf-8 -*-
# Description: samba netdata python.d module
# Author: Christopher Cox <chris_cox@endlessnow.com>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# The netdata user needs to be able to be able to sudo the smbstatus program
# without password:
# netdata ALL=(ALL) NOPASSWD: /usr/bin/smbstatus -P
#
Reported by Pylint.
Line: 25
Column: 1
from bases.FrameworkServices.ExecutableService import ExecutableService
from bases.collection import find_binary
disabled_by_default = True
update_every = 5
ORDER = [
'syscall_rw',
Reported by Pylint.
Line: 27
Column: 1
disabled_by_default = True
update_every = 5
ORDER = [
'syscall_rw',
'smb2_rw',
'smb2_create_close',
Reported by Pylint.
Line: 103
Column: 1
SMBSTATUS = 'smbstatus'
class Service(ExecutableService):
def __init__(self, configuration=None, name=None):
ExecutableService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.rgx_smb2 = re.compile(r'(smb2_[^:]+|syscall_.*file_bytes):\s+(\d+)')
Reported by Pylint.
Line: 103
Column: 1
SMBSTATUS = 'smbstatus'
class Service(ExecutableService):
def __init__(self, configuration=None, name=None):
ExecutableService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.rgx_smb2 = re.compile(r'(smb2_[^:]+|syscall_.*file_bytes):\s+(\d+)')
Reported by Pylint.
Line: 110
Column: 5
self.definitions = CHARTS
self.rgx_smb2 = re.compile(r'(smb2_[^:]+|syscall_.*file_bytes):\s+(\d+)')
def check(self):
smbstatus_binary = find_binary(SMBSTATUS)
if not smbstatus_binary:
self.error("can't locate '{0}' binary".format(SMBSTATUS))
return False
Reported by Pylint.
collectors/python.d.plugin/tor/tor.chart.py
11 issues
Line: 8
Column: 1
# SPDX-License-Identifier: GPL-3.0-or-later
from bases.FrameworkServices.SimpleService import SimpleService
try:
import stem
import stem.connection
import stem.control
Reported by Pylint.
Line: 1
Column: 1
# -*- coding: utf-8 -*-
# Description: adaptec_raid netdata python.d module
# Author: Federico Ceratto <federico.ceratto@gmail.com>
# Author: Ilya Mashchenko (ilyam8)
# SPDX-License-Identifier: GPL-3.0-or-later
from bases.FrameworkServices.SimpleService import SimpleService
Reported by Pylint.
Line: 40
Column: 9
"""Provide netdata service for Tor"""
def __init__(self, configuration=None, name=None):
super(Service, self).__init__(configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.port = self.configuration.get('control_port', DEF_PORT)
self.password = self.configuration.get('password')
self.use_socket = isinstance(self.port, str) and self.port != DEF_PORT and not self.port.isdigit()
Reported by Pylint.
Line: 45
Column: 1
self.definitions = CHARTS
self.port = self.configuration.get('control_port', DEF_PORT)
self.password = self.configuration.get('password')
self.use_socket = isinstance(self.port, str) and self.port != DEF_PORT and not self.port.isdigit()
self.conn = None
self.alive = False
def check(self):
if not STEM_AVAILABLE:
Reported by Pylint.
Line: 49
Column: 5
self.conn = None
self.alive = False
def check(self):
if not STEM_AVAILABLE:
self.error('the stem library is missing')
return False
return self.connect()
Reported by Pylint.
Line: 56
Column: 5
return self.connect()
def get_data(self):
if not self.alive and not self.reconnect():
return None
data = dict()
Reported by Pylint.
Line: 71
Column: 5
return data or None
def authenticate(self):
try:
self.conn.authenticate(password=self.password)
except stem.connection.AuthenticationFailure as error:
self.error('authentication error: {0}'.format(error))
return False
Reported by Pylint.
Line: 79
Column: 5
return False
return True
def connect_via_port(self):
try:
self.conn = stem.control.Controller.from_port(port=self.port)
except (stem.SocketError, ValueError) as error:
self.error(error)
Reported by Pylint.
Line: 85
Column: 5
except (stem.SocketError, ValueError) as error:
self.error(error)
def connect_via_socket(self):
try:
self.conn = stem.control.Controller.from_socket_file(path=self.port)
except (stem.SocketError, ValueError) as error:
self.error(error)
Reported by Pylint.
Line: 91
Column: 5
except (stem.SocketError, ValueError) as error:
self.error(error)
def connect(self):
if self.conn:
self.conn.close()
self.conn = None
if self.use_socket:
Reported by Pylint.