2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 09:57:41 +00:00

iolog_gets: change size parameter to int to match fgets/gzgets

Return an error, setting errno to EINVAL, for negative sizes.
This commit is contained in:
Todd C. Miller 2023-05-05 10:20:21 -06:00
parent c0fa3a4d24
commit 2f4b406809
2 changed files with 6 additions and 6 deletions

View File

@ -119,7 +119,7 @@ bool iolog_mkpath(char *path);
bool iolog_nextid(const 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_open(struct iolog_file *iol, int dfd, int iofd, const char *mode);
bool iolog_write_info_file(int dfd, struct eventlog *evlog); 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); char *iolog_gets(struct iolog_file *iol, char *buf, int bufsize, const char **errsttr);
const char *iolog_fd_to_name(int iofd); const char *iolog_fd_to_name(int iofd);
int iolog_openat(int fdf, const char *path, int flags); int iolog_openat(int fdf, const char *path, int flags);
off_t iolog_seek(struct iolog_file *iol, off_t offset, int whence); off_t iolog_seek(struct iolog_file *iol, off_t offset, int whence);

View File

@ -40,16 +40,16 @@
#include "sudo_iolog.h" #include "sudo_iolog.h"
/* /*
* Like gets() but for struct iolog_file. * Like fgets() but for struct iolog_file.
*/ */
char * char *
iolog_gets(struct iolog_file *iol, char *buf, size_t nbytes, iolog_gets(struct iolog_file *iol, char *buf, int bufsize,
const char **errstr) const char **errstr)
{ {
char *str; char *str;
debug_decl(iolog_gets, SUDO_DEBUG_UTIL); debug_decl(iolog_gets, SUDO_DEBUG_UTIL);
if (nbytes > UINT_MAX) { if (bufsize < 0) {
errno = EINVAL; errno = EINVAL;
if (errstr != NULL) if (errstr != NULL)
*errstr = strerror(errno); *errstr = strerror(errno);
@ -58,7 +58,7 @@ iolog_gets(struct iolog_file *iol, char *buf, size_t nbytes,
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
if (iol->compressed) { if (iol->compressed) {
if ((str = gzgets(iol->fd.g, buf, nbytes)) == NULL) { if ((str = gzgets(iol->fd.g, buf, bufsize)) == NULL) {
if (errstr != NULL) { if (errstr != NULL) {
int errnum; int errnum;
*errstr = gzerror(iol->fd.g, &errnum); *errstr = gzerror(iol->fd.g, &errnum);
@ -69,7 +69,7 @@ iolog_gets(struct iolog_file *iol, char *buf, size_t nbytes,
} else } else
#endif #endif
{ {
if ((str = fgets(buf, nbytes, iol->fd.f)) == NULL) { if ((str = fgets(buf, bufsize, iol->fd.f)) == NULL) {
if (errstr != NULL) if (errstr != NULL)
*errstr = strerror(errno); *errstr = strerror(errno);
} }