Browse code

freshclam/freshclam.c: fix handling of relative paths with --datadir (bb#2240)

Tomasz Kojm authored on 2010/08/31 23:13:31
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Aug 31 16:11:30 CEST 2010 (tk)
2
+----------------------------------
3
+ * freshclam/freshclam.c: fix handling of relative paths with --datadir (bb#2240)
4
+
1 5
 Tue Aug 31 15:10:29 EEST 2010 (edwin)
2 6
 -------------------------------------
3 7
  * clamd/clamd.c: limit RLIMIT_DATA to 2GB on 32-bit processes (bb #1941).
... ...
@@ -201,8 +201,8 @@ static int download(const struct optstruct *opts, const char *datadir, const cha
201 201
 int main(int argc, char **argv)
202 202
 {
203 203
 	int ret = 52, retcl;
204
-	const char *dbdir, *cfgfile, *arg = NULL, *pidfile = NULL;
205
-	char *pt;
204
+	const char *cfgfile, *arg = NULL, *pidfile = NULL;
205
+	char *pt, dbdir[512];
206 206
 	struct optstruct *opts;
207 207
 	const struct optstruct *opt;
208 208
 #ifndef	_WIN32
... ...
@@ -245,10 +245,8 @@ int main(int argc, char **argv)
245 245
     }
246 246
     free(pt);
247 247
 
248
-    dbdir = optget(opts, "DatabaseDirectory")->strarg;
249
-
250 248
     if(optget(opts, "version")->enabled) {
251
-	print_version(dbdir);
249
+	print_version(optget(opts, "DatabaseDirectory")->strarg);
252 250
 	optfree(opts);
253 251
 	return 0;
254 252
     }
... ...
@@ -364,12 +362,18 @@ int main(int argc, char **argv)
364 364
 #endif
365 365
 
366 366
     /* change the current working directory */
367
-    if(chdir(dbdir)) {
368
-	logg("Can't change dir to %s\n", dbdir);
367
+    if(chdir(optget(opts, "DatabaseDirectory")->strarg)) {
368
+	logg("!Can't change dir to %s\n", optget(opts, "DatabaseDirectory")->strarg);
369 369
 	optfree(opts);
370 370
 	return 50;
371
-    } else
371
+    } else {
372
+	if(!getcwd(dbdir, sizeof(dbdir))) {
373
+	    logg("!getcwd() failed\n");
374
+	    optfree(opts);
375
+	    return 50;
376
+	}
372 377
 	logg("*Current working dir is %s\n", dbdir);
378
+    }
373 379
 
374 380
 
375 381
     if(optget(opts, "list-mirrors")->enabled) {