Compare commits

...

5 Commits

Author SHA1 Message Date
holger krekel
e8158b5fbf fix the merge 2019-09-04 14:52:06 +02:00
holger krekel
580fda26b7 Merge branch 'master' into fix_securejoin_closure 2019-09-03 19:06:40 +02:00
jikstra
7b9da77d51 cargo fmt 2019-09-02 18:31:51 +02:00
jikstra
91510e7717 Cleanup closure should be defined as first thing and all variables should get passed as arguments 2019-09-02 17:37:41 +02:00
jikstra
ff1e62a42d Closure shouldn't copy qr variable into it's own scope and we should
never return null pointer
2019-09-02 17:05:31 +02:00

View File

@@ -30,6 +30,15 @@ pub unsafe fn dc_get_securejoin_qr(
==== Alice - the inviter side ====
==== Step 1 in "Setup verified contact" protocol ====
========================================================= */
let cleanup = |fingerprint, qr: Option<String>| {
free(fingerprint as *mut libc::c_void);
if let Some(qr) = qr {
qr.strdup()
} else {
"".strdup()
}
};
let mut fingerprint = ptr::null_mut();
let mut qr: Option<String> = None;
@@ -53,19 +62,9 @@ pub unsafe fn dc_get_securejoin_qr(
});
let self_addr = context.sql.get_config(context, "configured_addr");
let cleanup = |fingerprint| {
free(fingerprint as *mut libc::c_void);
if let Some(qr) = qr {
qr.strdup()
} else {
std::ptr::null_mut()
}
};
if self_addr.is_none() {
error!(context, 0, "Not configured, cannot generate QR code.",);
return cleanup(fingerprint);
return cleanup(fingerprint, qr);
}
let self_addr = self_addr.unwrap();
@@ -77,7 +76,7 @@ pub unsafe fn dc_get_securejoin_qr(
fingerprint = get_self_fingerprint(context);
if fingerprint.is_null() {
return cleanup(fingerprint);
return cleanup(fingerprint, qr);
}
let self_addr_urlencoded = utf8_percent_encode(&self_addr, NON_ALPHANUMERIC).to_string();
@@ -103,7 +102,7 @@ pub unsafe fn dc_get_securejoin_qr(
context,
0, "Cannot get QR-code for chat-id {}", group_chat_id,
);
return cleanup(fingerprint);
return cleanup(fingerprint, qr);
}
} else {
Some(format!(
@@ -118,7 +117,7 @@ pub unsafe fn dc_get_securejoin_qr(
info!(context, 0, "Generated QR code: {}", qr.as_ref().unwrap());
cleanup(fingerprint)
return cleanup(fingerprint, qr);
}
fn get_self_fingerprint(context: &Context) -> *mut libc::c_char {