Fix compiler warnings and improve code quality

- Replace unsafe strcpy with strcpy_s for better security
- Fix DLL binding issues by adding PRIVATEBIN_API macros
- Add explicit type casts to resolve size conversion warnings
- Replace unsafe getenv with _dupenv_s for better security
- Add PRIVATEBINAPI_EXPORTS definition in CMakeLists.txt
- Improve CMake configuration for better build compatibility
This commit is contained in:
mbusc
2025-08-28 21:25:25 +02:00
parent b97d9f2d7f
commit cd7e957692
5 changed files with 24 additions and 18 deletions

View File

@@ -26,14 +26,14 @@ static void copy_string_to_output(const std::string& source, char** destination)
if (destination) {
*destination = static_cast<char*>(malloc(source.length() + 1));
if (*destination) {
std::strcpy(*destination, source.c_str());
strcpy_s(*destination, source.length() + 1, source.c_str());
}
}
}
extern "C" {
int create_paste(const char* server_url, const char* content,
PRIVATEBIN_API int create_paste(const char* server_url, const char* content,
const char* password, const char* expiration,
const char* format, int burn_after_reading,
int open_discussion, char** paste_url,
@@ -128,10 +128,10 @@ int create_paste(const char* server_url, const char* content,
}
}
int upload_file(const char* server_url, const char* file_path,
const char* password, const char* expiration,
int burn_after_reading, int open_discussion,
char** paste_url, char** delete_token) {
PRIVATEBIN_API int upload_file(const char* server_url, const char* file_path,
const char* password, const char* expiration,
int burn_after_reading, int open_discussion,
char** paste_url, char** delete_token) {
if (!server_url || !file_path) {
return ERROR_INVALID_INPUT;
@@ -248,7 +248,7 @@ int upload_file(const char* server_url, const char* file_path,
}
}
int get_paste(const char* server_url, const char* paste_id,
PRIVATEBIN_API int get_paste(const char* server_url, const char* paste_id,
const char* key, char** content) {
if (!server_url || !paste_id || !key || !content) {
@@ -305,7 +305,7 @@ int get_paste(const char* server_url, const char* paste_id,
}
}
int delete_paste(const char* server_url, const char* paste_id,
PRIVATEBIN_API int delete_paste(const char* server_url, const char* paste_id,
const char* delete_token) {
if (!server_url || !paste_id || !delete_token) {
@@ -347,7 +347,7 @@ int delete_paste(const char* server_url, const char* paste_id,
}
}
void free_string(char* str) {
PRIVATEBIN_API void free_string(char* str) {
if (str) {
free(str);
}