Skip to content

Commit

Permalink
norman784GH-44: Fix a malloc error when providing the bakcup's path
Browse files Browse the repository at this point in the history
  • Loading branch information
dcp28 committed Dec 21, 2021
1 parent 893b316 commit 1266669
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 1 addition & 2 deletions examples/idevicebackup2_backup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const imobiledevice = require('../index');
const homedir = require('os').homedir();

const backup_path = homedir + '/backuptemp/';
const backup_path = homedir + '/backuptemp';

imobiledevice.backup2.backup({
debug: true,
network: true,
udid: '199d80698a9a5583b0577f157838861a9d878993',
backup_directory: backup_path
}, (error, data) => {
console.log('------------------- error -------------------');
Expand Down
10 changes: 8 additions & 2 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ namespace idevice_info_node {
char *ToCString(Isolate* isolate, const Local<Value>& value) {
if (!value->IsString()) return NULL;
String::Utf8Value string(isolate, value);
char *str = (char *) malloc(string.length() - 1);
strcpy(str, *string);
char *str = (char *) malloc(string.length() + 1);

if(!str) {
fprintf(stderr, "Fatal Error: failed to allocate %lu bytes.\n", sizeof(char) * (string.length() + 1));
exit(1);
}

strncpy(str, *string, string.length() + 1);
return str;
}

Expand Down

0 comments on commit 1266669

Please sign in to comment.