Normalize comment style
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2026-10-07 09:09:39 +02:00
parent 8fe9331f42
commit a39fb132f8
29 changed files with 186 additions and 190 deletions

View file

@ -3,7 +3,7 @@
#include "os/portable.h"
#ifdef __MINGW32__ /* Only for MingW */
#ifdef __MINGW32__ /* only for MingW */
#include "os.h"
@ -14,9 +14,9 @@
/****************************************************************************/
/* global */
/* Add missing Windows declaration */
/* add missing Windows declaration */
/* For SetThreadExecutionState */
/* for SetThreadExecutionState */
#ifndef WIN32_ES_SYSTEM_REQUIRED
#define WIN32_ES_SYSTEM_REQUIRED 0x00000001L
#endif
@ -33,7 +33,7 @@
#define WIN32_ES_CONTINUOUS 0x80000000L
#endif
/* For SetSearchPathMode */
/* for SetSearchPathMode */
#ifndef BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE
#define BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE 0x00000001
#endif
@ -41,7 +41,7 @@
#define BASE_SEARCH_PATH_PERMANENT 0x00008000
#endif
/* File Index */
/* file Index */
#undef FILE_INVALID_FILE_ID
#define FILE_INVALID_FILE_ID ((ULONGLONG)-1LL)
#undef FILE_UNSUPPORTED_FILE_ID
@ -571,17 +571,17 @@ static BOOL GetReparseTagInfoByHandle(HANDLE hFile, FILE_ATTRIBUTE_TAG_INFO* lpF
*/
static void windows_attr2stat(DWORD FileAttributes, DWORD ReparseTag, struct windows_stat* st)
{
/* Convert special attributes */
/* convert special attributes */
if ((FileAttributes & FILE_ATTRIBUTE_DEVICE) != 0) {
st->st_mode = S_IFBLK;
st->st_desc = "device";
} else if ((FileAttributes & FILE_ATTRIBUTE_OFFLINE) != 0) { /* Offline */
} else if ((FileAttributes & FILE_ATTRIBUTE_OFFLINE) != 0) { /* offline */
st->st_mode = S_IFCHR;
st->st_desc = "offline";
} else if ((FileAttributes & FILE_ATTRIBUTE_TEMPORARY) != 0) { /* Temporary */
} else if ((FileAttributes & FILE_ATTRIBUTE_TEMPORARY) != 0) { /* temporary */
st->st_mode = S_IFCHR;
st->st_desc = "temporary";
} else if ((FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { /* Reparse point */
} else if ((FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { /* reparse point */
switch (ReparseTag) {
/* if we don't have the ReparseTag information */
case 0 :
@ -622,7 +622,7 @@ static void windows_attr2stat(DWORD FileAttributes, DWORD ReparseTag, struct win
st->st_desc = "reparse-point";
break;
}
} else if ((FileAttributes & FILE_ATTRIBUTE_SYSTEM) != 0) { /* System */
} else if ((FileAttributes & FILE_ATTRIBUTE_SYSTEM) != 0) { /* system */
if ((FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
st->st_mode = S_IFCHR;
st->st_desc = "system-directory";
@ -696,7 +696,7 @@ static int windows_info2stat(const BY_HANDLE_FILE_INFORMATION* info, const FILE_
/* GetFileInformationByHandle() ensures to return synced information */
st->st_sync = 1;
/**
/*
* In ReFS the IDs are 128 bit, and the 64 bit interface may fail.
*
* From Microsoft "Application Compatibility with ReFS"
@ -799,13 +799,13 @@ static void windows_finddata2stat(const WIN32_FIND_DATAW* info, struct windows_s
windows_time2stat(mtime, st);
/* No inode information available */
/* no inode information available */
st->st_ino = INODE_INVALID;
/* No link information available */
/* no link information available */
st->st_nlink = 0;
/* No device information available */
/* no device information available */
st->st_dev = 0;
/* directory listing doesn't ensure to return synced information */
@ -2079,7 +2079,7 @@ int windows_symlink_directory(const char* existing, const char* file)
return windows_symlink_flags(existing, file, SYMBOLIC_LINK_FLAG_DIRECTORY);
}
/* Adds missing definitions in MingW winnt.h */
/* adds missing definitions in MingW winnt.h */
#ifndef FSCTL_GET_REPARSE_POINT
#define FSCTL_GET_REPARSE_POINT 0x000900a8
#endif
@ -2258,7 +2258,7 @@ ssize_t windows_read(int fd, void* buffer, size_t size)
if (!ReadFile(h, buffer, size, &count, 0)) {
DWORD error = GetLastError();
/* A closed Windows pipe has the same read semantics as a POSIX pipe at EOF. */
/* a closed Windows pipe has the same read semantics as a POSIX pipe at EOF. */
if (error == ERROR_BROKEN_PIPE)
return 0;
@ -2982,7 +2982,7 @@ static int fixcat(WCHAR* cmd, int size, int pos, const WCHAR* arg)
return pos;
}
/*
/**
* Append one argument using the Microsoft C runtime command-line
* quoting rules. Use this when building a normal CreateProcessW()
* command line that the target process will parse back into argv[].
@ -3043,7 +3043,7 @@ static int argcat(WCHAR* cmd, int size, int pos, const WCHAR* arg)
return pos;
}
/*
/**
* Append one argument for a batch script invoked through cmd.exe /c.
* Unlike argcat(), this must preserve the argument boundary while
* preventing cmd.exe command metacharacters from changing the command
@ -3369,10 +3369,10 @@ pid_t os_spawn(char** argv, int* stdout_read_int, int* stderr_read_int, const ch
if (!ret)
create_error = GetLastError();
} else {
/* Drop to restricted service account */
/* drop to restricted service account */
HANDLE h_token = NULL;
/* Validate that the requested user is actually a supported Service Account before attempting logon */
/* validate that the requested user is actually a supported Service Account before attempting logon */
if (_stricmp(run_as_user, "LocalService") != 0 && _stricmp(run_as_user, "NetworkService") != 0) {
os_syslog(OS_LVL_INFO, "only supported users are LocalService and NetworkService");
pid_unpublish(pid_slot, 0);
@ -3407,7 +3407,7 @@ pid_t os_spawn(char** argv, int* stdout_read_int, int* stderr_read_int, const ch
return -1;
}
/* Create an environment block to ensure PATH is loaded */
/* create an environment block to ensure PATH is loaded */
LPVOID env = NULL;
if (!CreateEnvironmentBlock(&env, h_token, FALSE)) {
windows_errno(GetLastError());
@ -4385,7 +4385,7 @@ OS_FILE* os_popen(const char** argv)
fail_child:
saved_errno = errno;
close(stdout_fd);
/* Terminate and reap the child immediately so no process or handle is leaked on stream creation failure. */
/* terminate and reap the child immediately so no process or handle is leaked on stream creation failure. */
pid_kill(pid);
status = 0;
os_wait(pid, &status, 0);
@ -4409,15 +4409,15 @@ int os_pclose(OS_FILE* stream)
int close_ret;
pid_t wait_ret;
/* Keep the owned resources locally so the OS_FILE container can be released immediately. */
/* keep the owned resources locally so the OS_FILE container can be released immediately. */
free(stream);
/* Closing the stream also closes the CRT descriptor and the underlying stdout pipe handle. */
/* closing the stream also closes the CRT descriptor and the underlying stdout pipe handle. */
close_ret = fclose(fp);
if (close_ret != 0)
saved_errno = errno;
/* Always reap the child even if closing the stream failed. */
/* always reap the child even if closing the stream failed. */
wait_ret = os_wait(pid, &status, 0);
if (wait_ret < 0 && saved_errno == 0)
saved_errno = errno;

View file

@ -4,7 +4,7 @@
#ifndef __PORTABLE_MINGW_H
#define __PORTABLE_MINGW_H
#ifdef __MINGW32__ /* Only for MingW */
#ifdef __MINGW32__ /* only for MingW */
#include <wchar.h>
@ -98,7 +98,7 @@ wchar_t* u8tou16_mayfail(wchar_t* conv_buf, size_t number_of_wchar, const char*
#undef PATH_MAX
#define PATH_MAX 1024
/* Remap functions and types */
/* remap functions and types */
#undef fopen
#define fopen windows_fopen
#define FOPEN_TEXT "t"
@ -167,11 +167,11 @@ wchar_t* u8tou16_mayfail(wchar_t* conv_buf, size_t number_of_wchar, const char*
#undef sleep
#define sleep windows_sleep
/* 4==DIR, 5,6,7=free, 8==REG */
#define S_IFLNK 0x5000 /* Symbolic link to file */
#define S_IFLNK 0x5000 /* symbolic link to file */
#define S_ISLNK(m) (((m) & _S_IFMT) == S_IFLNK)
#define S_IFLNKDIR 0x6000 /* Symbolic link to directory */
#define S_IFLNKDIR 0x6000 /* symbolic link to directory */
#define S_ISLNKDIR(m) (((m) & _S_IFMT) == S_IFLNKDIR)
#define S_IFJUN 0x7000 /* Junction */
#define S_IFJUN 0x7000 /* junction */
#define S_ISJUN(m) (((m) & _S_IFMT) == S_IFJUN)
#undef readlink
#define readlink windows_readlink
@ -210,7 +210,7 @@ wchar_t* u8tou16_mayfail(wchar_t* conv_buf, size_t number_of_wchar, const char*
*/
#define STAT_NSEC_INVALID -1
/* We have nano second support */
/* we have nano second support */
#define STAT_NSEC(st) ((int)(st)->st_mtimensec)
static inline int WEXITSTATUS(DWORD status)

View file

@ -5,11 +5,11 @@
#define __PORTABLE_H
#if HAVE_CONFIG_H
#include "config.h" /* Use " to include first in the same directory of this file */
#include "config.h" /* use " to include first in the same directory of this file */
#endif
/***************************************************************************/
/* Config */
/* config */
#ifdef __MINGW32__
/**
@ -163,7 +163,7 @@
* Includes some standard headers.
*/
#include <stdio.h>
#include <stdlib.h> /* On many systems (e.g., Darwin), `stdio.h' is a prerequisite. */
#include <stdlib.h> /* on many systems (e.g., Darwin), `stdio.h' is a prerequisite. */
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
@ -299,7 +299,7 @@
#include <linux/close_range.h>
#endif
/*
/**
* Flags for open()
*/
#ifndef O_PATH

View file

@ -3,7 +3,7 @@
#include "os/portable.h"
#ifndef __MINGW32__ /* Only for Unix */
#ifndef __MINGW32__ /* only for Unix */
#include "os.h"
@ -353,7 +353,7 @@ int filephy(const char* path, uint64_t size, uint64_t* physical)
/****************************************************************************/
/* exec */
/*
/**
* Scrubbed environment
* Only provide the bare essentials.
*/
@ -369,7 +369,7 @@ static char* const envp_scrubbed[] = {
NULL
};
/*
/**
* Enforce a strict 128-byte shebang limit to match the actual Linux kernel behavior
* and prevent security risks from truncation.
*
@ -560,7 +560,7 @@ static int verify_shebang_interpreter(int fd, const char* script_path)
return 0;
}
/*
/**
* Securely verify and open an executable file.
*
* Performs a series of security checks on the file at @exec_path before
@ -940,7 +940,7 @@ static int pid_kill(pid_t pid)
return -1;
}
/* Send SIGKILL signal to the negative PID to target the entire Process Group */
/* send SIGKILL signal to the negative PID to target the entire Process Group */
int ret = kill(-pid, SIGKILL);
/*
@ -1219,7 +1219,7 @@ int os_script(char** argv, char** envp, const char* run_as_user, uint64_t timeou
os_user_drop_privileges(&user);
#if defined(__linux__) && defined(PR_SET_PDEATHSIG)
/* Send SIGKILL to child if parent daemon dies unexpectedly */
/* send SIGKILL to child if parent daemon dies unexpectedly */
prctl(PR_SET_PDEATHSIG, SIGKILL);
/* exit if parent died before prctl to avoid becoming orphaned */
if (getppid() != ppid) {
@ -1432,13 +1432,13 @@ int os_command(const char* command, const char* run_as_user, const char* stdin_t
setpgid(0, 0);
if (pipe_fds[1] != -1)
close(pipe_fds[1]); /* Close unused write end */
close(pipe_fds[1]); /* close unused write end */
/* drop privileges first (if configured) */
os_user_drop_privileges(&user);
#if defined(__linux__) && defined(PR_SET_PDEATHSIG)
/* Send SIGKILL to child if parent daemon dies unexpectedly */
/* send SIGKILL to child if parent daemon dies unexpectedly */
prctl(PR_SET_PDEATHSIG, SIGKILL);
/* exit if parent died before prctl to avoid becoming orphaned */
if (getppid() != ppid) {
@ -1461,7 +1461,7 @@ int os_command(const char* command, const char* run_as_user, const char* stdin_t
_exit(126);
}
/* Redirect STDOUT and STDERR to /dev/null */
/* redirect STDOUT and STDERR to /dev/null */
if (dup2(null_fd, STDOUT_FILENO) == -1
|| dup2(null_fd, STDERR_FILENO) == -1)
_exit(126);
@ -1657,7 +1657,7 @@ pid_t os_spawn(char** argv, int* stdout_read_fd, int* stderr_read_fd, const char
os_user_drop_privileges(&user);
#if defined(__linux__) && defined(PR_SET_PDEATHSIG)
/* Send SIGKILL to child if parent daemon dies unexpectedly */
/* send SIGKILL to child if parent daemon dies unexpectedly */
prctl(PR_SET_PDEATHSIG, SIGKILL);
/* exit if parent died before prctl to avoid becoming orphaned */
if (getppid() != ppid) {
@ -2164,7 +2164,7 @@ void os_privileges_release(void)
}
}
/* Drop UID last. */
/* drop UID last. */
if (uid_dropped) {
if (syscall(SYS_setresuid, (uid_t)-1, (uid_t)unpriv_uid, (uid_t)-1) != 0) {
if (errno == EPERM) {
@ -2198,7 +2198,7 @@ void os_privileges_release(void)
}
}
/* Drop UID last. */
/* drop UID last. */
if (uid_dropped) {
if (seteuid(unpriv_uid) != 0) {
if (errno == EPERM) {

View file

@ -67,7 +67,7 @@ static inline int close_range_impl(unsigned int first, unsigned int last, unsign
*/
#define STAT_NSEC_INVALID -1
/* Check if we have nanoseconds support */
/* check if we have nanoseconds support */
#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
#define STAT_NSEC(st) ((int)(st)->st_mtim.tv_nsec) /* Linux */
#elif HAVE_STRUCT_STAT_ST_MTIMENSEC