Quellcode durchsuchen

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

main
PaulStoffregen vor 9 Jahren
Ursprung
Commit
c0149b2429
1 geänderte Dateien mit 7 neuen und 14 gelöschten Zeilen
  1. +7
    -14
      SD.cpp

+ 7
- 14
SD.cpp Datei anzeigen

@@ -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());

Laden…
Abbrechen
Speichern