Skip to content

Commit e989c09

Browse files
Fixup urldecode and log issues
1 parent f38c4d9 commit e989c09

5 files changed

Lines changed: 53 additions & 7 deletions

File tree

extractor/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void index_file(char *path, char* filename, bool new) {
178178
sprintf(sdr_path, "%s.sdr", full_path);
179179
mkdir(sdr_path, 0755);
180180

181-
if (validIcon && strncmp(header.icon, "data:image", strlen("data:image"))) {
181+
if (validIcon && strncmp(header.icon, "data:image", strlen("data:image")) == 0) {
182182
Log("Valid BASE64 icon detected, attempting to extract it");
183183
//data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAA
184184
char* fileTypePointer = strchr(header.icon, '/')+1;

launcher/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ void Log(const char* format, ...)
2020
va_list args2;
2121
va_copy (args2, args);
2222
int size = vsnprintf (NULL, 0, format, args) + 1;
23-
char* buffer = malloc((unsigned long) size);
23+
char* buffer = (char*) malloc((unsigned long) size);
2424
vsnprintf (buffer, (unsigned long) size, format, args2);
2525
printf("%s\n", buffer);
26-
syslog(LOG_INFO, buffer);
26+
syslog(LOG_INFO, "%s", buffer);
2727
free(buffer);
2828
va_end (args);
2929
va_end (args2);
@@ -133,6 +133,7 @@ LIPCcode go_callback(LIPC* lipc, const char* property, void* value, void* data)
133133

134134
// Parse the filePath as it is urlencoded
135135
char* filePath = urlDecode(rawFilePath);
136+
Log("Decoded path: \"%s\"", filePath);
136137

137138
char* command = getScriptCommand(filePath);
138139
if (command == NULL)

tests/launcher_test_edgecases.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
#include "launcher.h"
2+
#include "utils.h"
23
#include <assert.h>
34
#include <stdio.h>
45
#include <stdlib.h>
56
#include <string.h>
67

78
int main()
89
{
10+
assert(hexDecode('0') == 0);
11+
assert(hexDecode('1') == 1);
12+
assert(hexDecode('2') == 2);
13+
assert(hexDecode('3') == 3);
14+
assert(hexDecode('4') == 4);
15+
assert(hexDecode('5') == 5);
16+
assert(hexDecode('6') == 6);
17+
assert(hexDecode('7') == 7);
18+
assert(hexDecode('8') == 8);
19+
assert(hexDecode('9') == 9);
20+
assert(hexDecode('a') == 10);
21+
assert(hexDecode('b') == 11);
22+
assert(hexDecode('c') == 12);
23+
assert(hexDecode('d') == 13);
24+
assert(hexDecode('e') == 14);
25+
assert(hexDecode('f') == 15);
26+
assert(hexDecode('A') == 10);
27+
assert(hexDecode('B') == 11);
28+
assert(hexDecode('C') == 12);
29+
assert(hexDecode('D') == 13);
30+
assert(hexDecode('E') == 14);
31+
assert(hexDecode('F') == 15);
32+
33+
934
char* command = getScriptCommand("./tests/Check OTA status v1.1.sh");
1035
assert(command != NULL);
1136
printf("Check OTA status v1.1.sh - %s\n", command);
@@ -19,11 +44,13 @@ int main()
1944
free(command);
2045

2146
printf("\n\n");
22-
const char* test = "4:app://com.notmarek.shell_integration.launcher./tests/KindleCraft.sh";
47+
char* test = strdup("4:app://com.notmarek.shell_integration.launcher./tests/KindleCraft.sh");
2348
go_callback(NULL, "test1", test, NULL);
2449
printf("\n\n");
50+
free(test);
2551

26-
test = "4:app://com.notmarek.shell_integration.launcher./tests/Check OTA status v1.1.sh";
52+
test = strdup("4:app://com.notmarek.shell_integration.launcher.%2Ftests%2FCheck%20OTA%20status%20v1.1.sh");
2753
go_callback(NULL, "test2", test, NULL);
54+
free(test);
2855
return 0;
2956
}

utils/utils.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,31 @@
44
#include <stdlib.h>
55
#include <string.h>
66

7+
int hexDecode(char c)
8+
{
9+
if (c >= '0' && c <= '9')
10+
{
11+
return c - '0';
12+
}
13+
else if (c >= 'a' && c <= 'z')
14+
{
15+
return c - 'a' + 10;
16+
}
17+
else if (c >= 'A' && c <= 'Z')
18+
{
19+
return c - 'A' + 10;
20+
}
21+
return 0;
22+
}
23+
724
char* urlDecode(char* raw)
825
{
926
char* result = (char*) malloc(strlen(raw) + 1); // URLEncoded string will NEVER be longer decoded
1027
int currentFilepathLen = 0;
1128

1229
for (size_t i=0; i < strlen(raw); i++) {
1330
if (raw[i] == '%') {
14-
result[currentFilepathLen++] = (char)(((raw[i+1] - '0') << 4) + (raw[i+2] - '0'));
31+
result[currentFilepathLen++] = (char)((hexDecode(raw[i+1]) << 4) + hexDecode(raw[i+2]));
1532
i += 2;
1633
} else {
1734
result[currentFilepathLen++] = raw[i];
@@ -33,7 +50,7 @@ void strip(char** string)
3350
*string = finalString;
3451
}
3552

36-
inline char* buildCommand(const char* command, const char* sub)
53+
char* buildCommand(const char* command, const char* sub)
3754
{
3855
char* builtCommand = (char*) malloc(strlen(command) + strlen(sub) + 1);
3956
sprintf(builtCommand, command, sub);

utils/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdlib.h>
88
#include <string.h>
99

10+
int hexDecode(char c);
1011
char* urlDecode(char* raw);
1112
void strip(char** string);
1213

0 commit comments

Comments
 (0)