2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 01:49:11 +00:00

iolog_nextid(): make iolog_dir argument const.

We make a copy of the directory so there's no real reason that
parameter can't be const.
This commit is contained in:
Todd C. Miller 2021-09-21 19:09:21 -06:00
parent 0f2252f898
commit 23d04dde24
2 changed files with 14 additions and 6 deletions

View File

@ -111,7 +111,7 @@ bool iolog_close(struct iolog_file *iol, const char **errstr);
bool iolog_eof(struct iolog_file *iol);
bool iolog_mkdtemp(char *path);
bool iolog_mkpath(char *path);
bool iolog_nextid(char *iolog_dir, char sessid[7]);
bool iolog_nextid(const char *iolog_dir, char sessid[7]);
bool iolog_open(struct iolog_file *iol, int dfd, int iofd, const char *mode);
bool iolog_write_info_file(int dfd, struct eventlog *evlog);
char *iolog_gets(struct iolog_file *iol, char *buf, size_t nbytes, const char **errsttr);

View File

@ -50,11 +50,12 @@
* Uses file locking to avoid sequence number collisions.
*/
bool
iolog_nextid(char *iolog_dir, char sessid[7])
iolog_nextid(const char *iolog_dir, char sessid[7])
{
char buf[32], *ep;
int i, len, fd = -1;
int i, fd = -1;
unsigned long id = 0;
size_t len;
ssize_t nread;
bool ret = false;
char pathbuf[PATH_MAX];
@ -66,14 +67,21 @@ iolog_nextid(char *iolog_dir, char sessid[7])
/*
* Create I/O log directory if it doesn't already exist.
*/
if (!iolog_mkdirs(iolog_dir))
len = strlcpy(pathbuf, iolog_dir, sizeof(pathbuf));
if (len >= sizeof(pathbuf)) {
errno = ENAMETOOLONG;
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
"%s: %s", __func__, iolog_dir);
goto done;
}
if (!iolog_mkdirs(pathbuf))
goto done;
/*
* Open sequence file
*/
len = snprintf(pathbuf, sizeof(pathbuf), "%s/seq", iolog_dir);
if (len < 0 || len >= ssizeof(pathbuf)) {
len = strlcat(pathbuf, "/seq", sizeof(pathbuf));
if (len >= sizeof(pathbuf)) {
errno = ENAMETOOLONG;
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
"%s: %s/seq", __func__, iolog_dir);