The `di_method` object accesses fields of the `s` server in its dtor.
Therefore delete that one first, and `s` second.
Change-Id: Ib5f86753c7801b0b67d92e4c0f97464c2aecdaed
Rework the `nbWrite()` function so, that it gets safe
in terms of:
- operating on data written/data remaining integers
- has protection guards for extra big chunks to write at once
Refactor to use size_t/ssize_t instead of primitive int,
where possible (e.g. bytesWritten).
Let the `nbWrite()` use reference instead of pointer
for the bytes written parameter.
Fixes Coverity Scan report:
4. tainted_data_return: Called function write(fd, sp, nToWrite),
and a possible return value may be less than zero.
5. cast_overflow: An assign that casts to a different type,
which might trigger an overflow.
Overflowed integer argument (INTEGER_OVERFLOW)
13. overflow_sink: nToWrite, which might have overflowed,
is passed to write(fd, sp, nToWrite).
7. overflow: The expression nToWrite is considered
to have possibly overflowed.
Change-Id: I32aa6aae5ef5715d61a91714e62b0a094bc03f21
As long as the `TypeInt` is actually a long primitive,
and we tend to switch using the long type everywhere
within xml implementation, then
there is no need to support both `int` and `long`
types, just force users to be on `long` always.
Refactor the user code accordingly.
Change-Id: I5c5b032a824a84f69f99dc7c755d0da745a9a068
As this is only a syntactic sugar there is no difference,
but from the style perspective the project tends to
use C++ style.
Change-Id: I3636c48163b3d262b272b5088e03c074e49a9ec3
Properly select the equal operator based on long instead.
Otherwise it selects the `ValueStruct` as the latest
possible from the variant based `_value` and eventually
it gets stumbled over `[]` operator for
building structs which asserts it.
Change-Id: Ib9a4fe9c66ff02554a84451df8aa940fe766fedc
Don't try to double free the `_ssl_ssl` and `_ssl_ctx`
provided by `XmlRpcSource`, because this job
is already done by `XmlRpcSource::close()`.
Additionally:
- add a separate non-null check for the _ssl_ctx freeing
- move log lines from `XmlRpcClient::close()` to `XmlRpcSource::close()`
Change-Id: Ifef799fa6a0ffa65b60415f39c51f4b54ff4bb14
Additional logic around these two objects to free it during the
destruction phase.
Also add NULLing for the according pointers in other places
which might also free it before the destructor takes place,
which would lead otherwise to a double free attempt.
Change-Id: I046a660e4b1467a7093dbf2c0c3170a950d5f607
Don't appeal to the XmlRpcSource's members (e.g. `_ssl`)
if this has been freed via `this`.
To check this out see controllable delete behavior
via introduced getter `getsDeletedOnClose()`.
Should fix:
freed_arg: close frees this.
CID 542402: (#1 of 1): Read from pointer after free (USE_AFTER_FREE)
use_after_free: Using freed pointer this.
Change-Id: I8f23564957c57491db8cf051e7296671bf2a698a
Let STL handle memory management and type safety.
In the future this can be refactored further to eliminate the "Type"
enum and value, as the variant itself keeps this information.
Fix white spacing.
Change-Id: I6e903b51de339b686ba89bb7ae81f4d86eb66bc0
Store integers as long to reduce likelihood of overflows. Retain
overloaded accessors for compatibility.
Use time_t and suseconds_t for timestamps.
Fix up formatting strings to match the new types and to also fix
incorrect formatting of decimal values.
Remove unused methods.
Change-Id: I58bfcd8a34bef2363eac06242dfedf6aae8451e0
Directly contain the ValueArray in the variant instead of manually
managing a pointer. Requires updating the return type of some const
functions to also be const, which in turn requires some of their users
to have the type const qualified as well.
Change-Id: I2ec31d659eef521a3f68d642ee431b5c38f27fdf
Move from debian/rules into actual makefile. This is not Debian-specific
and needs to be set for a successful build.
Also it's not a preprocessor option, it's a C++ option.
Change-Id: I19be56f4e319778def5697b1fdbc77a9988ccb9b
Add missing initialisers and fix order.
In some cases the member was actually unused and could just be removed.
Change-Id: I0f0c927eb8271c35dcfd371f225847f62bea2812
Warned-by: Coverity
Use a static cast to make sure we use the right type for
std::string::length()
Change-Id: I3b21146ca8898d7e1f3b35c83389d37eadac5ff6
Warned-by: Coverity
Make it more explicit that this is meant to set the flag instead of
doing a comparison with a typo.
Change-Id: I31a1a7f35b9072f157105f6c2acdd2caf9bea09a
Warned-by: Coverity
Classes that inherit from both AmThread and AmEventHandler must inherit
from AmEventQueue first and from AmThread after. This is needed so that
the AmThread dtor is called first, which will trigger the thread to shut
down, which in turn makes sure nothing is waiting on the AmEventQueue's
condition variable.
Otherwise, if AmEventQueue is destroyed first while the corresponding
thread is still running and waiting on the condition variable, it will
be a deadlock.
With this, sems finally can shut down cleanly without having to be
killed by systemd.
Change-Id: I914455763b517c96561acb0b64fce26f127f44bc
Use overloading for the various flavours of str2int functions. This has
the benefit of automatically choosing the appropriate function for
aliased types that may be one or the other underlying type, such as
size_t.
Do a mass renaming of all relevant instances.
Change-Id: I7abb6b9031ee53332d2b04a6cba4a6cc667a4807
When handling `XMLRPC2DIServer` allocation,
first make sure to have the `XmlRpcServer`
and then do rest of processing (e.g.: `di_export`,
`di_method`, `registerMethods()` etc.)
Otherwise can lead to seg.faults when appealing
to objects via still non-allocated `XmlRpcServer`
object.
Change-Id: Id3395ce3e0d6f2de76ed8caa1a786a6e139a851b
For the `XMLRPC2DIServer` class as well as for the
`XMLRPC2DI` one, heap allocated objects aren't properly
managed by destruction time.
Pointers have to be initialized as NULL, and point
only when allocation was successfull.
Then by a destruction time, check them and free.
Change-Id: I1a31813db254cc4ab0f7ecc7b382fcb3635feee0
There is only one instance of XMLRPC2DI API,
hence only one possible value for a list of
class members, such as:
- XML RPC port for DI
- XML RPC DI server
- variable, which defines, if that's configured
Additionally fixes:
Uninitialized pointer field (UNINIT_CTOR)
uninit_member: Non-static class member XMLRPCPort
is not initialized in this constructor nor in any functions that it calls.
Change-Id: I0120652220129774137e90d1ad8dfa579cca3202
It has no sense to keep it as `unsigned int`, because
it's used in comparisons with other `time_t` type
variables.
Although it's only used for now in `is_active()`.
Change-Id: Iceda2338d88ba7de38d084001bbfce03da75e452
No need to cast them into `unsigned int`,
especially using the C-style casting.
Fixes:
Use of 32-bit time_t (Y2K38_SAFETY)
store_truncates_time_t: A time_t value is stored in an integer
with too few bits to accommodate it.
The expression time(NULL) is cast to unsigned int.
Change-Id: I0b7ecb86d4941d4441c8e89ade589064693c226e
Use only references to pass parameters to constructor,
otherwise copy operation would be used instead of move.
Same for other class methods.
Fixes:
Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE)
copy_constructor_call: direct_export is passed-by-value as parameter
to std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::basic_string(std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > const &),
when it could be moved instead.
...
Change-Id: If4be730292b3329af1d806c8cf8292498428ea61
Fix possible memory leak during loading.
No functional change.
Fixes:
Resource leak (RESOURCE_LEAK)
leaked_storage: Variable s going
out of scope leaks the storage it points to.
Change-Id: Ibed584c7ce82056bf0d4c492d76b78584eb7ac08
Use std::condition_variable and std::mutex to implement AmCondition.
Only bools are used for conditions in the code, so make it not a
template.
Change-Id: I57d67492e29c220a5ce941ef67d142b34dcebbff
Give an exact size of the buf to the `snprintf()` and also treat the
returned value from it to eliminate this warning:
src/XmlRpcValue.cpp: In member function 'std::string XmlRpc::XmlRpcValue::timeToXml() const':
src/XmlRpcValue.cpp:404:53: warning: '%02d' directive output may be truncated writing between 2 and 11 bytes into a region of size between 0 and 7 [-Wformat-truncation=]
404 | snprintf(buf, sizeof(buf)-1, "%04d%02d%02dT%02d:%02d:%02d",
| ^~~~
In file included from /usr/include/stdio.h:867,
from /usr/include/c++/10/cstdio:42,
from /usr/include/c++/10/ext/string_conversions.h:43,
from /usr/include/c++/10/bits/basic_string.h:6545,
from /usr/include/c++/10/string:55,
from src/XmlRpcValue.h:14,
from src/XmlRpcValue.cpp:2:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:35: note: '__builtin___snprintf_chk' output between 18 and 70 bytes into a destination of size 19
67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Change-Id: Ic545bbc942715f433610f49286ee9d0f92ee25f6
We should provide a proper formation of the timestamp
in the `timeToXml()`. Just unify that in the manner
it's done in the rest of places.
It will fix then this:
src/XmlRpcValue.cpp: In member function 'std::string XmlRpc::XmlRpcValue::timeToXml() const':
src/XmlRpcValue.cpp:404:53: warning: '%02d' directive output may be truncated writing between 2 and 11 bytes into a region of size between 0 and 7 [-Wformat-truncation=]
404 | snprintf(buf, sizeof(buf)-1, "%04d%02d%02dT%02d:%02d:%02d",
| ^~~~
In file included from /usr/include/stdio.h:867,
from /usr/include/c++/10/cstdio:42,
from /usr/include/c++/10/ext/string_conversions.h:43,
from /usr/include/c++/10/bits/basic_string.h:6545,
from /usr/include/c++/10/string:55,
from src/XmlRpcValue.h:14,
from src/XmlRpcValue.cpp:2:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:35: note: '__builtin___snprintf_chk' output between 18 and 70 bytes into a destination of size 19
67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Change-Id: Iadfed6c14e1bdb0c8ed0b8b36b996ed08b129c42
A mistake in the bool of the return in the XmlRpc::tmEq():
src/XmlRpcValue.cpp: In function 'bool XmlRpc::tmEq(const tm&, const tm&)':
src/XmlRpcValue.cpp:144:52: warning: self-comparison always evaluates to true [-Wtautological-compare]
144 | t1.tm_hour == t2.tm_hour && t1.tm_mday == t1.tm_mday &&
|
Second one should be of the `t2` variable.
Change-Id: I7fbf3b1b2f9becdb14db2e994fb4d0abf0937964