Skip to content

Commit 62a13ec

Browse files
Use asprintf_hd implementation
1 parent 67ac574 commit 62a13ec

3 files changed

Lines changed: 14 additions & 28 deletions

File tree

extractor/main.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ cJSON* generateChangeRequest(cJSON* json, char* filePath, char* uuid, char* name
138138
void index_file(char *path, char* filename, bool new) {
139139
Log("Indexing file: %s/%s\n", path, filename);
140140

141-
char* full_path;
142-
asprintf(&full_path, "%s/%s", path, filename);
141+
char* full_path = asprintf_hd("%s/%s", path, filename);
143142

144143
// Generate UUID
145144
char uuid[37] = {0};
@@ -174,8 +173,7 @@ void index_file(char *path, char* filename, bool new) {
174173
if (validIcon || header.useHooks) {
175174
Log("Valid icon OR uses hooks");
176175
// Create sdr folder
177-
char* sdr_path;
178-
asprintf(&sdr_path, "%s.sdr", full_path);
176+
char* sdr_path = asprintf_hd("%s.sdr", full_path);
179177
mkdir(sdr_path, 0755);
180178

181179
if (validIcon && strncmp(header.icon, "data:image", strlen("data:image")) == 0) {
@@ -193,8 +191,7 @@ void index_file(char *path, char* filename, bool new) {
193191
strncpy(fileType, fileTypePointer, fileTypeEndPointer - fileTypePointer);
194192
fileType[fileTypeEndPointer - fileTypePointer] = '\0';
195193

196-
char* icon_sdr_path;
197-
asprintf(&icon_sdr_path, "%s/icon.%s", sdr_path, fileType);
194+
char* icon_sdr_path = asprintf_hd( "%s/icon.%s", sdr_path, fileType);
198195

199196
// Parse the base64
200197
FILE* file = fopen(icon_sdr_path, "wb");
@@ -263,8 +260,7 @@ void index_file(char *path, char* filename, bool new) {
263260
const int pid = fork();
264261
if (pid == 0) {
265262
Log("Hello from fork!");
266-
char* command;
267-
asprintf(&command, "source \"%s\"; on_install;", escapedPath);
263+
char* command = asprintf_hd("source \"%s\"; on_install;", escapedPath);
268264
Log("Executing command: %s", command);
269265
execl("/var/local/mkk/su", "su", "-c", command, NULL);
270266
} else {
@@ -275,8 +271,7 @@ void index_file(char *path, char* filename, bool new) {
275271

276272
free(escapedPath);
277273

278-
char* sdrFilePath;
279-
asprintf(&sdrFilePath, "%s/script.sh", sdr_path);
274+
char* sdrFilePath = asprintf_hd("%s/script.sh", sdr_path);
280275
Log("Writing script to %s\n", sdrFilePath);
281276
FILE* scriptFile = fopen(full_path, "r");
282277
FILE* sdrFile = fopen(sdrFilePath, "w");
@@ -322,15 +317,12 @@ void index_file(char *path, char* filename, bool new) {
322317

323318
void remove_file(const char* path, const char* filename, char* uuid) {
324319
Log("Removing file: %s/%s", path, filename);
325-
char* filePath;
326-
asprintf(&filePath, "%s/%s", path, filename);
320+
char* filePath = asprintf_hd("%s/%s", path, filename);
327321

328-
char* sdrPath;
329-
asprintf(&sdrPath, "%s.sdr", filePath);
322+
char* sdrPath = asprintf_hd("%s.sdr", filePath);
330323
free(filePath);
331324

332-
char* sdrScriptPath;
333-
asprintf(&sdrScriptPath, "%s/script.sh", sdrPath);
325+
char* sdrScriptPath = asprintf_hd("%s/script.sh", sdrPath);
334326

335327
Log("Loading file");
336328
FILE* file = fopen(sdrScriptPath, "r");

launcher/main.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ void Log(const char* format, ...)
1919
va_start (args, format);
2020
va_list args2;
2121
va_copy (args2, args);
22-
char* buffer;
23-
vasprintf(&buffer, format, args2);
22+
char* buffer = asprintf_hd(format, args2);
2423
printf("%s\n", buffer);
2524
syslog(LOG_INFO, "%s", buffer);
2625
free(buffer);
@@ -37,11 +36,9 @@ LIPCcode stub(LIPC *lipc, const char *property, void *value, void*) {
3736
(char *)value);
3837
char* mutValue = strdup(value);
3938
char *id = strtok((char *)mutValue, ":");
40-
char *response;
41-
asprintf(&response, "%s:0:", id);
39+
char *response = asprintf_hd("%s:0:", id);
4240
Log("Replying with %s", response);
43-
char *target;
44-
asprintf(&target, "%sresult", property);
41+
char *target = asprintf_hd("%sresult", property);
4542
Log("Replying with %s, %s", target, response);
4643
LipcSetStringProperty(lipc, "com.lab126.appmgrd", target, response);
4744
free(response);
@@ -60,8 +57,7 @@ LIPCcode unload_callback(LIPC* lipc, const char* property, void* value, void* da
6057

6158
// Kill the app if it's running
6259
if (app_pid > 0) {
63-
char* command;
64-
asprintf(&command, "/var/local/mkk/su -c \"kill -9 %i\"", app_pid);
60+
char* command = asprintf_hd("/var/local/mkk/su -c \"kill -9 %i\"", app_pid);
6561
Log("Killing with: %s", command);
6662
system(command);
6763
free(command);

utils/utils.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ void strip(char** string)
7474

7575
char* buildCommand(const char* command, const char* sub)
7676
{
77-
char* builtCommand;
78-
asprintf(&builtCommand, command, sub);
77+
char* builtCommand = asprintf_hd(command, sub);
7978
return builtCommand;
8079
}
8180

@@ -89,8 +88,7 @@ void recursiveDelete(char* path)
8988
{
9089
continue;
9190
}
92-
char* itemPath;
93-
asprintf(&itemPath, "%s/%s", path, item->d_name);
91+
char* itemPath = asprintf_hd("%s/%s", path, item->d_name);
9492
if (item->d_type == DT_DIR)
9593
{
9694
recursiveDelete(itemPath);

0 commit comments

Comments
 (0)