Skip to content

Commit

Permalink
[FIX] [valord]: fix crash because of non-resetted errors
Browse files Browse the repository at this point in the history
  • Loading branch information
0xf104a committed May 27, 2024
1 parent ebf88b5 commit 0a5a47d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion valord/src/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


char *make_proc_path(char *dirname) {
reset_errors;
char *path = (char *) malloc((7 + strlen(dirname)) * sizeof(char));
cerror("malloc");
strcpy(path, "/proc/");
Expand Down Expand Up @@ -57,7 +58,7 @@ char *get_process_comm(const char *proc_path) {
if (!file) {
#if DEBUG
error("Failed to open file: %s", filename);
perror("fopen");
valor_perror("fopen");
#endif
free(filename);
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions valord/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ bool is_int(char *str) {
/**
* Prints error to log. Does not exits from program
* @param _name name of call where error may occur
* @param _file name of file of perror call(passed by macro)
* @param _line number of line of perror call(passed by macro)
* @param _file name of file of valor_perror call(passed by macro)
* @param _line number of line of valor_perror call(passed by macro)
* @return whether there was an error
*/
bool perror_internal(const char *_name, const char *_file, int _line) {
Expand Down
2 changes: 1 addition & 1 deletion valord/src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @note Resets global errno variable to 0 after execution
* @return whether there was an error
*/
#define perror(c) perror_internal(c, __FILE__, __LINE__)
#define valor_perror(c) perror_internal(c, __FILE__, __LINE__)

/**
* Resets last error
Expand Down
6 changes: 3 additions & 3 deletions valord/src/valor.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <unistd.h>


const char *VERSION = "0.2.3";
const char *VERSION = "0.2.4";
const char *DB_FILE = "/system/etc/valor.db";
const uint8_t IDLE_TIME = 3;

Expand Down Expand Up @@ -79,7 +79,7 @@ int main(void) {
warn("Detected threat by name %s", proc.comm);
reset_errors;
kill(proc.pid, 9);
if (!perror("kill")) {
if (!valor_perror("kill")) {
info("Sent signal 9 to %d", proc.pid);
}
} else if(proc.comm != NULL) {
Expand All @@ -91,7 +91,7 @@ int main(void) {
warn("Threat with PID %d is matching to database checksum on %.2f%%", matching_k * 100.0);
reset_errors;
kill(proc.pid, 9);
if (!perror("kill")) {
if (!valor_perror("kill")) {
info("Sent signal 9 to %d", proc.pid);
}
}
Expand Down

0 comments on commit 0a5a47d

Please sign in to comment.