Skip to content

Commit

Permalink
ref: Formating and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
userwiths committed Aug 15, 2024
1 parent aa3480d commit 4815aef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
1 change: 0 additions & 1 deletion freshclam/freshclam.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,6 @@ static fc_error_t initialize(struct optstruct *opts)
}
#endif /* HAVE_PWD_H */


/*
* Set libfreshclam callback functions.
*/
Expand Down
51 changes: 25 additions & 26 deletions libfreshclam/libfreshclam.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,49 +126,48 @@ const char *fc_strerror(fc_error_t fcerror)
int fc_upsert_logg_file(fc_config *fcConfig)
{
int ret = 0;
char* current_dir = "/";
char* file_path = strdup(fcConfig->logFile);
char* log_file = fcConfig->logFile;
char* token = strtok(file_path, "/");
FILE *logg_fp = NULL;
struct passwd *current_user = getpwuid(getuid());
struct passwd *db_owner = getpwnam(fcConfig->dbOwner);
current_dir = (char*)malloc(2);
strcpy(current_dir, "/");
char *current_path, *file_path = strdup(fcConfig->logFile), *token;
FILE *logg_fp = NULL;
token = strtok(file_path, PATHSEP);
struct passwd *current_user = getpwuid(getuid()), *db_owner = getpwnam(fcConfig->dbOwner);

Check warning on line 132 in libfreshclam/libfreshclam.c

View workflow job for this annotation

GitHub Actions / build-windows

'initializing': 'passwd *' differs in levels of indirection from 'int'
current_path = (char *)malloc(2);
strcpy(current_path, PATHSEP);
STATBUF sb;

while (token != NULL) {
current_dir = (char*)realloc(current_dir, strlen(current_dir) + strlen(token) + 2);
strcat(current_dir, token);
token = strtok(NULL, "/");
if(token == NULL) {
current_path = (char *)realloc(current_path, strlen(current_path) + strlen(token) + 2);
strcat(current_path, token);
token = strtok(NULL, PATHSEP);
if (token == NULL) {
break;
}
if(LSTAT(current_dir, &sb) == -1) {
if(mkdir(current_dir, 0755) == -1) {
printf("ERROR: Failed to create required directory %s. Will continue without writing in %s.\n", current_dir, log_file);
if (LSTAT(current_path, &sb) == -1) {
if (mkdir(current_path, 0755) == -1) {
printf("ERROR: Failed to create required directory %s. Will continue without writing in %s.\n", current_path, fcConfig->logFile);
ret = -1;
goto cleanup;
}
if(chown(current_dir, db_owner->pw_uid, db_owner->pw_gid) == -1) {
printf("ERROR: Failed to change owner of %s to %s. Will continue without writing in %s.\n", current_dir, fcConfig->dbOwner, log_file);
ret = -1;
goto cleanup;
if (current_user->pw_uid != db_owner->pw_uid) {

Check failure on line 150 in libfreshclam/libfreshclam.c

View workflow job for this annotation

GitHub Actions / build-windows

left of 'pw_uid' specifies undefined struct/union 'passwd'
if (chown(current_path, db_owner->pw_uid, db_owner->pw_gid) == -1) {

Check failure on line 151 in libfreshclam/libfreshclam.c

View workflow job for this annotation

GitHub Actions / build-windows

left of 'pw_uid' specifies undefined struct/union 'passwd'

Check failure on line 151 in libfreshclam/libfreshclam.c

View workflow job for this annotation

GitHub Actions / build-windows

left of 'pw_gid' specifies undefined struct/union 'passwd'

Check failure

Code scanning / CodeQL

Time-of-check time-of-use filesystem race condition High

The
filename
being operated upon was previously
checked
, but the underlying file may have been changed since then.
printf("ERROR: Failed to change owner of %s to %s. Will continue without writing in %s.\n", current_path, fcConfig->dbOwner, fcConfig->logFile);
ret = -1;
goto cleanup;
}
}
}
strcat(current_dir, "/");
strcat(current_path, PATHSEP);
}
if ((logg_fp = fopen(log_file, "at")) == NULL) {
printf("ERROR: Can't open %s in append mode (check permissions!).\n", log_file);
if ((logg_fp = fopen(fcConfig->logFile, "at")) == NULL) {
printf("ERROR: Can't open %s in append mode (check permissions!).\n", fcConfig->logFile);
ret = -1;
goto cleanup;
}
lchown(log_file, db_owner->pw_uid, db_owner->pw_gid);
lchown(fcConfig->logFile, db_owner->pw_uid, db_owner->pw_gid);

Check failure on line 165 in libfreshclam/libfreshclam.c

View workflow job for this annotation

GitHub Actions / build-windows

left of 'pw_uid' specifies undefined struct/union 'passwd'

Check failure on line 165 in libfreshclam/libfreshclam.c

View workflow job for this annotation

GitHub Actions / build-windows

left of 'pw_gid' specifies undefined struct/union 'passwd'

cleanup:
free(current_dir);
free(current_path);
free(file_path);
if(logg_fp != NULL) {
if (logg_fp != NULL) {
fclose(logg_fp);
}

Expand Down

0 comments on commit 4815aef

Please sign in to comment.