]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream commit
authorDamien Miller <djm@mindrot.org>
Fri, 15 Nov 2019 05:06:30 +0000 (16:06 +1100)
committerDamien Miller <djm@mindrot.org>
Fri, 15 Nov 2019 05:06:30 +0000 (16:06 +1100)
revision 1.48
date: 2019/02/04 16:45:40;  author: millert;  state: Exp;  lines: +16 -17;  commitid: cpNtVC7erojNyctw;
Make gl_pathc, gl_matchc and gl_offs size_t in glob_t to match POSIX.
This requires a libc major version bump.  OK deraadt@

openbsd-compat/glob.c
openbsd-compat/glob.h

index 27710b4d62d2f0f03fd4cc68e052b8cfd75cd958..1e346a8f66791162752a9fc6ac8a52274f4b69dd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: glob.c,v 1.47 2017/05/08 14:53:27 millert Exp $ */
+/*     $OpenBSD: glob.c,v 1.48 2019/02/04 16:45:40 millert Exp $ */
 /*
  * Copyright (c) 1989, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -150,7 +150,7 @@ struct glob_path_stat {
 
 static int      compare(const void *, const void *);
 static int      compare_gps(const void *, const void *);
-static int      g_Ctoc(const Char *, char *, u_int);
+static int      g_Ctoc(const Char *, char *, size_t);
 static int      g_lstat(Char *, struct stat *, glob_t *);
 static DIR     *g_opendir(Char *, glob_t *);
 static Char    *g_strchr(const Char *, int);
@@ -198,9 +198,8 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
        if (strnlen(pattern, PATH_MAX) == PATH_MAX)
                return(GLOB_NOMATCH);
 
-       if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 ||
-           pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX ||
-           pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1)
+       if (pglob->gl_offs >= SSIZE_MAX || pglob->gl_pathc >= SSIZE_MAX ||
+           pglob->gl_pathc >= SSIZE_MAX - pglob->gl_offs - 1)
                return GLOB_NOSPACE;
 
        bufnext = patbuf;
@@ -472,7 +471,8 @@ static int
 glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
 {
        const Char *qpatnext;
-       int c, err, oldpathc;
+       int c, err;
+       size_t oldpathc;
        Char *bufnext, patbuf[PATH_MAX];
 
        qpatnext = globtilde(pattern, patbuf, PATH_MAX, pglob);
@@ -566,9 +566,9 @@ glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
                if ((pglob->gl_flags & GLOB_KEEPSTAT)) {
                        /* Keep the paths and stat info synced during sort */
                        struct glob_path_stat *path_stat;
-                       int i;
-                       int n = pglob->gl_pathc - oldpathc;
-                       int o = pglob->gl_offs + oldpathc;
+                       size_t i;
+                       size_t n = pglob->gl_pathc - oldpathc;
+                       size_t o = pglob->gl_offs + oldpathc;
 
                        if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL)
                                return GLOB_NOSPACE;
@@ -797,20 +797,19 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
     struct stat *sb)
 {
        char **pathv;
-       ssize_t i;
-       size_t newn, len;
+       size_t i, newn, len;
        char *copy = NULL;
        const Char *p;
        struct stat **statv;
 
        newn = 2 + pglob->gl_pathc + pglob->gl_offs;
-       if (pglob->gl_offs >= INT_MAX ||
-           pglob->gl_pathc >= INT_MAX ||
-           newn >= INT_MAX ||
+       if (pglob->gl_offs >= SSIZE_MAX ||
+           pglob->gl_pathc >= SSIZE_MAX ||
+           newn >= SSIZE_MAX ||
            SIZE_MAX / sizeof(*pathv) <= newn ||
            SIZE_MAX / sizeof(*statv) <= newn) {
  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])
                                free(pglob->gl_pathv[i]);
                        if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 &&
@@ -971,7 +970,7 @@ fail:
 void
 globfree(glob_t *pglob)
 {
-       int i;
+       size_t i;
        char **pp;
 
        if (pglob->gl_pathv != NULL) {
@@ -1043,7 +1042,7 @@ g_strchr(const Char *str, int ch)
 }
 
 static int
-g_Ctoc(const Char *str, char *buf, u_int len)
+g_Ctoc(const Char *str, char *buf, size_t len)
 {
 
        while (len--) {
index f069a05dc6561379d51e87055131844b3c309f67..1692d36cc25adf4a95deeebe42e5ccab62c57c13 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: glob.h,v 1.11 2010/09/24 13:32:55 djm Exp $   */
+/*     $OpenBSD: glob.h,v 1.14 2019/02/04 16:45:40 millert Exp $       */
 /*     $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $     */
 
 /*
@@ -46,6 +46,7 @@
 #define        _COMPAT_GLOB_H_
 
 #include <sys/stat.h>
+#include <sys/types.h>
 
 # define glob_t _ssh_compat_glob_t
 # define glob(a, b, c, d)  _ssh__compat_glob(a, b, c, d)
@@ -53,9 +54,9 @@
 
 struct stat;
 typedef struct {
-       int gl_pathc;           /* Count of total paths so far. */
-       int gl_matchc;          /* Count of paths matching pattern. */
-       int gl_offs;            /* Reserved at beginning of gl_pathv. */
+       size_t gl_pathc;        /* Count of total paths so far. */
+       size_t gl_matchc;       /* Count of paths matching pattern. */
+       size_t gl_offs;         /* Reserved at beginning of gl_pathv. */
        int gl_flags;           /* Copy of flags parameter to glob. */
        char **gl_pathv;        /* List of paths matching pattern. */
        struct stat **gl_statv; /* Stat entries corresponding to gl_pathv */