summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2019-11-15 16:06:30 +1100
committerDamien Miller <djm@mindrot.org>2019-11-15 16:06:30 +1100
commitfbcb9a7fa55300b8bd4c18bee024c6104c5a25d7 (patch)
tree70ba057302311ed31678bf0167e13dbc5d72771d /openbsd-compat
parent2cfb11abac85885de0cb888bbeb9a3e4303105ea (diff)
upstream commit
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@
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/glob.c33
-rw-r--r--openbsd-compat/glob.h9
2 files changed, 21 insertions, 21 deletions
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c
index 27710b4d6..1e346a8f6 100644
--- a/openbsd-compat/glob.c
+++ b/openbsd-compat/glob.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: glob.c,v 1.47 2017/05/08 14:53:27 millert Exp $ */ 1/* $OpenBSD: glob.c,v 1.48 2019/02/04 16:45:40 millert Exp $ */
2/* 2/*
3 * Copyright (c) 1989, 1993 3 * Copyright (c) 1989, 1993
4 * The Regents of the University of California. All rights reserved. 4 * The Regents of the University of California. All rights reserved.
@@ -150,7 +150,7 @@ struct glob_path_stat {
150 150
151static int compare(const void *, const void *); 151static int compare(const void *, const void *);
152static int compare_gps(const void *, const void *); 152static int compare_gps(const void *, const void *);
153static int g_Ctoc(const Char *, char *, u_int); 153static int g_Ctoc(const Char *, char *, size_t);
154static int g_lstat(Char *, struct stat *, glob_t *); 154static int g_lstat(Char *, struct stat *, glob_t *);
155static DIR *g_opendir(Char *, glob_t *); 155static DIR *g_opendir(Char *, glob_t *);
156static Char *g_strchr(const Char *, int); 156static Char *g_strchr(const Char *, int);
@@ -198,9 +198,8 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
198 if (strnlen(pattern, PATH_MAX) == PATH_MAX) 198 if (strnlen(pattern, PATH_MAX) == PATH_MAX)
199 return(GLOB_NOMATCH); 199 return(GLOB_NOMATCH);
200 200
201 if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 || 201 if (pglob->gl_offs >= SSIZE_MAX || pglob->gl_pathc >= SSIZE_MAX ||
202 pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX || 202 pglob->gl_pathc >= SSIZE_MAX - pglob->gl_offs - 1)
203 pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1)
204 return GLOB_NOSPACE; 203 return GLOB_NOSPACE;
205 204
206 bufnext = patbuf; 205 bufnext = patbuf;
@@ -472,7 +471,8 @@ static int
472glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) 471glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
473{ 472{
474 const Char *qpatnext; 473 const Char *qpatnext;
475 int c, err, oldpathc; 474 int c, err;
475 size_t oldpathc;
476 Char *bufnext, patbuf[PATH_MAX]; 476 Char *bufnext, patbuf[PATH_MAX];
477 477
478 qpatnext = globtilde(pattern, patbuf, PATH_MAX, pglob); 478 qpatnext = globtilde(pattern, patbuf, PATH_MAX, pglob);
@@ -566,9 +566,9 @@ glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
566 if ((pglob->gl_flags & GLOB_KEEPSTAT)) { 566 if ((pglob->gl_flags & GLOB_KEEPSTAT)) {
567 /* Keep the paths and stat info synced during sort */ 567 /* Keep the paths and stat info synced during sort */
568 struct glob_path_stat *path_stat; 568 struct glob_path_stat *path_stat;
569 int i; 569 size_t i;
570 int n = pglob->gl_pathc - oldpathc; 570 size_t n = pglob->gl_pathc - oldpathc;
571 int o = pglob->gl_offs + oldpathc; 571 size_t o = pglob->gl_offs + oldpathc;
572 572
573 if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL) 573 if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL)
574 return GLOB_NOSPACE; 574 return GLOB_NOSPACE;
@@ -797,20 +797,19 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
797 struct stat *sb) 797 struct stat *sb)
798{ 798{
799 char **pathv; 799 char **pathv;
800 ssize_t i; 800 size_t i, newn, len;
801 size_t newn, len;
802 char *copy = NULL; 801 char *copy = NULL;
803 const Char *p; 802 const Char *p;
804 struct stat **statv; 803 struct stat **statv;
805 804
806 newn = 2 + pglob->gl_pathc + pglob->gl_offs; 805 newn = 2 + pglob->gl_pathc + pglob->gl_offs;
807 if (pglob->gl_offs >= INT_MAX || 806 if (pglob->gl_offs >= SSIZE_MAX ||
808 pglob->gl_pathc >= INT_MAX || 807 pglob->gl_pathc >= SSIZE_MAX ||
809 newn >= INT_MAX || 808 newn >= SSIZE_MAX ||
810 SIZE_MAX / sizeof(*pathv) <= newn || 809 SIZE_MAX / sizeof(*pathv) <= newn ||
811 SIZE_MAX / sizeof(*statv) <= newn) { 810 SIZE_MAX / sizeof(*statv) <= newn) {
812 nospace: 811 nospace:
813 for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) { 812 for (i = pglob->gl_offs; i < newn - 2; i++) {
814 if (pglob->gl_pathv && pglob->gl_pathv[i]) 813 if (pglob->gl_pathv && pglob->gl_pathv[i])
815 free(pglob->gl_pathv[i]); 814 free(pglob->gl_pathv[i]);
816 if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 && 815 if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 &&
@@ -971,7 +970,7 @@ fail:
971void 970void
972globfree(glob_t *pglob) 971globfree(glob_t *pglob)
973{ 972{
974 int i; 973 size_t i;
975 char **pp; 974 char **pp;
976 975
977 if (pglob->gl_pathv != NULL) { 976 if (pglob->gl_pathv != NULL) {
@@ -1043,7 +1042,7 @@ g_strchr(const Char *str, int ch)
1043} 1042}
1044 1043
1045static int 1044static int
1046g_Ctoc(const Char *str, char *buf, u_int len) 1045g_Ctoc(const Char *str, char *buf, size_t len)
1047{ 1046{
1048 1047
1049 while (len--) { 1048 while (len--) {
diff --git a/openbsd-compat/glob.h b/openbsd-compat/glob.h
index f069a05dc..1692d36cc 100644
--- a/openbsd-compat/glob.h
+++ b/openbsd-compat/glob.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: glob.h,v 1.11 2010/09/24 13:32:55 djm Exp $ */ 1/* $OpenBSD: glob.h,v 1.14 2019/02/04 16:45:40 millert Exp $ */
2/* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ 2/* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */
3 3
4/* 4/*
@@ -46,6 +46,7 @@
46#define _COMPAT_GLOB_H_ 46#define _COMPAT_GLOB_H_
47 47
48#include <sys/stat.h> 48#include <sys/stat.h>
49#include <sys/types.h>
49 50
50# define glob_t _ssh_compat_glob_t 51# define glob_t _ssh_compat_glob_t
51# define glob(a, b, c, d) _ssh__compat_glob(a, b, c, d) 52# define glob(a, b, c, d) _ssh__compat_glob(a, b, c, d)
@@ -53,9 +54,9 @@
53 54
54struct stat; 55struct stat;
55typedef struct { 56typedef struct {
56 int gl_pathc; /* Count of total paths so far. */ 57 size_t gl_pathc; /* Count of total paths so far. */
57 int gl_matchc; /* Count of paths matching pattern. */ 58 size_t gl_matchc; /* Count of paths matching pattern. */
58 int gl_offs; /* Reserved at beginning of gl_pathv. */ 59 size_t gl_offs; /* Reserved at beginning of gl_pathv. */
59 int gl_flags; /* Copy of flags parameter to glob. */ 60 int gl_flags; /* Copy of flags parameter to glob. */
60 char **gl_pathv; /* List of paths matching pattern. */ 61 char **gl_pathv; /* List of paths matching pattern. */
61 struct stat **gl_statv; /* Stat entries corresponding to gl_pathv */ 62 struct stat **gl_statv; /* Stat entries corresponding to gl_pathv */