Browse code

freshclam/manager.c: fix warnings - bb#1142

git-svn: trunk@4132

Tomasz Kojm authored on 2008/08/22 22:25:05
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Aug 22 15:20:08 CEST 2008 (tk)
2
+----------------------------------
3
+  * freshclam/manager.c: fix warnings - bb#1142
4
+
1 5
 Fri Aug 22 12:33:58 CEST 2008 (acab)
2 6
 ------------------------------------
3 7
   * clamav-milter/clamav-milter.c: missing proto
... ...
@@ -85,6 +85,10 @@
85 85
 #define	closesocket(s)	close(s)
86 86
 #endif
87 87
 
88
+#define CHDIR_ERR(x)				\
89
+	if(chdir(x) == -1)			\
90
+	    logg("!Can't chdir to %s\n", x);
91
+
88 92
 #ifndef SUPPORT_IPv6
89 93
 static const char *ghbn_err(int err) /* hstrerror() */
90 94
 {
... ...
@@ -763,8 +767,11 @@ static int getfile(const char *srcfile, const char *destfile, const char *hostna
763 763
     if((fd = open(destfile, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644)) == -1) {
764 764
 	    char currdir[512];
765 765
 
766
-	getcwd(currdir, sizeof(currdir));
767
-	logg("!getfile: Can't create new file %s in %s\n", destfile, currdir);
766
+	if(getcwd(currdir, sizeof(currdir)))
767
+	    logg("!getfile: Can't create new file %s in %s\n", destfile, currdir);
768
+	else
769
+	    logg("!getfile: Can't create new file %s in the current directory\n", destfile);
770
+
768 771
 	logg("Hint: The database directory must be writable for UID %d or GID %d\n", getuid(), getgid());
769 772
 	closesocket(sd);
770 773
 	return 57;
... ...
@@ -904,7 +911,7 @@ static int getpatch(const char *dbname, const char *tmpdir, int version, const c
904 904
         logg("%cgetpatch: Can't download %s from %s\n", logerr ? '!' : '^', patch, hostname);
905 905
         unlink(tempname);
906 906
         free(tempname);
907
-	chdir(olddir);
907
+	CHDIR_ERR(olddir);
908 908
         return ret;
909 909
     }
910 910
 
... ...
@@ -912,7 +919,7 @@ static int getpatch(const char *dbname, const char *tmpdir, int version, const c
912 912
 	logg("!getpatch: Can't open %s for reading\n", tempname);
913 913
         unlink(tempname);
914 914
         free(tempname);
915
-	chdir(olddir);
915
+	CHDIR_ERR(olddir);
916 916
 	return 55;
917 917
     }
918 918
 
... ...
@@ -921,14 +928,17 @@ static int getpatch(const char *dbname, const char *tmpdir, int version, const c
921 921
 	close(fd);
922 922
         unlink(tempname);
923 923
         free(tempname);
924
-	chdir(olddir);
924
+	CHDIR_ERR(olddir);
925 925
 	return 70; /* FIXME */
926 926
     }
927 927
 
928 928
     close(fd);
929 929
     unlink(tempname);
930 930
     free(tempname);
931
-    chdir(olddir);
931
+    if(chdir(olddir) == -1) {
932
+	logg("!getpatch: Can't chdir to %s\n", olddir);
933
+	return 50; /* FIXME */
934
+    }
932 935
     return 0;
933 936
 }
934 937
 
... ...
@@ -962,8 +972,11 @@ static int buildcld(const char *tmpdir, const char *dbname, const char *newfile,
962 962
 	int fd, err = 0;
963 963
 	gzFile *gzs = NULL;
964 964
 
965
+    if(!getcwd(cwd, sizeof(cwd))) {
966
+	logg("!buildcld: Can't get path of current working directory\n");
967
+	return -1;
968
+    }
965 969
 
966
-    getcwd(cwd, sizeof(cwd));
967 970
     if(chdir(tmpdir) == -1) {
968 971
 	logg("!buildcld: Can't access directory %s\n", tmpdir);
969 972
 	return -1;
... ...
@@ -972,13 +985,13 @@ static int buildcld(const char *tmpdir, const char *dbname, const char *newfile,
972 972
     snprintf(info, sizeof(info), "%s.info", dbname);
973 973
     if((fd = open(info, O_RDONLY|O_BINARY)) == -1) {
974 974
 	logg("!buildcld: Can't open %s\n", info);
975
-	chdir(cwd);
975
+	CHDIR_ERR(cwd);
976 976
 	return -1;
977 977
     }
978 978
 
979 979
     if(read(fd, buff, 512) == -1) {
980 980
 	logg("!buildcld: Can't read %s\n", info);
981
-	chdir(cwd);
981
+	CHDIR_ERR(cwd);
982 982
 	close(fd);
983 983
 	return -1;
984 984
     }
... ...
@@ -987,19 +1000,19 @@ static int buildcld(const char *tmpdir, const char *dbname, const char *newfile,
987 987
 
988 988
     if(!(pt = strchr(buff, '\n'))) {
989 989
 	logg("!buildcld: Bad format of %s\n", info);
990
-	chdir(cwd);
990
+	CHDIR_ERR(cwd);
991 991
 	return -1;
992 992
     }
993 993
     memset(pt, ' ', 512 + buff - pt);
994 994
 
995 995
     if((fd = open(newfile, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644)) == -1) {
996 996
 	logg("!buildcld: Can't open %s for writing\n", newfile);
997
-	chdir(cwd);
997
+	CHDIR_ERR(cwd);
998 998
 	return -1;
999 999
     }
1000 1000
     if(write(fd, buff, 512) != 512) {
1001 1001
 	logg("!buildcld: Can't write to %s\n", newfile);
1002
-	chdir(cwd);
1002
+	CHDIR_ERR(cwd);
1003 1003
 	unlink(newfile);
1004 1004
 	close(fd);
1005 1005
 	return -1;
... ...
@@ -1007,7 +1020,7 @@ static int buildcld(const char *tmpdir, const char *dbname, const char *newfile,
1007 1007
 
1008 1008
     if((dir = opendir(".")) == NULL) {
1009 1009
 	logg("!buildcld: Can't open directory %s\n", tmpdir);
1010
-	chdir(cwd);
1010
+	CHDIR_ERR(cwd);
1011 1011
 	unlink(newfile);
1012 1012
 	close(fd);
1013 1013
 	return -1;
... ...
@@ -1017,7 +1030,7 @@ static int buildcld(const char *tmpdir, const char *dbname, const char *newfile,
1017 1017
 	close(fd);
1018 1018
 	if(!(gzs = gzopen(newfile, "ab"))) {
1019 1019
 	    logg("!buildcld: gzopen() failed for %s\n", newfile);
1020
-	    chdir(cwd);
1020
+	    CHDIR_ERR(cwd);
1021 1021
 	    unlink(newfile);
1022 1022
 	    closedir(dir);
1023 1023
 	    return -1;
... ...
@@ -1042,7 +1055,7 @@ static int buildcld(const char *tmpdir, const char *dbname, const char *newfile,
1042 1042
     }
1043 1043
 
1044 1044
     if(err) {
1045
-	chdir(cwd);
1045
+	CHDIR_ERR(cwd);
1046 1046
 	if(gzs)
1047 1047
 	    gzclose(gzs);
1048 1048
 	else
... ...
@@ -1061,7 +1074,7 @@ static int buildcld(const char *tmpdir, const char *dbname, const char *newfile,
1061 1061
 
1062 1062
 	    if(tar_addfile(fd, gzs, dent->d_name) == -1) {
1063 1063
 		logg("!buildcld: Can't add %s to .cld file\n", dent->d_name);
1064
-		chdir(cwd);
1064
+		CHDIR_ERR(cwd);
1065 1065
 		if(gzs)
1066 1066
 		    gzclose(gzs);
1067 1067
 		else
... ...
@@ -1245,7 +1258,10 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
1245 1245
     if(!cfgopt(copt, "ScriptedUpdates")->enabled)
1246 1246
 	nodb = 1;
1247 1247
 
1248
-    getcwd(cwd, sizeof(cwd));
1248
+    if(!getcwd(cwd, sizeof(cwd))) {
1249
+	logg("!updatedb: Can't get path of current working directory\n");
1250
+	return 50; /* FIXME */
1251
+    }
1249 1252
     newfile = cli_gentemp(cwd);
1250 1253
 
1251 1254
     if(nodb) {