http-files: Avoid null dereferences
This commit is contained in:
parent
aa39852931
commit
f3c50f0739
|
@ -117,7 +117,9 @@ public class FileProvider : Dino.FileProvider, Object {
|
|||
});
|
||||
file_meta.mime_type = content_type;
|
||||
if (content_length != null) {
|
||||
file_meta.size = int64.parse(content_length);
|
||||
if (int64.try_parse(content_length, out file_meta.size) == false) {
|
||||
throw new FileReceiveError.GET_METADATA_FAILED("failed to parse size");
|
||||
}
|
||||
}
|
||||
|
||||
return file_meta;
|
||||
|
@ -152,10 +154,23 @@ public class FileProvider : Dino.FileProvider, Object {
|
|||
}
|
||||
|
||||
public FileMeta get_file_meta(FileTransfer file_transfer) throws FileReceiveError {
|
||||
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(file_transfer.counterpart.bare_jid, file_transfer.account);
|
||||
if (conversation == null) throw new FileReceiveError.GET_METADATA_FAILED("No conversation");
|
||||
var? cm_identity = stream_interactor.get_module(ConversationManager.IDENTITY);
|
||||
if (cm_identity == null) {
|
||||
throw new FileReceiveError.GET_METADATA_FAILED("null ConversationManager");
|
||||
}
|
||||
|
||||
Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_id(int.parse(file_transfer.info), conversation);
|
||||
Conversation? conversation = cm_identity.get_conversation(file_transfer.counterpart.bare_jid, file_transfer.account);
|
||||
if (conversation == null) throw new FileReceiveError.GET_METADATA_FAILED("No conversation");
|
||||
else if (file_transfer.info == null) {
|
||||
throw new FileReceiveError.GET_METADATA_FAILED("null file_transfer.info");
|
||||
}
|
||||
|
||||
int info;
|
||||
bool result = int.try_parse(file_transfer.info, out info);
|
||||
if (result == false) {
|
||||
throw new FileReceiveError.GET_METADATA_FAILED("failed to parse file_transfer.info");
|
||||
}
|
||||
Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_id(info, conversation);
|
||||
if (message == null) throw new FileReceiveError.GET_METADATA_FAILED("No message");
|
||||
|
||||
var file_meta = new HttpFileMeta();
|
||||
|
@ -170,10 +185,20 @@ public class FileProvider : Dino.FileProvider, Object {
|
|||
}
|
||||
|
||||
public FileReceiveData? get_file_receive_data(FileTransfer file_transfer) {
|
||||
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(file_transfer.counterpart.bare_jid, file_transfer.account);
|
||||
var? cm_identity = stream_interactor.get_module(ConversationManager.IDENTITY);
|
||||
if (cm_identity == null) return null;
|
||||
|
||||
Conversation? conversation = cm_identity.get_conversation(file_transfer.counterpart.bare_jid, file_transfer.account);
|
||||
if (conversation == null) return null;
|
||||
|
||||
Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_id(int.parse(file_transfer.info), conversation);
|
||||
var? ms_identity = stream_interactor.get_module(MessageStorage.IDENTITY);
|
||||
if (ms_identity == null || file_transfer.info == null) return null;
|
||||
|
||||
int info;
|
||||
bool result = int.try_parse(file_transfer.info, out info);
|
||||
if (result == false) return null;
|
||||
|
||||
Message? message = ms_identity.get_message_by_id(info, conversation);
|
||||
if (message == null) return null;
|
||||
|
||||
var receive_data = new HttpFileReceiveData();
|
||||
|
|
|
@ -81,6 +81,10 @@ public class HttpFileSender : FileSender, Object {
|
|||
body.complete();
|
||||
return;
|
||||
}
|
||||
else if (read < 0) {
|
||||
warning("transfer_more_bytes: stream.read failed");
|
||||
return;
|
||||
}
|
||||
bytes.length = (int)read;
|
||||
body.append_buffer(new Soup.Buffer.take(bytes));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue