Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions conserver/cutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,19 +618,19 @@ FileOpenFD(int fd, enum consFileType type)
#if DEBUG_CONSFILE_IO
{
char buf[1024];
sprintf(buf, "CONSFILE-%s-%lu-%d.w", progname,
snprintf(buf, 1024, "CONSFILE-%s-%lu-%d.w", progname,

@fweimer-rh fweimer-rh Sep 26, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
snprintf(buf, 1024, "CONSFILE-%s-%lu-%d.w", progname,
snprintf(buf, sizeof(buf), "CONSFILE-%s-%lu-%d.w", progname,

But if things are crashing here, we know that buf isn't large enough. Given what is written here (and below), that seems unlikely? Probably something else is going on.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an excellent recommendation. It makes it much cleaner. With respect to what size buf should be, I am open to what is recommended.

(unsigned long)thepid, fd);
if ((cfp->debugwfd =
open(buf, O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) {
sprintf(buf, "[---- STARTED - %s ----]\n",
snprintf(buf, 1024, "[---- STARTED - %s ----]\n",
StrTime((time_t *)0));
write(cfp->debugwfd, buf, strlen(buf));
}
sprintf(buf, "CONSFILE-%s-%lu-%d.r", progname,
snprintf(buf, 1024, "CONSFILE-%s-%lu-%d.r", progname,
(unsigned long)thepid, fd);
if ((cfp->debugrfd =
open(buf, O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) {
sprintf(buf, "[---- STARTED - %s ----]\n",
snprintf(buf, 1024, "[---- STARTED - %s ----]\n",
StrTime((time_t *)0));
write(cfp->debugrfd, buf, strlen(buf));
}
Expand Down Expand Up @@ -663,19 +663,19 @@ FileOpenPipe(int fd, int fdout)
#if DEBUG_CONSFILE_IO
{
char buf[1024];
sprintf(buf, "CONSFILE-%s-%lu-%d.w", progname,
snprintf(buf, 1024, "CONSFILE-%s-%lu-%d.w", progname,
(unsigned long)thepid, fdout);
if ((cfp->debugwfd =
open(buf, O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) {
sprintf(buf, "[---- STARTED - %s ----]\n",
snprintf(buf, 1024, "[---- STARTED - %s ----]\n",
StrTime((time_t *)0));
write(cfp->debugwfd, buf, strlen(buf));
}
sprintf(buf, "CONSFILE-%s-%lu-%d.r", progname,
snprintf(buf, 1024, "CONSFILE-%s-%lu-%d.r", progname,
(unsigned long)thepid, fd);
if ((cfp->debugrfd =
open(buf, O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) {
sprintf(buf, "[---- STARTED - %s ----]\n",
snprintf(buf, 1024, "[---- STARTED - %s ----]\n",
StrTime((time_t *)0));
write(cfp->debugrfd, buf, strlen(buf));
}
Expand Down Expand Up @@ -754,19 +754,19 @@ FileOpen(const char *path, int flag, int mode)
#if DEBUG_CONSFILE_IO
{
char buf[1024];
sprintf(buf, "CONSFILE-%s-%lu-%d.w", progname,
snprintf(buf, 1024, "CONSFILE-%s-%lu-%d.w", progname,
(unsigned long)thepid, fd);
if ((cfp->debugwfd =
open(buf, O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) {
sprintf(buf, "[---- STARTED - %s ----]\n",
snprintf(buf, 1024, "[---- STARTED - %s ----]\n",
StrTime((time_t *)0));
write(cfp->debugwfd, buf, strlen(buf));
}
sprintf(buf, "CONSFILE-%s-%lu-%d.r", progname,
snprintf(buf, 1024, "CONSFILE-%s-%lu-%d.r", progname,
(unsigned long)thepid, fd);
if ((cfp->debugrfd =
open(buf, O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) {
sprintf(buf, "[---- STARTED - %s ----]\n",
snprintf(buf, 1024, "[---- STARTED - %s ----]\n",
StrTime((time_t *)0));
write(cfp->debugrfd, buf, strlen(buf));
}
Expand Down
2 changes: 1 addition & 1 deletion conserver/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ TelOpt(int o)
if (o < sizeof(telopts) / sizeof(char *))
return telopts[o];
else {
sprintf(opt, "%d", o);
snprintf(opt, 128, "%d", o);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
snprintf(opt, 128, "%d", o);
snprintf(opt, sizeof(opt), "%d", o);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I very much agree with what you are doing, this is an excellent recommendation.

return opt;
}
}
Expand Down