Skip to content

Commit 4a3aa15

Browse files
author
kalibera
committed
Fix path length checks (thanks to Ivan Krylov).
git-svn-id: https://svn.r-project.org/R/trunk@88294 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent bcb8a60 commit 4a3aa15

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/dounzip.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ extract_one(unzFile uf, const char *const dest, const char * const filename,
122122

123123
err = unzOpenCurrentFile(uf);
124124
if (err != UNZ_OK) return err;
125-
if (strlen(dest) > R_PATH_MAX - 1) return 1;
125+
if (strlen(dest) > R_PATH_MAX - 2) return 1;
126126
strcpy(outname, dest);
127127
strcat(outname, FILESEP);
128128
unz_file_info64 file_info;
@@ -131,9 +131,8 @@ extract_one(unzFile uf, const char *const dest, const char * const filename,
131131
sizeof(filename_inzip), NULL, 0, NULL, 0);
132132
fn = filename_inzip; /* might be UTF-8 ... */
133133
if (filename) {
134-
if (strlen(dest) + strlen(filename) > R_PATH_MAX - 2) return 1;
135-
strncpy(fn0, filename, R_PATH_MAX);
136-
fn0[R_PATH_MAX - 1] = '\0';
134+
if (strlen(filename) > R_PATH_MAX - 1) return 1;
135+
strcpy(fn0, filename);
137136
fn = fn0;
138137
}
139138
#ifdef Win32
@@ -143,6 +142,7 @@ extract_one(unzFile uf, const char *const dest, const char * const filename,
143142
p = Rf_strrchr(fn, '/');
144143
if (p) fn = p+1;
145144
}
145+
if (strlen(outname) + strlen(fn) > R_PATH_MAX - 1) return 1;
146146
strcat(outname, fn);
147147

148148
#ifdef Win32

0 commit comments

Comments
 (0)