Skip to content

Commit ade1453

Browse files
author
ripley
committed
catch zero-length strings in dir.create
git-svn-id: https://svn.r-project.org/R/trunk@87460 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent b61d893 commit ade1453

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

doc/NEWS.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@
479479
480480
\item \code{sort(x, method = "qsort")} made illegal accesses when
481481
\code{x} has length 0.
482+
483+
\item \code{dir.create()} is protected against being passed an
484+
empty string as its \code{path} argument.
482485
}
483486
}
484487
}

src/main/platform.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,6 +2680,7 @@ attribute_hidden SEXP do_dircreate(SEXP call, SEXP op, SEXP args, SEXP env)
26802680
mode = asInteger(CADDDR(args));
26812681
if (mode == NA_LOGICAL) mode = 0777;
26822682
strcpy(dir, R_ExpandFileName(translateCharFP(STRING_ELT(path, 0))));
2683+
if (strlen(dir) == 0) error(_("zero-length 'path' argument"));
26832684
/* remove trailing slashes */
26842685
p = dir + strlen(dir) - 1;
26852686
while (*p == '/' && strlen(dir) > 1) *p-- = '\0';
@@ -2737,6 +2738,7 @@ attribute_hidden SEXP do_dircreate(SEXP call, SEXP op, SEXP args, SEXP env)
27372738
recursive = asLogical(CADDR(args));
27382739
if (recursive == NA_LOGICAL) recursive = 0;
27392740
p = filenameToWchar(STRING_ELT(path, 0), TRUE);
2741+
if (wcslen(p) == 0) error(_("zero-length 'path' argument"));
27402742
dir = (wchar_t*) R_alloc(wcslen(p) + 1, sizeof(wchar_t));
27412743
wcscpy(dir, p);
27422744
R_wfixbackslash(dir);

0 commit comments

Comments
 (0)