Skip to content

Commit 93187cd

Browse files
committed
fix: security in both prompt.c and build.sh, aswell as see that reading and writing in binary mode is unneeded.
1 parent 0e6973a commit 93187cd

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

build/build.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ clean() {
409409
CLEAN="y"
410410
fi
411411
if [[ ${CLEAN} =~ [Yy] ]]; then
412-
rm -fr "${LOCALOUT}"/*
413-
rm -fr "${LOCALBIN}"/*
412+
rm -fr "${LOCALOUT:?}"/*
413+
rm -fr "${LOCALBIN:?}"/*
414414
if ${LOG}; then
415415
echo -e "${GREEN}${CLEAR} Cleaned ${CYAN}${LOCALOUT}/*${CLEAR} & ${CYAN}${LOCALBIN}/*${CLEAR} successfully."
416416
fi

src/hamon/file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void *convert_string_to_wide(const char *str) {
3636
#endif
3737

3838
int write_file(const char *filename, const char *content) {
39-
FILE *file = fopen(filename, "wb");
39+
FILE *file = fopen(filename, "w");
4040
if (!file) {
4141
perror("Failed to open file");
4242
fclose(file);
@@ -53,7 +53,7 @@ int write_file(const char *filename, const char *content) {
5353
}
5454

5555
char *read_file(const char *file_path) {
56-
FILE *file = fopen(file_path, "rb");
56+
FILE *file = fopen(file_path, "r");
5757
size_t file_len = 0;
5858

5959
if (!file) {

src/hamon/prompt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ char **get_environment_variables() {
8787
while (*ptr != '\0' && count < 4096 - 1) {
8888
size_t len = strlen(ptr);
8989
env_array[count] = malloc(len + 1);
90-
strcpy(env_array[count], ptr);
90+
strlcpy(env_array[count], ptr, strlen(env_array[count]) + 1);
9191
ptr += len + 1;
9292
count++;
9393
}

0 commit comments

Comments
 (0)