Skip to content

Commit 74a928c

Browse files
committed
getcwd optimization ( our cwd is usually 38 chars )
1 parent e7d8850 commit 74a928c

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

dSploit/jni/dSploitd/handler.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,30 @@ int load_handlers() {
7373
void *handle;
7474
size_t len;
7575

76-
d = opendir(HANDLERS_DIR);
77-
78-
if(!d) {
79-
print( ERROR, "opendir: %s", strerror(errno) );
80-
return -1;
76+
len = 50;
77+
cwd = malloc(len);
78+
79+
while(cwd && len < PATH_MAX) {
80+
if(getcwd(cwd, len)) break;
81+
if(errno != ERANGE) {
82+
print( ERROR, "getcwd: %s", strerror(errno));
83+
free(cwd);
84+
return -1;
85+
}
86+
len += 50;
87+
cwd = realloc(cwd, len);
8188
}
8289

83-
cwd = malloc(PATH_MAX);
84-
8590
if(!cwd) {
86-
print( ERROR, "malloc: %s", strerror(errno));
87-
closedir(d);
91+
print( ERROR, "malloc(%d): %s", len, strerror(errno));
8892
return -1;
8993
}
9094

91-
if(!getcwd(cwd, PATH_MAX)) {
92-
print( ERROR, "getcwd: %s", strerror(errno));
95+
d = opendir(HANDLERS_DIR);
96+
97+
if(!d) {
98+
print( ERROR, "opendir: %s", strerror(errno) );
9399
free(cwd);
94-
closedir(d);
95100
return -1;
96101
}
97102

0 commit comments

Comments
 (0)