user portable absolute path checking

This commit is contained in:
Xiaoqiang Wang
2019-12-16 14:30:19 +01:00
parent 993bc6559b
commit e03b2591f2
+5 -2
View File
@@ -50,6 +50,9 @@ extern void dbLoadRecords(const char*, const char*);
#define dbmfStrdup(s) dbmfStrdup((char*)s)
#endif
/* from runScript.c */
extern int isAbsPath(const char* filename);
static int line_num;
static int yyerror(char* str);
@@ -385,7 +388,7 @@ int dbLoadTemplate(const char *sub_file, const char *cmd_collect, const char *pa
}
fp = fopen(sub_file, "r");
if (!fp && sub_file[0] != OSI_PATH_SEPARATOR[0]) {
if (!fp && !isAbsPath(sub_file)) {
const char *dirname, *end;
int dirlen;
char* filename;
@@ -400,7 +403,7 @@ int dbLoadTemplate(const char *sub_file, const char *cmd_collect, const char *pa
if (dirlen == 0) continue; /* ignore empty path elements */
if (dirlen == 1 && dirname[0] == '.') continue; /* we had . already */
filename = NULL;
if (asprintf(&filename, "%.*s" OSI_PATH_SEPARATOR "%s", dirlen, dirname, sub_file) < 0)
if (asprintf(&filename, "%.*s/%s", dirlen, dirname, sub_file) < 0)
{
fprintf(stderr,"dbLoadTemplate: out of memory\n");
break;