Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@
#define ABS_MP(s, path, file) ABS_MP_(s, path, file, alloca)
#define ABS_MP2(s, path, file) ABS_MP_(s, path, file, malloc)

#define str_beginwith(text, prefix) (!strncmp(text, prefix, strlen(prefix)))

#endif
8 changes: 4 additions & 4 deletions src/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static int __hashtable_entry_delete_subkeys(void *h, const char *key,
while (p->next) {
n = p;
p = p->next;
if ((hash == b->hash) && (strstr(p->key, key) == p->key)) {
if ((hash == b->hash) && str_beginwith(p->key, key)) {
level = __hashtable_entry_delete_subkeys(h, key,
get_hash(p->key, 0),
level);
Expand All @@ -230,7 +230,7 @@ static int __hashtable_entry_delete_subkeys(void *h, const char *key,
}
}
/* Finally check the bucket */
if (b->key && (hash == b->hash) && (strstr(b->key, key) == b->key)) {
if (b->key && (hash == b->hash) && str_beginwith(b->key, key)) {
level = __hashtable_entry_delete_subkeys(h, key,
get_hash(b->key, 0),
level);
Expand Down Expand Up @@ -267,13 +267,13 @@ void hashtable_entry_delete_subkeys(void *h, const char *key, uint32_t hash)
while (p->next) {
n = p;
p = p->next;
if (strstr(p->key, key) == p->key) {
if (str_beginwith(p->key, key)) {
hashtable_entry_delete_hash(h, p->key, p->hash);
p = n;
}
}
/* Finally check the bucket */
if (b->key && (strstr(b->key, key) == b->key))
if (b->key && str_beginwith(b->key, key))
hashtable_entry_delete_hash(h, b->key, b->hash);
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/rar2fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static int get_save_eof(char *rar)
char *s = OPT_STR(OPT_KEY_SRC, 0);
int save_eof;

if (strstr(rar, s))
if (str_beginwith(rar, s))
rar += strlen(s);
save_eof = rarconfig_getprop(int, rar, RAR_SAVE_EOF_PROP);
if (save_eof >= 0)
Expand All @@ -270,7 +270,7 @@ static const char *get_alias(const char *rar, const char *file)

ABS_MP(file_abs, "/", file);

if (strstr(rar, s))
if (str_beginwith(rar, s))
rar += strlen(s);
alias = rarconfig_getalias(rar, file_abs);
if (alias)
Expand All @@ -294,7 +294,7 @@ static int get_seek_length(char *rar)
char *s = OPT_STR(OPT_KEY_SRC, 0);
int seek_len;

if (strstr(rar, s))
if (str_beginwith(rar, s))
rar += strlen(s);
seek_len = rarconfig_getprop(int, rar, RAR_SEEK_LENGTH_PROP);
if (seek_len >= 0)
Expand Down Expand Up @@ -481,8 +481,11 @@ static char *get_password(const char *file, char *buf, size_t len)
tmp = rar;
s = OPT_STR(OPT_KEY_SRC, 0);

if (strstr(rar, s))
int slen = strlen(s);
if (!strncmp(rar, s, slen)){
rar += strlen(s);
}

password = rarconfig_getprop(prop_type_, rar,
RAR_PASSWORD_PROP);
if (password) {
Expand Down
20 changes: 14 additions & 6 deletions src/rarconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,20 @@ static struct parent_node *find_next_parent(FILE *fp, struct parent_node *p)
fseek(fp, 0L, SEEK_SET);

while (fgets(line, LINE_MAX, fp)) {
if (sscanf(line, " [ %[^]] ", s) == 1) {
p = malloc(sizeof(struct parent_node));
p->name = strdup(s);
p->pos = ftell(fp);
return p;
}
const char *lstart=line;
while (isspace(*lstart)) lstart++;
if (*lstart!='[') continue;
lstart++;

const char *lend=lstart+strlen(lstart)-1;
while (lend>lstart && *lend!=']') lend--;
if (lend==lstart) continue; // Shall we warn on invalid line here?
*(char*)lend = '\0';

p = malloc(sizeof(struct parent_node));
p->name = strdup(lstart);
p->pos = ftell(fp);
return p;
}

return NULL;
Expand Down