|
| 1 | +diff --git a/pkg/loader/plugin_loader.c b/pkg/loader/plugin_loader.c |
| 2 | +index 3aea70c..a68327a 100644 |
| 3 | +--- a/pkg/loader/plugin_loader.c |
| 4 | ++++ b/pkg/loader/plugin_loader.c |
| 5 | +@@ -33,6 +33,7 @@ typedef void* library_handle_t; |
| 6 | + // note(jasondellaluce,therealbobo): implementation taken from falcosecurity/libs |
| 7 | + // note(leogr): to avoid clashing with `strlcpy` introduced by glibc 2.38, |
| 8 | + // the func has been renamed to plugin_loader_strlcpy. |
| 9 | ++// The same applies to `strlcat`. |
| 10 | + // N.B.: our building system here is not smart enough to detect if the function |
| 11 | + // was declared already. |
| 12 | + #include <stdint.h> |
| 13 | +@@ -61,6 +62,37 @@ static inline size_t plugin_loader_strlcpy(char *dst, const char *src, size_t si |
| 14 | + return srcsize; |
| 15 | + } |
| 16 | + |
| 17 | ++/*! |
| 18 | ++ \brief Append the NUL-terminated string src to the end of dst. It will append at most size − |
| 19 | ++ strlen(dst) − 1 bytes, NUL-terminating the result. |
| 20 | ++ |
| 21 | ++ \return The initial length of dst plus the length of src |
| 22 | ++*/ |
| 23 | ++ |
| 24 | ++static inline size_t plugin_loader_strlcat(char *dst, const char *src, size_t size) { |
| 25 | ++ size_t srcsize = strlen(src); |
| 26 | ++ size_t dstsize = strlen(dst); |
| 27 | ++ |
| 28 | ++ if(dstsize >= size) { |
| 29 | ++ return size; |
| 30 | ++ } |
| 31 | ++ |
| 32 | ++ if(srcsize == 0) { |
| 33 | ++ return dstsize; |
| 34 | ++ } |
| 35 | ++ |
| 36 | ++ size_t totalsize = srcsize + dstsize; |
| 37 | ++ if(totalsize > size - 1) { |
| 38 | ++ totalsize = size - 1; |
| 39 | ++ } |
| 40 | ++ |
| 41 | ++ size_t copysize = totalsize - dstsize; |
| 42 | ++ memcpy(dst + dstsize, src, copysize); |
| 43 | ++ dst[totalsize] = '\0'; |
| 44 | ++ |
| 45 | ++ return dstsize + srcsize; |
| 46 | ++} |
| 47 | ++ |
| 48 | + static inline void err_prepend(char* s, const char* prefix, const char* sep) { |
| 49 | + char tmp[PLUGIN_MAX_ERRLEN]; |
| 50 | + size_t prefix_len = plugin_loader_strlcpy(tmp, prefix, PLUGIN_MAX_ERRLEN); |
| 51 | +@@ -74,9 +106,9 @@ static inline void err_prepend(char* s, const char* prefix, const char* sep) { |
| 52 | + |
| 53 | + static inline void err_append(char* s, const char* suffix, const char* sep) { |
| 54 | + if(*s != '\0') { |
| 55 | +- strlcat(s, sep, PLUGIN_MAX_ERRLEN); |
| 56 | ++ plugin_loader_strlcat(s, sep, PLUGIN_MAX_ERRLEN); |
| 57 | + } |
| 58 | +- strlcat(s, suffix, PLUGIN_MAX_ERRLEN); |
| 59 | ++ plugin_loader_strlcat(s, suffix, PLUGIN_MAX_ERRLEN); |
| 60 | + } |
| 61 | + |
| 62 | + static void* getsym(library_handle_t handle, const char* name) { |
0 commit comments