Skip to content

Commit

Permalink
Various: use NUT_PATH_MAX instead of SMALLBUF for file/sock/pipe names [
Browse files Browse the repository at this point in the history
#2764]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jan 18, 2025
1 parent e2b2140 commit 8979560
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion clients/cgilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static void cgilib_err(const char *errmsg)

int checkhost(const char *host, char **desc)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
PCONF_CTX_t ctx;

if (!host)
Expand Down
2 changes: 1 addition & 1 deletion clients/upssched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ static void upssched_err(const char *errmsg)

static void checkconf(void)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
PCONF_CTX_t ctx;
int numerrors = 0;

Expand Down
4 changes: 2 additions & 2 deletions clients/upsset.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void upsset_hosts_err(const char *errmsg)
/* this defaults to wherever we are now, ups and function-wise */
static void do_pickups(const char *currfunc)
{
char hostfn[SMALLBUF];
char hostfn[NUT_PATH_MAX];
PCONF_CTX_t ctx;

snprintf(hostfn, sizeof(hostfn), "%s/hosts.conf", confpath());
Expand Down Expand Up @@ -1020,7 +1020,7 @@ static void upsset_conf_err(const char *errmsg)
/* see if the user has confirmed their cgi directory's secure state */
static void check_conf(void)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
PCONF_CTX_t ctx;

snprintf(fn, sizeof(fn), "%s/upsset.conf", confpath());
Expand Down
4 changes: 2 additions & 2 deletions clients/upsstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ static void parse_line(const char *buf)

static void display_template(const char *tfn)
{
char fn[SMALLBUF], buf[LARGEBUF];
char fn[NUT_PATH_MAX], buf[LARGEBUF];

snprintf(fn, sizeof(fn), "%s/%s", confpath(), tfn);

Expand Down Expand Up @@ -965,7 +965,7 @@ static void upsstats_hosts_err(const char *errmsg)

static void load_hosts_conf(void)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
PCONF_CTX_t ctx;

snprintf(fn, sizeof(fn), "%s/hosts.conf", CONFPATH);
Expand Down
8 changes: 4 additions & 4 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ int snprintfcat(char *dst, size_t size, const char *fmt, ...)
#ifndef WIN32
int sendsignal(const char *progname, int sig, int check_current_progname)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];

snprintf(fn, sizeof(fn), "%s/%s.pid", rootpidpath(), progname);

Expand Down Expand Up @@ -3880,12 +3880,12 @@ static char * get_libname_in_dir(const char* base_libname, size_t base_libname_l
DIR *dp;
struct dirent *dirp;
char *libname_path = NULL, *libname_alias = NULL;
char current_test_path[LARGEBUF];
char current_test_path[NUT_PATH_MAX];

upsdebugx(3, "%s('%s', %" PRIuSIZE ", '%s', %i): Entering method...",
__func__, base_libname, base_libname_length, dirname, index);

memset(current_test_path, 0, LARGEBUF);
memset(current_test_path, 0, sizeof(current_test_path));

if ((dp = opendir(dirname)) == NULL) {
if (index >= 0) {
Expand Down Expand Up @@ -3928,7 +3928,7 @@ static char * get_libname_in_dir(const char* base_libname, size_t base_libname_l
continue;
}

snprintf(current_test_path, LARGEBUF, "%s/%s", dirname, dirp->d_name);
snprintf(current_test_path, sizeof(current_test_path), "%s/%s", dirname, dirp->d_name);
#if HAVE_DECL_REALPATH
libname_path = realpath(current_test_path, NULL);
#else
Expand Down
2 changes: 1 addition & 1 deletion common/upsconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void upsconf_err(const char *errmsg)
*/
int read_upsconf(int fatal_errors)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
PCONF_CTX_t ctx;

ups_section = NULL;
Expand Down
6 changes: 3 additions & 3 deletions common/wincompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,11 @@ static const char *named_pipe_name=NULL;
void pipe_create(const char * pipe_name)
{
BOOL ret;
char pipe_full_name[SMALLBUF];
char pipe_full_name[NUT_PATH_MAX];

/* save pipe name for further use in pipe_connect */
if( pipe_name == NULL ) {
if( named_pipe_name == NULL ) {
if (pipe_name == NULL) {
if (named_pipe_name == NULL) {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/clone-outlet.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static TYPE_FD sstate_connect(void)

/* continued below... */
#else /* WIN32 */
char pipename[SMALLBUF];
char pipename[NUT_PATH_MAX];
BOOL result = FALSE;

snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\%s/%s", dflt_statepath(), device_path);
Expand Down
2 changes: 1 addition & 1 deletion drivers/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static TYPE_FD sstate_connect(void)

/* continued below... */
#else /* WIN32 */
char pipename[SMALLBUF];
char pipename[NUT_PATH_MAX];
BOOL result = FALSE;

snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\%s/%s", dflt_statepath(), device_path);
Expand Down
2 changes: 1 addition & 1 deletion drivers/dstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ static void sock_close(void)

char * dstate_init(const char *prog, const char *devname)
{
char sockname[SMALLBUF];
char sockname[NUT_PATH_MAX];

#ifndef WIN32
/* do this here for now */
Expand Down
6 changes: 3 additions & 3 deletions drivers/dummy-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void upsdrv_updateinfo(void)
/* less stress on the sys */
if (ctx == NULL && next_update == -1) {
struct stat fs;
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];

prepare_filepath(fn, sizeof(fn));

Expand Down Expand Up @@ -446,7 +446,7 @@ void upsdrv_initups(void)
}
else
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
mode = MODE_NONE;

if (val) {
Expand Down Expand Up @@ -747,7 +747,7 @@ static void upsconf_err(const char *errmsg)
*/
static int parse_data_file(TYPE_FD arg_upsfd)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
char *ptr, var_value[MAX_STRING_SIZE];
size_t value_args = 0, counter;
time_t now;
Expand Down
6 changes: 3 additions & 3 deletions drivers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ int main(int argc, char **argv)

const char * drv_name = NULL;
char * dot = NULL;
char name[SMALLBUF];
char name[NUT_PATH_MAX];
#endif

const char optstring[] = "+a:s:kDFBd:hx:Lqr:u:g:Vi:c:"
Expand Down Expand Up @@ -2595,7 +2595,7 @@ int main(int argc, char **argv)
* deliberately.
*/
if (cmd || foreground == 0 || foreground == 2 || do_forceshutdown) {
char pidfnbuf[SMALLBUF];
char pidfnbuf[NUT_PATH_MAX];

snprintf(pidfnbuf, sizeof(pidfnbuf), "%s/%s-%s.pid", altpidpath(), progname, upsname);

Expand Down Expand Up @@ -3002,7 +3002,7 @@ int main(int argc, char **argv)
*/
case 2:
if (!pidfn) {
char pidfnbuf[SMALLBUF];
char pidfnbuf[NUT_PATH_MAX];
snprintf(pidfnbuf, sizeof(pidfnbuf), "%s/%s-%s.pid", altpidpath(), progname, upsname);
pidfn = xstrdup(pidfnbuf);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/snmp-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -4181,7 +4181,7 @@ static void mibconf_err(const char *errmsg)
/* load *mib.conf into an snmp_info_t structure */
void read_mibconf(char *mib)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
PCONF_CTX_t ctx;
int numerrors = 0;

Expand Down
10 changes: 5 additions & 5 deletions drivers/upsdrvctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void signal_driver_cmd(const ups_t *ups,
/* TODO: implement WIN32: https://github.com/networkupstools/nut/issues/1916
* Currently the codepath is not implemented below
*/
char pidfn[SMALLBUF];
char pidfn[NUT_PATH_MAX];
#endif
int ret;

Expand Down Expand Up @@ -338,7 +338,7 @@ static void signal_driver(const ups_t *ups) {
/* handle sending the signal */
static void stop_driver(const ups_t *ups)
{
char pidfn[SMALLBUF];
char pidfn[NUT_PATH_MAX];
int ret, i;

upsdebugx(1, "Stopping UPS: %s", ups->upsname);
Expand Down Expand Up @@ -819,7 +819,7 @@ static void status_driver(const ups_t *ups)
*/
static int headerShown = 0;
#ifndef WIN32
char pidfn[SMALLBUF];
char pidfn[NUT_PATH_MAX];
int cmdret = -1;
#endif
char bufPid[LARGEBUF], *pidStrFromSocket = NULL,
Expand Down Expand Up @@ -1023,7 +1023,7 @@ static void status_driver(const ups_t *ups)
static void start_driver(const ups_t *ups)
{
char *argv[10];
char dfn[SMALLBUF], dbg[SMALLBUF];
char dfn[NUT_PATH_MAX], dbg[SMALLBUF];
int ret, arg = 0;
int initial_exec_error = exec_error, initial_exec_timeout = exec_timeout, drv_maxretry = maxretry;
struct stat fs;
Expand Down Expand Up @@ -1248,7 +1248,7 @@ static void help(const char *arg_progname)
static void shutdown_driver(const ups_t *ups)
{
char *argv[9];
char dfn[SMALLBUF];
char dfn[NUT_PATH_MAX];
int arg = 0;

upsdebugx(1, "Shutdown UPS: %s", ups->upsname);
Expand Down
2 changes: 1 addition & 1 deletion drivers/upsdrvquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ udq_pipe_conn_t *upsdrvquery_connect(const char *sockfn) {
}

udq_pipe_conn_t *upsdrvquery_connect_drvname_upsname(const char *drvname, const char *upsname) {
char sockname[SMALLBUF];
char sockname[NUT_PATH_MAX];
#ifndef WIN32
struct stat fs;
snprintf(sockname, sizeof(sockname), "%s/%s-%s",
Expand Down
2 changes: 1 addition & 1 deletion drivers/upsdrvquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef struct udq_pipe_conn_s {
int newread; /* Set to 1 to start a new ReadFile, forget old buf */
#endif /* WIN32 */
char buf[LARGEBUF];
char sockfn[LARGEBUF];
char sockfn[NUT_PATH_MAX];
} udq_pipe_conn_t;

udq_pipe_conn_t *upsdrvquery_connect(const char *sockfn);
Expand Down
4 changes: 2 additions & 2 deletions scripts/Windows/wininit.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ static DWORD shutdown_ups(void)
/* return 0 on failure */
static int parse_nutconf(BOOL start_flag)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
FILE *nutf;
char buf[SMALLBUF];
char fullname[SMALLBUF];
char fullname[NUT_PATH_MAX];

snprintf(fn, sizeof(fn), "%s/nut.conf", confpath());

Expand Down
6 changes: 3 additions & 3 deletions server/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static void upsd_conf_err(const char *errmsg)

void load_upsdconf(int reloading)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
PCONF_CTX_t ctx;
int numerrors = 0;

Expand Down Expand Up @@ -497,7 +497,7 @@ void do_upsconf_args(char *upsname, char *var, char *val)
void upsconf_add(int reloading)
{
ups_t *tmp = upstable, *next;
char statefn[SMALLBUF];
char statefn[NUT_PATH_MAX];

if (!tmp) {
upslogx(LOG_WARNING, "Warning: no UPS definitions in ups.conf");
Expand Down Expand Up @@ -599,7 +599,7 @@ static void delete_ups(upstype_t *target)
/* see if we can open a file */
static int check_file(const char *fn)
{
char chkfn[SMALLBUF];
char chkfn[NUT_PATH_MAX];
FILE *f;

snprintf(chkfn, sizeof(chkfn), "%s/%s", confpath(), fn);
Expand Down
2 changes: 1 addition & 1 deletion server/desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void desc_file_err(const char *errmsg)

void desc_load(void)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
PCONF_CTX_t ctx;

snprintf(fn, sizeof(fn), "%s/cmdvartab", datapath);
Expand Down
2 changes: 1 addition & 1 deletion server/pipedebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void pipe_arg(int numarg, char **arg)
static HANDLE pipe_connect(const char *pipefn)
{
HANDLE fd;
char pipename[SMALLBUF];
char pipename[NUT_PATH_MAX];
BOOL result = FALSE;

snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\%s", pipefn);
Expand Down
2 changes: 1 addition & 1 deletion server/sstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ TYPE_FD sstate_connect(upstype_t *ups)
}

#else
char pipename[SMALLBUF];
char pipename[NUT_PATH_MAX];
const char *dumpcmd = "DUMPALL\n";
BOOL result = FALSE;
DWORD bytesWritten;
Expand Down
2 changes: 1 addition & 1 deletion server/upsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static HANDLE mutex = INVALID_HANDLE_VALUE;
static handler_t *handler = NULL;

/* pid file */
static char pidfn[SMALLBUF];
static char pidfn[NUT_PATH_MAX];

/* set by signal handlers */
static int reload_flag = 0, exit_flag = 0;
Expand Down
2 changes: 1 addition & 1 deletion server/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ static void upsd_user_err(const char *errmsg)

void user_load(void)
{
char fn[SMALLBUF];
char fn[NUT_PATH_MAX];
PCONF_CTX_t ctx;

curr_user = NULL;
Expand Down

0 comments on commit 8979560

Please sign in to comment.