Update 'resume_upload' handling in the event of bad OneDrive response (Issue #468) (#469)

* Add JSON response checks in the event OneDrive sends malformed data
This commit is contained in:
abraunegg 2019-04-15 08:10:48 +10:00 committed by GitHub
parent 25d2f7284f
commit c6923cdf29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -75,6 +75,7 @@ struct UploadSession
try {
response = onedrive.requestUploadStatus(session["uploadUrl"].str);
} catch (OneDriveException e) {
// handle any onedrive error response
if (e.httpStatusCode == 400) {
log.vlog("Upload session not found");
return false;
@ -82,10 +83,23 @@ struct UploadSession
throw e;
}
}
session["expirationDateTime"] = response["expirationDateTime"];
session["nextExpectedRanges"] = response["nextExpectedRanges"];
if (session["nextExpectedRanges"].array.length == 0) {
log.vlog("The upload session is completed");
// do we have a valid response from OneDrive?
if (response.object()){
// JSON object
if (("expirationDateTime" in response) && ("nextExpectedRanges" in response)){
// has the elements we need
session["expirationDateTime"] = response["expirationDateTime"];
session["nextExpectedRanges"] = response["nextExpectedRanges"];
if (session["nextExpectedRanges"].array.length == 0) {
log.vlog("The upload session is completed");
return false;
}
} else {
// bad data
return false;
}
} else {
// not a JSON object
return false;
}
return true;