Ver código fonte

Do not expose internal SD.root to sketches with SD.open("/")

main
PaulStoffregen 9 anos atrás
pai
commit
c0149b2429
1 arquivos alterados com 7 adições e 14 exclusões
  1. +7
    -14
      SD.cpp

+ 7
- 14
SD.cpp Ver arquivo

@@ -351,9 +351,11 @@ boolean SDClass::begin(uint8_t csPin) {
// this little helper is used to traverse paths
SdFile SDClass::getParentDir(const char *filepath, int *index) {
// get parent directory
SdFile d1 = root; // start with the mostparent, root!
SdFile d1;
SdFile d2;

d1.openRoot(volume); // start with the mostparent, root!

// we'll use the pointers to swap between the two objects
SdFile *parent = &d1;
SdFile *subdir = &d2;
@@ -449,20 +451,11 @@ File SDClass::open(const char *filepath, uint8_t mode) {
if (!parentdir.isOpen())
return File();

// there is a special case for the Root directory since its a static dir
if (parentdir.isRoot()) {
if ( ! file.open(SD.root, filepath, mode)) {
// failed to open the file :(
return File();
}
// dont close the root!
} else {
if ( ! file.open(parentdir, filepath, mode)) {
return File();
}
// close the parent
parentdir.close();
if ( ! file.open(parentdir, filepath, mode)) {
return File();
}
// close the parent
parentdir.close();

if (mode & (O_APPEND | O_WRITE))
file.seekSet(file.fileSize());

Carregando…
Cancelar
Salvar