Skip to content

dc_array: panic on null pointers and out of range indexes - #333

Merged
link2xt merged 1 commit into
chatmail:masterfrom
link2xt:dc_array-assert
Aug 13, 2019
Merged

dc_array: panic on null pointers and out of range indexes#333
link2xt merged 1 commit into
chatmail:masterfrom
link2xt:dc_array-assert

Conversation

@link2xt

Copy link
Copy Markdown
Collaborator

No description provided.

Comment threadsrc/dc_array.rs
(*array).get_ptr(index)
}
assert!(!array.is_null());
(*array).get_ptr(index)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you remove index >= (*array).len() check.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_ptr() does this check. It is safe, actually.

@link2xtlink2xt changed the title dc_array: panic on null pointers and out of range indexesWIP: dc_array: panic on null pointers and out of range indexesAug 11, 2019
@link2xt

Copy link
Copy Markdown
CollaboratorAuthor

WIP as I want to rebase it on top of #334

@link2xtlink2xt changed the title WIP: dc_array: panic on null pointers and out of range indexesdc_array: panic on null pointers and out of range indexesAug 13, 2019
Comment threadsrc/dc_array.rs
} else {
(*array).get_uint(index)
}
assert!(!array.is_null());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panicing on a null pointer changes the behaviour of the ffi, i think we should avoid this. If it's null, we should return a 0

https://github.com/deltachat/deltachat-core/blob/e4ce281dc2c8cb1d0765f0e2e73f7846cbba3faa/src/dc_array.c#L252

@JikstraJikstraAug 13, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r10s what do you think about this? Is it likely that we break android/ios at some points with this change?

<Jikstra> we have to be careful with panics in the ffi just because array is a null pointer
<Jikstra> the api allowed us to do weird stuff, panicing will break all apps based on -core-rust
<link2xt[m]> yes, but such panics can be easily debugged
<link2xt[m]> if FFI call panics, it panics immediately
<link2xt[m]> and then you know you should not pass invalid value into it
<link2xt[m]> a simple if is enough to fix it in this case, but it may happen to be an actual bug

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #291 for previous discussion of similar changes. No input from @r10s there, but it got merged.

@link2xt
link2xt merged commit 3175c4f into chatmail:masterAug 13, 2019
@link2xt

Copy link
Copy Markdown
CollaboratorAuthor

deltachat-ffi/src/lib.rs already has the same assertions anyway

Now going to move all unsafe code to FFI

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@link2xt@Jikstra@KAction