Make gl_pathc, gl_matchc and gl_offs size_t in glob_t to match POSIX.
This commit is contained in:
@@ -39,9 +39,9 @@
|
|||||||
|
|
||||||
struct stat;
|
struct stat;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int gl_pathc; /* Count of total paths so far. */
|
size_t gl_pathc; /* Count of total paths so far. */
|
||||||
int gl_matchc; /* Count of paths matching pattern. */
|
size_t gl_matchc; /* Count of paths matching pattern. */
|
||||||
int gl_offs; /* Reserved at beginning of gl_pathv. */
|
size_t gl_offs; /* Reserved at beginning of gl_pathv. */
|
||||||
int gl_flags; /* Copy of flags parameter to glob. */
|
int gl_flags; /* Copy of flags parameter to glob. */
|
||||||
char **gl_pathv; /* List of paths matching pattern. */
|
char **gl_pathv; /* List of paths matching pattern. */
|
||||||
/* Copy of errfunc parameter to glob. */
|
/* Copy of errfunc parameter to glob. */
|
||||||
|
@@ -144,7 +144,7 @@ struct glob_lim {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int compare(const void *, const void *);
|
static int compare(const void *, const void *);
|
||||||
static int g_Ctoc(const Char *, char *, unsigned int);
|
static int g_Ctoc(const Char *, char *, size_t);
|
||||||
static int g_lstat(Char *, struct stat *, glob_t *);
|
static int g_lstat(Char *, struct stat *, glob_t *);
|
||||||
static DIR *g_opendir(Char *, glob_t *);
|
static DIR *g_opendir(Char *, glob_t *);
|
||||||
static Char *g_strchr(const Char *, int);
|
static Char *g_strchr(const Char *, int);
|
||||||
@@ -188,9 +188,8 @@ sudo_glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
|
|||||||
pglob->gl_errfunc = errfunc;
|
pglob->gl_errfunc = errfunc;
|
||||||
pglob->gl_matchc = 0;
|
pglob->gl_matchc = 0;
|
||||||
|
|
||||||
if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 ||
|
if (pglob->gl_offs >= SSIZE_MAX || pglob->gl_pathc >= SSIZE_MAX ||
|
||||||
pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX ||
|
pglob->gl_pathc >= SSIZE_MAX - pglob->gl_offs - 1)
|
||||||
pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1)
|
|
||||||
return GLOB_NOSPACE;
|
return GLOB_NOSPACE;
|
||||||
|
|
||||||
if (strnlen(pattern, PATH_MAX) == PATH_MAX)
|
if (strnlen(pattern, PATH_MAX) == PATH_MAX)
|
||||||
@@ -457,7 +456,8 @@ static int
|
|||||||
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
|
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
|
||||||
{
|
{
|
||||||
const Char *qpatnext;
|
const Char *qpatnext;
|
||||||
int c, err, oldpathc;
|
int c, err;
|
||||||
|
size_t oldpathc;
|
||||||
Char *bufnext, patbuf[PATH_MAX];
|
Char *bufnext, patbuf[PATH_MAX];
|
||||||
|
|
||||||
qpatnext = globtilde(pattern, patbuf, PATH_MAX, pglob);
|
qpatnext = globtilde(pattern, patbuf, PATH_MAX, pglob);
|
||||||
@@ -731,18 +731,17 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
|
|||||||
struct stat *sb)
|
struct stat *sb)
|
||||||
{
|
{
|
||||||
char **pathv;
|
char **pathv;
|
||||||
ssize_t i;
|
size_t i, newn, len;
|
||||||
size_t newn, len;
|
|
||||||
char *copy = NULL;
|
char *copy = NULL;
|
||||||
const Char *p;
|
const Char *p;
|
||||||
|
|
||||||
newn = 2 + pglob->gl_pathc + pglob->gl_offs;
|
newn = 2 + pglob->gl_pathc + pglob->gl_offs;
|
||||||
if (pglob->gl_offs >= INT_MAX ||
|
if (pglob->gl_offs >= SSIZE_MAX ||
|
||||||
pglob->gl_pathc >= INT_MAX ||
|
pglob->gl_pathc >= SSIZE_MAX ||
|
||||||
newn >= INT_MAX ||
|
newn >= SSIZE_MAX ||
|
||||||
SIZE_MAX / sizeof(*pathv) <= newn) {
|
SIZE_MAX / sizeof(*pathv) <= newn) {
|
||||||
nospace:
|
nospace:
|
||||||
for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) {
|
for (i = pglob->gl_offs; i < newn - 2; i++) {
|
||||||
if (pglob->gl_pathv && pglob->gl_pathv[i])
|
if (pglob->gl_pathv && pglob->gl_pathv[i])
|
||||||
free(pglob->gl_pathv[i]);
|
free(pglob->gl_pathv[i]);
|
||||||
}
|
}
|
||||||
@@ -759,7 +758,7 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
|
|||||||
if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
|
if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
|
||||||
/* first time around -- clear initial gl_offs items */
|
/* first time around -- clear initial gl_offs items */
|
||||||
pathv += pglob->gl_offs;
|
pathv += pglob->gl_offs;
|
||||||
for (i = pglob->gl_offs; --i >= 0; )
|
for (i = pglob->gl_offs; i > 0; i--)
|
||||||
*--pathv = NULL;
|
*--pathv = NULL;
|
||||||
}
|
}
|
||||||
pglob->gl_pathv = pathv;
|
pglob->gl_pathv = pathv;
|
||||||
@@ -869,7 +868,7 @@ fail:
|
|||||||
void
|
void
|
||||||
sudo_globfree(glob_t *pglob)
|
sudo_globfree(glob_t *pglob)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
char **pp;
|
char **pp;
|
||||||
|
|
||||||
if (pglob->gl_pathv != NULL) {
|
if (pglob->gl_pathv != NULL) {
|
||||||
@@ -929,7 +928,7 @@ g_strchr(const Char *str, int ch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
g_Ctoc(const Char *str, char *buf, unsigned int len)
|
g_Ctoc(const Char *str, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
|
|
||||||
while (len--) {
|
while (len--) {
|
||||||
|
Reference in New Issue
Block a user