summaryrefslogtreecommitdiff
path: root/src/shared/dlt_common.c
Commit message (Collapse)AuthorAgeFilesLines
* logfile: exhance internal dlt logging by introducing size limits (#369)Daniel Weber2023-03-101-10/+146
| | | | | | | | | | | Enhance dlt logging such that multiple files are used as it is done for the offline traces. Add limit-specific config values for logging. For this purpose the pattern of index-based file names is used only. This approach of logging to multiple files and rotating in order to keep the limits ensures that dlt logs take care of available space on the underlying file system and do not grow infinitely. Signed-off-by: Daniel Weber <daniel.w.weber@daimler.com> Co-authored-by: Oleg Tropmann <oleg.tropmann@daimler.com>
* Check for negative index in dlt_file_messageMichael Methner2023-01-271-1/+1
| | | | | | Fixes #436 Signed-off-by: Michael Methner <mmethner@de.adit-jv.com>
* client: Fix Get Log Info response conversion method (#422)Andrei Rusu2022-11-301-1/+1
| | | | Signed-off-by: Andrei-Mircea Rusu <andrei-mircea.rusu@continental-corporation.com>
* Avoid memory corruption behind buffer wp in function ↵michael-methner2022-10-111-5/+18
| | | | | | | | | | | | dlt_getloginfo_conv_ascii_to_id (#411) * Avoid memory corruption behind buffer wp in function dlt_getloginfo_conv_ascii_to_id - Introduced new function dlt_getloginfo_conv_ascii_to_string for '\0' terminated strings - Avoid printing garbage characters in dlt-control after APID and CTID (which are not null terminated anymore) - Added unit test for dlt_client_parse_get_log_info_resp_text and dlt_getloginfo_conv_ascii_to_string - Use dlt_getloginfo_conv_ascii_to_string to get '\0' terminated for app_description and context_description Signed-off-by: Michael Methner <mmethner@de.adit-jv.com>
* dlt_common: change output of message for log initialization (#412)lti9hc2022-10-061-1/+1
| | | | | | | Switch dlt_vlog() to dlt_user_printf(), the message could be observed in case the log can not be written in file Signed-off-by: Le Tin <tin.le@vn.bosch.com>
* internal-logging: Fix issues with file logging (#378)Alexander Mohr2022-10-051-4/+6
| | | | | | | | | | | | | This commit fixes the following issues if access to the internal log file is not possible (logging_mode = DLT_LOG_TO_FILE) * dlt_log_free tried to call fclose on a nullptr Added a nullcheck for this * Access to log file might be denied but access to logs is still wanted Add a new CMake option WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK If this is set to ON and the logging moe is set to file, the dlt-daemon will fall back to syslog if opening the internal log file failed Signed-off-by: Alexander Mohr <alexander.m.mohr@mercedes-benz.com>
* dlt_common.c: Change default logging_mode (#406)wusto2022-09-211-1/+1
| | | | | | | | | | | | | | | | | Up to now the default for logging is stdout (DLT_LOG_TO_CONSOLE). Scenario: program_a arg1 | dd of=/my-beauty-case If program_a wants to log to dlt, but it fails to connect to the socket: socket /run/dlt-files/dlt cannot be opened, error:Resource temporarily unavailable. Retrying later... The error will be logged by default to stdout leading in the best case to an error and in the worst to damaged partitions. To solve this log to STDERR (DLT_LOG_TO_STDERR) by default. Co-authored-by: Tobias Kaufmann <Tobias.KA.Kaufmann@bmw.de>
* Fix handle returned value (#384)Bui Nguyen Quoc Thanh2022-07-071-17/+43
| | | | | | | | | | | | | | | | * common: Handle returned value - The returned value of supporting APIs should be checked correctly. - In case of extended header, the buffer of header must be checked before proceeding further. Signed-off-by: Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com> * console: Handle returned value In case of parsing dlt file, the failed messages should be skipped by evaluating returned value Signed-off-by: Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>
* Support for Cygwin toolchain. (#351)DoctorNoobingstoneIPresume2021-11-151-0/+1
| | | | | | Also tested with the latest version running on Windows XP (gcc-5.4.0) (http://www.crouchingtigerhiddenfruitbat.org/cygwin/timemachine.html). Signed-off-by: Adder <adder_2003@yahoo.com>
* fix -Wformat issues reported by clang (#349)sebastienr2021-11-091-5/+5
| | | | | | | | | | | | | | * some previous dlt_vlog was using %lu specifier to display an uint64_t variable. However, this isn't portable as depending on the system you're targeting (32bits, 64bits, Linux, android, etc.), the uint64_t can be an unsigned long long. This prevents compilation on system where -Werror and -Wformat is activated coupled with a less tolerant compiler (e.g clang). Instead, PRIxN macros (e.g PRIu64 for uint64_t) are now used as specifier to ensure compatibility for each platforms * for bytes_read which is of type ssize_t, zd specifier is used as indicated in C99 standard * for st_size (from struct stat) which is of type off_t, POSIX says that it should be a signed integer. To be safe, we now use %jd specifier to ensure that it will fit correctly
* lib: generate dlt library internal log fileLe-Tin2021-10-051-2/+2
| | | | | | | Extern logging_mode and logging_handle variables from commom.c Reusing dlt_log_init() in cases dlt library internal log file is not opened and logging_mode is DLT_LOG_TO_FILE Signed-off-by: Le-Tin <Tin.Le@vn.bosch.com>
* dlt_common: remove duplicate stdbool headerDinh Cong Toan2021-10-051-1/+0
| | | | | | | Remove duplicate stdbool.h file in dlt_common.c, which has been included in dlt_common.h Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com>
* fix malformed printf format strings (#295)Radek Kaczorowski2021-10-051-45/+33
| | | Co-authored-by: Saya Sugiura <39760799+ssugiura@users.noreply.github.com>
* dlt_common: correct read/write positionDinh Cong Toan2021-06-301-3/+9
| | | | | | | | | In dlt_buffer_read_block() and dlt_buffer_write_block(), read/write position should be updated in case these positions are equal to the size of ringbuffer. Adding boundary check in gtest_dlt_common.cpp Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com>
* Update document and fix conversion warningDinh Cong Toan2021-06-301-1/+1
| | | | Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com>
* dlt_common: Increment size after memcpy()Dinh Cong Toan2021-06-301-3/+2
| | | | | | | | | This commit fixes to increment read and write point only if memcpy() succeeded in dlt_buffer_read_block() and dlt_buffer_write_block(). Related issues: https://github.com/GENIVI/dlt-daemon/issues/305 Signed-off-by: Sugiura, Saya <ssugiura@jp.adit-jv.com>
* Alternative solutions for json-c dependencyBiastoch, Darian (ADITG/ESM)2021-06-301-297/+0
| | | | | | | json-c dependency was removed from libdlt ('dlt_common') and shifted into 'dlt-control-common'. By this only the command line tools have a dependency on json-c. dlt-control-common is now built as a static library, so that it can be linked against json-c. Command line tools that included only the .c file of dlt-control-common before, are now linked against this static libarary (see console/CMakeLists.txt). Signed-off-by: dbiastoch <dbiastoch@de.adit-jv.com>
* dlt-receive:Fix compiler warningdbiastoch2021-06-301-4/+8
| | | | | | | | dlt_common.c: -Check if filter file fits into read buffer -Cast 'filename' into non-const to make it json-c API conform Signed-off-by: dbiastoch <dbiastoch@de.adit-jv.com>
* dlt-receive: Enabled more filtering by using json filter filesdbiastoch2021-06-301-145/+475
| | | | | | | | | | | | | | | -Added '-j' flag to dlt-receive for reading a json filter file -Added more attributes to DltFilter (LogLevel, MaxPayload, MinPayload) for extended message filtering, when using old filters these values are set to default. Same behaviour, when they are not defined in json filter file. -extended dlt_common.c to support json filter files and new DltFilter attributes +add dlt_json_filter_load to parse a json filter file into a DltFilter +add dlt_json_filter_save to print a DltFilter into a json file -Two new libraries are used to parse the json filter files: json-c for Linux based systems and the QNX internal libjson for QNX systems -gtest_dlt_common was modified to test the new function 'dlt_json_filter_load' +add testfile_extended.dlt that contains a bigger varity of messages (different context/app IDs, lengths and log levels) +add testfilter.json which is a valid json filter file -New dependency on library was added to related CMakeLists and is described in README.md Signed-off-by: dbiastoch <dbiastoch@de.adit-jv.com>
* dlt message header brokenDinh Cong Toan2021-06-301-1/+1
| | | | | | | | | | | | | This commit is to revert the following commits: - de4a4234 - fb9ff078 - db9917b3 - e4467f0e - a567e01d Those commits are from improvement but they seem to break the dlt message header in some cases. Signed-off-by: Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>
* daemon: check the conf inputsBui Nguyen Quoc Thanh2021-05-101-0/+8
| | | | | | | | | | | | | | The configuration of memory buffer size must be carefully parsed and validated to avoid segmentation fault Any misleading information in configuration file must be considered as major error and dlt-daemon should stop and raise error message to stderr This commit also corrects error handling of dlt_buffer_init_dynamic(). Signed-off-by: Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>
* Better formatting of RAWD (#291)Martin Willers2021-04-051-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the bytes of a RAWD argument were be printed onto the console as space-separated hex values, making it difficult or impossible to see where the RAWD argument ends and the next argument starts. For instance, with code like this: dlt_user_log_write_raw(&ctxData, "data", 4); dlt_user_log_write_uint8(&ctxData, 53); the console output is shown as: [64 61 54 61 53] and there is no indication that there are two arguments, one RAWD and one UINT8. This patch changes for console formatting of RAW data to separate by apostrophs, making the above message appear as: [64'61'54'61 53] This makes it immediately obvious that there is a RAWD argument, and still keeps the separators quite unobtrusive. Signed-off-by: Martin Willers <M.Willers@gmx.net>
* Add verbose mode attribute handling (#292)Martin Willers2021-03-161-28/+107
| | | | | | dlt_user_log_write_*_attr() enables to writing these types, but also support adding "attributes" for them, i.e. a "name" and a "unit". Signed-off-by: Martin Willers <M.Willers@gmx.net>
* fscanf() uses dynamic formatting to prevent buffer overflow (#288)Kevin-Luong2021-01-291-2/+5
| | | | | | | CVE: CVE-2020-29394 Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com> Co-authored-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
* gtest_dlt_common: fix seg fault when using memcpy().Dinh Cong Toan2021-01-061-5/+9
| | | | | | | | - Checking size of buffer and size of message before using memcpy(). - Adding configuration file for testfilter in /tests/CMakeLists.txt. Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com>
* other: fix remaining conversion warningsDinh Cong Toan2021-01-061-34/+34
| | | | | | | | | | | - Converting datatype to the correct one. - As macro do not perform type-checking before, so these functions used it with different datatype could create a lot of conversion warnings. For this reason, these warnings could be consider as normal information and will not be fixed. Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com>
* library: fix conversion warningsDinh Cong Toan(RBVH/ECM12)2021-01-061-21/+42
| | | | | | | | | | | | - Change the data type of variable 'size' in DltContextData struct (dlt_user.h.in). Variable 'size' was used repeated with function 'sizeof()' many time, so change type to 'size_t' can avoid a lot of warnings. - Adding temporary variable to calculate the datasize header (define in dlt_common.h) in 'dlt_common.c' file. Signed-off-by: Dinh Cong Toan(RBVH/ECM12) <Toan.DinhCong@vn.bosch.com>
* shared: fix conversion warningsiod1hc2021-01-061-66/+66
| | | | | | | | | | | - Data type of 'textlength' create a lot of warnings while using in function 'snprintf()', so change data type to 'size_t' will resolve these warnings. - Change data type of variable 'size' to the right type 'unsigned int', which is located in struct DltBuffer in dlt_common.h (line 832). Signed-off-by: Dinh Cong Toan <toan.dinhcong@vn.bosch.com> Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* gateway: fix compile warningsDinh Cong Toan(RBVH/ECM12)2021-01-061-4/+3
| | | | | | | | | - Correct the data type of 'headersize' and 'datasize' variables in header 'dlt_common.h', then config those functions using this library. - Explicit the data type. Signed-off-by: Dinh Cong Toan(RBVH/ECM12) <Toan.DinhCong@vn.bosch.com>
* dlt_common: Execute system command using execvpKHANH LUONG HONG DUY2021-01-061-0/+55
| | | | | | | Add function dlt_execute_command() to execute system command using execvp. Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
* Add support for logging with VSOCK (#255)Martin Ejdestig2020-12-141-46/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For more information about VSOCK, see "man vsock" ( https://man7.org/linux/man-pages/man7/vsock.7.html ). Makes it possible for processes in a virtual machine to log directly in DLT running on host without setting up a network connection between guest and host. It is also probably more efficient. Have not done any performance measurements (not main reason for patch), but no forwarding is required as when running DLT in a multi-node setup. When building dlt-daemon for host, WITH_DLT_DAEMON_VSOCK_IPC should be enabled for daemon to listen on incoming VSOCK requests. Local communication method between applications and daemon is still determined with DLT_IPC. When building for guest, WITH_DLT_LIB_VSOCK_IPC should be enabled and DLT_IPC will be ignored, which will make libdlt open a VSOCK socket to the deamon for logging messages. VSOCK can be tested without a virtual machine. Since VMADDR_CID_HOST is used by libdlt when connecting, see vsock man page, clients can be run on host to test VSOCK communication. Some modifications has been done to be able to handle logging through FIFO pipe and socket in the same build of dlt-daemon: - dlt_receiver_init/free_unix_socket() is renamed to dlt_receiver_init/free_global_buffer() and used for FIFO as well. Also fixes memory leak since dlt_receiver_free_unix_socket() was used regardless of whether DLT_USE_UNIX_SOCKET was defined or not. - Pass type to dlt_receiver_init() instead of dlt_receiver_receive(). And remove preprocessor conditionals for handling DLT_CONNECTION_APP_MSG in dlt_daemon_process_user_messages(). Also fixes wrong enum type being passed to dlt_receiver_receive() in dlt_client.c (DltClient::mode was used as a DltReceiverType enum but it is a DltClientMode enum). - Add a flag to DltDaemonApplication to indicate whether file descriptor is "owned" by the DltDaemonApplication or not. When dlt_daemon_application_add() is called due to message received on a socket, fd is passed as an argument (app does not own fd). For FIFO, a per application FIFO is opened (app owns the fd). Also fixes so that user handle is reset for both application and all its contexts when resetting any. Prevents fd from being used by accident after it has been closed. dlt_mkdir_recursive() is moved to src/daemon since it is only used in the daemon. Minimizes use of DLT_USE_UNIX_SOCKET_IPC. Other bugfixes: - Call DLT_SEM_FREE() if setting socket to O_NONBLOCK fails in src/lib/dlt_user.c:dlt_initialize_socket_connection(). - Close socket if dlt_receiver_init() fails in src/lib/dlt_user.c:dlt_initialize_socket_connection(). Signed-off-by: Martin Ejdestig <martin.ejdestig@volvocars.com>
* Check size of ring buffer (#269)schrewe2020-12-071-12/+26
| | | | | | | | | | | | | | There is no check if "data" fits into the ring buffer buffer. This causes a write heap buffer overflow. If data is too big for the ringbuffer nothing is written to the ringbuffer and a error is logged If the buffers are bigger than the free space in the ringbuffer, the ringbuffer is increased by a step size set at initialization. But there is no check if this increase was sufficient. Fix this by using a while loop that increases the ring buffer size until it is big enough or the buffer can not be further increased. Signed-off-by: Jan Schrewe <schrewe@uni-bonn.de>
* dlt_common: Fix buffer overflow in dlt_filter_load (#275)gy7412020-11-301-2/+2
| | | | | | | A buffer overflow in the dlt_filter_load function in dlt_common.c in dlt-daemon allows arbitrary code execution via an unsafe usage of fscanf, because it does not limit the number of characters to be read in a format argument. Fixed: #274 Signed-off-by: GwanYeong Kim <gy741.kim@gmail.com>
* Avoid memory access errors with 4-chars context ids (#250)Martin Willers2020-11-171-8/+15
| | | | | | | | | | | | | | | | | | | | | | | | For a 4-chars CTXID, i.e. one that does not include a null character, the strlen() calls were happily accessing memory until they eventually encountered a null character somewhere in memory. This was detected by valgrind, which reported a memory error when using a CTXID such as "INTM": ==21924== Conditional jump or move depends on uninitialised value(s) ==21924== at 0x4C30F78: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==21924== by 0x4E4B5A0: dlt_print_id (dlt_common.c:303) ==21924== by 0x4E4CF47: dlt_message_header_flags (dlt_common.c:687) ==21924== by 0x4E51434: dlt_message_print_ascii (dlt_common.c:3169) ==21924== by 0x4E4247A: dlt_user_print_msg (dlt_user.c:4108) ==21924== by 0x4E46D92: dlt_user_log_send_log (dlt_user.c:3670) ==21924== by 0x4E46F14: dlt_user_log_write_finish (dlt_user.c:1611) Sanitize some code Using memset() and memcpy() is always preferable to hand-rolled loops, because compilers have built-in support for them. Signed-off-by: Martin Willers <M.Willers@gmx.net>
* dlt-common.c: ensure null terminated string (#256)Moritz Warning2020-11-101-1/+1
| | | Signed-off-by: Moritz Warning <moritzwarning@web.de>
* Implement DLTClient for UDP multicast (#240)João Sousa2020-08-311-1/+14
| | | | | | | | | * Add UDP multicast support on client side UDP multicast support is already present on server side. This patch add seemless support for UDP multicast on client side in dlt-receive. Signed-off-by: Joao Sousa <joao.sa.sousa@ctw.bmwgroup.com>
* common: Isolate FIFO/Unix socketLUONG HONG DUY KHANH(RBVH/ENG42)2020-07-061-3/+9
| | | | | | | | | | | | | | dlt_common - Add preprocessor DLT_USE_UNIX_SOCKET_IPC for dlt_log_set_fifo_basedir() and dltFifoBaseDir variable - Rename input parameter of dlt_log_set_fifo_basedir() dlt-daemon - Replace setting dltFifoBaseDir by dlt_log_set_fifo_basedir() and add preproc DLT_USE_UNIX_SOCKET_IPC - Update -h opt and flags.loggingFilename based on IPC type Signed-off-by: LUONG HONG DUY KHANH(RBVH/ENG42) <KHANH.LUONGHONGDUY@vn.bosch.com>
* libdlt: Relocate dltFifoBaseDir settingLUONG HONG DUY KHANH(RBVH/ENG42)2020-07-061-0/+3
| | | | | | | Relocate the setting of dltFifoBaseDir variable from dlt_init() to dlt_check_envvar() Signed-off-by: LUONG HONG DUY KHANH(RBVH/ENG42) <KHANH.LUONGHONGDUY@vn.bosch.com>
* Improve performance of DLT file parsingBui Nguyen Quoc Thanh2020-07-061-0/+69
| | | | | | Introduce new API to support quick parsing a DLT file. Signed-off-by: Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>
* Redirect stdout to stderrLUONG HONG DUY KHANH(RBVH/ENG42)2020-07-061-13/+45
| | | | | | | | | | | | - daemon: New feature for LoggingMode at /etc/dlt.conf to be able to set value at 3 in order to redirect all stdout messages to stderr. - libdlt: New feature for DLT_LOG_MODE environment variable to be able to set value at 3 in order to redirect all stdout messages to stderr. - unit test: Add test cases for DLT_LOG_TO_STDERR Signed-off-by: LUONG HONG DUY KHANH(RBVH/ENG42) <KHANH.LUONGHONGDUY@vn.bosch.com>
* fix some gcc9 compiler warningsFelix Herrmann2020-07-061-3/+4
| | | | | | | | | Many stringop-truncation and stringop-overflow warnings are still there (so many). https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/ Signed-off-by: Felix Herrmann <fherrmann@de.adit-jv.com> Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
* Android: Enable Android buildFelix Herrmann2020-07-061-2/+5
| | | | | Signed-off-by: Felix Herrmann <fherrmann@de.adit-jv.com> Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
* shared: Read DLT header until it's foundSaya Sugiura2020-07-061-13/+31
| | | | | | | | | Current dlt_file_read_header() function which is used for e.g. dlt-convert, dlt-sortbytimestamp, etc. stops finding DLT header if it's not available in the next file position. It is improved to read the header in a loop until it's found. Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* Revert "dlt_common: Fix buffer overflow in dlt_buffer_get (#215)"Saya Sugiura2020-06-161-4/+2
| | | | This reverts commit e420ee62d89d5efab6ad7275910cb3eec8497da6.
* common: Fix uint64 type (#217)Saya Sugiura2020-04-021-1/+1
| | | | | | The log message was printed as a signed value for uint64 type. This commit fixes to print as an unsigned value. Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
* dlt_common: Fix buffer overflow in dlt_buffer_get (#215)Ricardo Leite2020-03-301-2/+4
| | | | | | A DLT lib user can create a message large enough that dlt_user.resend_buffer is not large enough, and thus it will overflow Signed-off-by: Ricardo Leite <rleite@dcc.fc.up.pt>
* FIX: Check validity of `file` pointer before usage.Sebastian Kloska2020-02-201-3/+3
| | | | | | | Check for file == null before accessing the pointer for a debug message Signed-off-by: Sebastian Kloska <sebastian.kloska@snafu.de>
* Fix compiler warnings: pointer of type ‘void *’ used in arithmetic (#196)Sebastian Lipponer2019-12-101-2/+2
| | | Signed-off-by: Sebastian Lipponer <mail@sebastianlipponer.de>
* Change the DLT_CHECK_RCV_DATA_SIZE macro to an internal function (#191)Sebastian Lipponer2019-11-251-0/+10
| | | | | | | | | The use of this macro in a if condition is actually non-standard C++ code. GCC issues a warning that ISO C++ forbids braced-groups within expressions when compiled with -Wpedantic. Other compilers fail with an error. Change the macro to an internal function in order to improve the portability to other platforms (i.e. MSVC, proprietary embedded). Signed-off-by: Sebastian Lipponer <mail@sebastianlipponer.de>
* Avoided Seg fault in dlt_message_payload (#179) (#181)Vo Trung Chi2019-11-141-54/+60
| | | | | | | | | * Avoided Seg fault in dlt_message_payload (#179) Avoided Seg fault by adding boundary check before buffer access. Signed-off-by: Ravi Sankar P <ponnurangamravi.sankar@in.bosch.com> Signed-off-by: Vo Trung Chi <chi.votrung@vn.bosch.com>