1
0
mirror of https://github.com/fumiama/base16384.git synced 2026-06-06 10:40:30 +08:00

优化 hardening

This commit is contained in:
源文雨
2022-10-16 12:50:57 +08:00
parent 6d251fcfc7
commit 1b6ba41562
2 changed files with 17 additions and 16 deletions

View File

@@ -18,6 +18,14 @@ ELSE()
add_library(base16384_s STATIC file.c base1432.c)
ENDIF()
if (MSVC)
# do nothing
else()
# add hardening
target_compile_options(base16384 INTERFACE -Wl,-z,relro,-z,now -Wdate-time)
add_definitions(-D_FORTIFY_SOURCE=2)
endif()
set_target_properties(base16384_b PROPERTIES OUTPUT_NAME base16384)
set_target_properties(base16384_s PROPERTIES OUTPUT_NAME base16384)
set_target_properties(base16384 PROPERTIES VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

25
file.c
View File

@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef _WIN32
#include <windows.h>
#else
@@ -73,10 +74,8 @@ base16384_err_t base16384_encode_file(const char* input, const char* output, cha
return base16384_err_write_file;
}
}
/* 由操作系统负责释放资源
fclose(fpo);
fclose(fp);
以缩短程序运行时间 */
fclose(fpo);
fclose(fp);
#ifndef _WIN32
} else { // small file, use mmap & fwrite
int fd = open(input, O_RDONLY);
@@ -95,10 +94,8 @@ base16384_err_t base16384_encode_file(const char* input, const char* output, cha
return base16384_err_write_file;
}
munmap(input_file, (size_t)inputsize);
/* 由操作系统负责释放资源
fclose(fpo);
close(fd);
以缩短程序运行时间 */
fclose(fpo);
close(fd);
}
#endif
return base16384_err_ok;
@@ -156,10 +153,8 @@ base16384_err_t base16384_decode_file(const char* input, const char* output, cha
return base16384_err_write_file;
}
}
/* 由操作系统负责释放资源
fclose(fpo);
fclose(fp);
以缩短程序运行时间 */
fclose(fpo);
fclose(fp);
#ifndef _WIN32
} else { // small file, use mmap & fwrite
int fd = open(input, O_RDONLY);
@@ -176,10 +171,8 @@ base16384_err_t base16384_decode_file(const char* input, const char* output, cha
return base16384_err_write_file;
}
munmap(input_file, (size_t)inputsize);
/* 由操作系统负责释放资源
fclose(fpo);
close(fd);
以缩短程序运行时间 */
fclose(fpo);
close(fd);
}
#endif
return base16384_err_ok;