Fix age_old_log() after r337468.

We can no longer use sizeof() to get the path buffer's size.  Apply
a straightforward fix for now with the aim of MFCing soon.

PR:		233633
Submitted by:	Katsuyuki Miyoshi <katsu@miyoshi.matsuyama.ehime.jp>
MFC after:	3 days
This commit is contained in:
Mark Johnston 2018-11-29 16:49:56 +00:00
parent e31fc3ab13
commit c2c3992b39

View File

@ -2426,6 +2426,7 @@ age_old_log(const char *file)
const char *logfile_suffix; const char *logfile_suffix;
static unsigned int suffix_maxlen = 0; static unsigned int suffix_maxlen = 0;
char *tmp; char *tmp;
size_t tmpsiz;
time_t mtime; time_t mtime;
int c; int c;
@ -2435,33 +2436,34 @@ age_old_log(const char *file)
strlen(compress_type[c].suffix)); strlen(compress_type[c].suffix));
} }
tmp = alloca(MAXPATHLEN + sizeof(".0") + suffix_maxlen + 1); tmpsiz = MAXPATHLEN + sizeof(".0") + suffix_maxlen + 1;
tmp = alloca(tmpsiz);
if (archtodir) { if (archtodir) {
char *p; char *p;
/* build name of archive directory into tmp */ /* build name of archive directory into tmp */
if (*archdirname == '/') { /* absolute */ if (*archdirname == '/') { /* absolute */
strlcpy(tmp, archdirname, sizeof(tmp)); strlcpy(tmp, archdirname, tmpsiz);
} else { /* relative */ } else { /* relative */
/* get directory part of logfile */ /* get directory part of logfile */
strlcpy(tmp, file, sizeof(tmp)); strlcpy(tmp, file, tmpsiz);
if ((p = strrchr(tmp, '/')) == NULL) if ((p = strrchr(tmp, '/')) == NULL)
tmp[0] = '\0'; tmp[0] = '\0';
else else
*(p + 1) = '\0'; *(p + 1) = '\0';
strlcat(tmp, archdirname, sizeof(tmp)); strlcat(tmp, archdirname, tmpsiz);
} }
strlcat(tmp, "/", sizeof(tmp)); strlcat(tmp, "/", tmpsiz);
/* get filename part of logfile */ /* get filename part of logfile */
if ((p = strrchr(file, '/')) == NULL) if ((p = strrchr(file, '/')) == NULL)
strlcat(tmp, file, sizeof(tmp)); strlcat(tmp, file, tmpsiz);
else else
strlcat(tmp, p + 1, sizeof(tmp)); strlcat(tmp, p + 1, tmpsiz);
} else { } else {
(void) strlcpy(tmp, file, sizeof(tmp)); (void) strlcpy(tmp, file, tmpsiz);
} }
if (timefnamefmt != NULL) { if (timefnamefmt != NULL) {
@ -2469,11 +2471,11 @@ age_old_log(const char *file)
if (mtime == -1) if (mtime == -1)
return (-1); return (-1);
} else { } else {
strlcat(tmp, ".0", sizeof(tmp)); strlcat(tmp, ".0", tmpsiz);
logfile_suffix = get_logfile_suffix(tmp); logfile_suffix = get_logfile_suffix(tmp);
if (logfile_suffix == NULL) if (logfile_suffix == NULL)
return (-1); return (-1);
(void) strlcat(tmp, logfile_suffix, sizeof(tmp)); (void) strlcat(tmp, logfile_suffix, tmpsiz);
if (stat(tmp, &sb) < 0) if (stat(tmp, &sb) < 0)
return (-1); return (-1);
mtime = sb.st_mtime; mtime = sb.st_mtime;