@@ -31,8 +31,8 @@ zdb_settings_t *zdb_initialize() {
3131 return NULL ;
3232
3333 // apply default settings
34- s -> datapath = strdup ( ZDB_DEFAULT_DATAPATH ) ;
35- s -> indexpath = strdup ( ZDB_DEFAULT_INDEXPATH ) ;
34+ s -> datapath = ZDB_DEFAULT_DATAPATH ;
35+ s -> indexpath = ZDB_DEFAULT_INDEXPATH ;
3636 s -> datasize = ZDB_DEFAULT_DATA_MAXSIZE ;
3737
3838 // running 0-db in mixed mode by default
@@ -108,6 +108,19 @@ zdb_settings_t *zdb_open(zdb_settings_t *zdb_settings) {
108108 zdb_dir_create (zdb_settings -> indexpath );
109109 }
110110
111+ // ensure that data and index does not points to the
112+ // same directory
113+ char * datapath = realpath (zdb_settings -> datapath , NULL );
114+ char * indexpath = realpath (zdb_settings -> indexpath , NULL );
115+
116+ if (strcmp (datapath , indexpath ) == 0 ) {
117+ zdb_danger ("[-] system: cannot use the same directory for index and data path" );
118+ return NULL ;
119+ }
120+
121+ free (datapath );
122+ free (indexpath );
123+
111124 // check/install a lock on the index and data directory to avoid
112125 // multiple instance of zdb running on theses directories
113126 snprintf (lockpath , sizeof (lockpath ), "%s/.lockfile" , zdb_settings -> indexpath );
@@ -139,8 +152,6 @@ void zdb_close(zdb_settings_t *zdb_settings) {
139152
140153 zdb_debug ("[+] bootstrap: cleaning library\n" );
141154 free (zdb_settings -> zdbid );
142- free (zdb_settings -> indexpath );
143- free (zdb_settings -> datapath );
144155 zdb_settings -> zdbid = NULL ;
145156 zdb_settings -> initialized = 0 ;
146157
0 commit comments