Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove path prefix in RNP_LOG #2297

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ set_property(CACHE ENABLE_DOC PROPERTY STRINGS ${TRISTATE_VALUES})
# so we can use our bundled finders
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")

# add source path prefix length to be able to crop it in logs
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")

# required modules
include(CTest)
include(FetchContent)
Expand Down Expand Up @@ -194,6 +198,11 @@ if (ENABLE_DOC)
include(AdocMan)
endif()

# make sure that msvc set full path in __FILE__ macro
if(MSVC)
add_compile_options(/FC)
endif()

# everything else is in subdirs
add_subdirectory(src/examples)
if (ENABLE_FUZZERS)
Expand Down
2 changes: 1 addition & 1 deletion include/rekey/rnp_key_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class KeyStore {
pgp_key_t *add_key(pgp_key_t &key);

/**
* @brief Add signature of the specific key to the keystore, revalidating and refresing
* @brief Add signature of the specific key to the keystore, revalidating and refreshing
* key's data.
*
* @param keyfp key's fingerprint.
Expand Down
16 changes: 9 additions & 7 deletions src/lib/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ class LogStop {
};
} // namespace rnp

#define RNP_LOG_FD(fd, ...) \
do { \
if (!rnp_log_switch()) \
break; \
(void) fprintf((fd), "[%s() %s:%d] ", __func__, __FILE__, __LINE__); \
(void) fprintf((fd), __VA_ARGS__); \
(void) fprintf((fd), "\n"); \
#define __SOURCE_PATH_FILE__ (__FILE__ + SOURCE_PATH_SIZE + 3 /* remove "src" */)

#define RNP_LOG_FD(fd, ...) \
do { \
if (!rnp_log_switch()) \
break; \
(void) fprintf((fd), "[%s() %s:%d] ", __func__, __SOURCE_PATH_FILE__, __LINE__); \
(void) fprintf((fd), __VA_ARGS__); \
(void) fprintf((fd), "\n"); \
} while (0)

#define RNP_LOG(...) RNP_LOG_FD(stderr, __VA_ARGS__)
Expand Down
5 changes: 5 additions & 0 deletions src/tests/cli_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4301,6 +4301,11 @@ def test_default_v5_key(self):

shutil.rmtree(RNP2, ignore_errors=True)

def test_warning_source_path_prefix_cropping(self):
ret, _, err = run_proc(RNPK, ['--keyfile', data_path(PUBRING_7), '--notty', '--list-keys'])
self.assertEqual(ret, 0)
self.assertRegex(err, r'(?s)^.*\[signature_validate\(\) [/\\]lib[/\\]crypto[/\\]signatures.cpp:[0-9]*\] Insecure hash algorithm [0-9]*, marking signature as invalid.*$')

class Encryption(unittest.TestCase):
'''
Things to try later:
Expand Down
Loading