Only allow absolute paths
This commit is contained in:
@ -18,6 +18,7 @@ size_t hal_strcspn(const char *s, const char *reject);
|
|||||||
size_t hal_strspn(const char *s, const char *accept);
|
size_t hal_strspn(const char *s, const char *accept);
|
||||||
char *hal_strcpy(char *dest, const char *src);
|
char *hal_strcpy(char *dest, const char *src);
|
||||||
char *hal_strchr(const char *s, int c);
|
char *hal_strchr(const char *s, int c);
|
||||||
|
char *hal_strstr(const char *str, const char *substring);
|
||||||
void hal_wait(uint32_t ms);
|
void hal_wait(uint32_t ms);
|
||||||
int32_t hal_randnum(void);
|
int32_t hal_randnum(void);
|
||||||
|
|
||||||
|
|||||||
@ -109,3 +109,34 @@ char *hal_strchr(const char *s, int c) {
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *hal_strstr(const char *str, const char *substring)
|
||||||
|
{
|
||||||
|
const char *a;
|
||||||
|
const char *b;
|
||||||
|
|
||||||
|
b = substring;
|
||||||
|
|
||||||
|
if (*b == 0) {
|
||||||
|
return (char *) str;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( ; *str != 0; str += 1) {
|
||||||
|
if (*str != *b) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
a = str;
|
||||||
|
while (1) {
|
||||||
|
if (*b == 0) {
|
||||||
|
return (char *) str;
|
||||||
|
}
|
||||||
|
if (*a++ != *b++) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b = substring;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
#include "hal/hal.h"
|
||||||
|
|
||||||
void path_parse(const char *in, char *mp, char *path) {
|
void path_parse(const char *in, char *mp, char *path) {
|
||||||
if (in == 0 || *in == 0) {
|
if (in == 0 || *in == 0) {
|
||||||
@ -37,5 +38,18 @@ void path_parse(const char *in, char *mp, char *path) {
|
|||||||
} else {
|
} else {
|
||||||
path[j] = 0;
|
path[j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path[0] != '/') {
|
||||||
|
mp[0] = 0;
|
||||||
|
path[0] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hal_strstr(path, "/../") || hal_strstr(path, "/./")
|
||||||
|
|| hal_strcmp(path, "..") == 0 || hal_strcmp(path, ".") == 0) {
|
||||||
|
mp[0] = 0;
|
||||||
|
path[0] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,6 +38,19 @@ void path_parse(const char *in, char *mp, char *path) {
|
|||||||
} else {
|
} else {
|
||||||
path[j] = 0;
|
path[j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path[0] != '/') {
|
||||||
|
mp[0] = 0;
|
||||||
|
path[0] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string_strstr(path, "/../") || string_strstr(path, "/./")
|
||||||
|
|| string_strcmp(path, "..") == 0 || string_strcmp(path, ".") == 0) {
|
||||||
|
mp[0] = 0;
|
||||||
|
path[0] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *path_basename(const char *path) {
|
const char *path_basename(const char *path) {
|
||||||
|
|||||||
@ -282,3 +282,34 @@ void * string_memmove(void* dest, const void* src, unsigned int n)
|
|||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *string_strstr(const char *str, const char *substring)
|
||||||
|
{
|
||||||
|
const char *a;
|
||||||
|
const char *b;
|
||||||
|
|
||||||
|
b = substring;
|
||||||
|
|
||||||
|
if (*b == 0) {
|
||||||
|
return (char *) str;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( ; *str != 0; str += 1) {
|
||||||
|
if (*str != *b) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
a = str;
|
||||||
|
while (1) {
|
||||||
|
if (*b == 0) {
|
||||||
|
return (char *) str;
|
||||||
|
}
|
||||||
|
if (*a++ != *b++) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b = substring;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ char *string_tokenizealloc(char *s, char *delim);
|
|||||||
char *string_tokenizealloc_linecontinue(char *s, char *delim);
|
char *string_tokenizealloc_linecontinue(char *s, char *delim);
|
||||||
char *string_combine(char *dest, const char *src);
|
char *string_combine(char *dest, const char *src);
|
||||||
void * string_memmove(void* dest, const void* src, unsigned int n);
|
void * string_memmove(void* dest, const void* src, unsigned int n);
|
||||||
|
char *string_strstr(const char *str, const char *substring);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user