Add object check for json value (#551)

* Add explicit check that variable is a valid object
* Add default handling if query throws an error
This commit is contained in:
abraunegg 2019-06-21 00:45:04 +10:00 committed by GitHub
parent cc7bcb1be8
commit bb2986b222
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1107,20 +1107,32 @@ final class SyncEngine
if (e.httpStatusCode >= 500) { if (e.httpStatusCode >= 500) {
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged // OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
return; return;
} else {
// Default operation if not a 500 error
log.error("ERROR: Query of OneDrive for file details failed");
return;
} }
} }
if (isMalware(fileDetails)){ // fileDetails has to be a valid JSON object
// OneDrive reports that this file is malware if (fileDetails.object()){
log.error("ERROR: MALWARE DETECTED IN FILE - DOWNLOAD SKIPPED"); if (isMalware(fileDetails)){
// set global flag // OneDrive reports that this file is malware
malwareDetected = true; log.error("ERROR: MALWARE DETECTED IN FILE - DOWNLOAD SKIPPED");
// set global flag
malwareDetected = true;
return;
}
} else {
// Issue #550 handling
log.vdebug("ERROR: onedrive.getFileDetails call returned a OneDriveException error");
// We want to return, cant download
return; return;
} }
if (!dryRun) { if (!dryRun) {
ulong fileSize = 0; ulong fileSize = 0;
if (hasFileSize(fileDetails)) { if ( (hasFileSize(fileDetails)) && (fileDetails.object()) ) {
// Set the file size from the returned data // Set the file size from the returned data
fileSize = fileDetails["size"].integer; fileSize = fileDetails["size"].integer;
} else { } else {