Make dc_create_setup_code() safe (#239)

Make dc_create_setup_code() safe
This commit is contained in:
Friedel Ziegelmayer
2019-07-28 19:50:25 +02:00
committed by GitHub
3 changed files with 13 additions and 12 deletions

View File

@@ -105,7 +105,7 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
if 0 == dc_alloc_ongoing(context) {
return 0 as *mut libc::c_char;
}
setup_code = dc_create_setup_code(context);
setup_code = to_cstring(dc_create_setup_code(context));
if !setup_code.is_null() {
/* this may require a keypair to be created. this may take a second ... */
if !context
@@ -282,7 +282,7 @@ pub unsafe extern "C" fn dc_render_setup_file(
ret_setupfilecontent
}
pub unsafe fn dc_create_setup_code(_context: &Context) -> *mut libc::c_char {
pub fn dc_create_setup_code(_context: &Context) -> String {
let mut random_val: uint16_t;
let mut rng = thread_rng();
let mut ret = String::new();
@@ -302,7 +302,7 @@ pub unsafe fn dc_create_setup_code(_context: &Context) -> *mut libc::c_char {
);
}
to_cstring(ret)
ret
}
// TODO should return bool /rtn