Fossil SCM
Added check of rc for setgid/setuid() calls.
Commit
4d107b597a4c9eb9db9f76754b069726288762a4
Parent
8a18e7fb7f0a7e2…
1 file changed
+8
-3
+8
-3
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -24,11 +24,13 @@ | ||
| 24 | 24 | #include <time.h> |
| 25 | 25 | #include <fcntl.h> |
| 26 | 26 | #include <sys/types.h> |
| 27 | 27 | #include <sys/stat.h> |
| 28 | 28 | #include <stdlib.h> /* atexit() */ |
| 29 | - | |
| 29 | +#if !defined(_WIN32) | |
| 30 | +# include <errno.h> /* errno global */ | |
| 31 | +#endif | |
| 30 | 32 | #if INTERFACE |
| 31 | 33 | #ifdef FOSSIL_ENABLE_JSON |
| 32 | 34 | # include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */ |
| 33 | 35 | # include "json_detail.h" |
| 34 | 36 | #endif |
| @@ -1151,12 +1153,15 @@ | ||
| 1151 | 1153 | zRepo = &zDir[i]; |
| 1152 | 1154 | } |
| 1153 | 1155 | if( stat(zRepo, &sStat)!=0 ){ |
| 1154 | 1156 | fossil_fatal("cannot stat() repository: %s", zRepo); |
| 1155 | 1157 | } |
| 1156 | - setgid(sStat.st_gid); | |
| 1157 | - setuid(sStat.st_uid); | |
| 1158 | + i = setgid(sStat.st_gid); | |
| 1159 | + i = i || setuid(sStat.st_uid); | |
| 1160 | + if(i){ | |
| 1161 | + fossil_fatal("setgid/uid() failed with errno %d", errno); | |
| 1162 | + } | |
| 1158 | 1163 | if( g.db!=0 ){ |
| 1159 | 1164 | db_close(1); |
| 1160 | 1165 | db_open_repository(zRepo); |
| 1161 | 1166 | } |
| 1162 | 1167 | } |
| 1163 | 1168 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -24,11 +24,13 @@ | |
| 24 | #include <time.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <stdlib.h> /* atexit() */ |
| 29 | |
| 30 | #if INTERFACE |
| 31 | #ifdef FOSSIL_ENABLE_JSON |
| 32 | # include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */ |
| 33 | # include "json_detail.h" |
| 34 | #endif |
| @@ -1151,12 +1153,15 @@ | |
| 1151 | zRepo = &zDir[i]; |
| 1152 | } |
| 1153 | if( stat(zRepo, &sStat)!=0 ){ |
| 1154 | fossil_fatal("cannot stat() repository: %s", zRepo); |
| 1155 | } |
| 1156 | setgid(sStat.st_gid); |
| 1157 | setuid(sStat.st_uid); |
| 1158 | if( g.db!=0 ){ |
| 1159 | db_close(1); |
| 1160 | db_open_repository(zRepo); |
| 1161 | } |
| 1162 | } |
| 1163 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -24,11 +24,13 @@ | |
| 24 | #include <time.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <stdlib.h> /* atexit() */ |
| 29 | #if !defined(_WIN32) |
| 30 | # include <errno.h> /* errno global */ |
| 31 | #endif |
| 32 | #if INTERFACE |
| 33 | #ifdef FOSSIL_ENABLE_JSON |
| 34 | # include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */ |
| 35 | # include "json_detail.h" |
| 36 | #endif |
| @@ -1151,12 +1153,15 @@ | |
| 1153 | zRepo = &zDir[i]; |
| 1154 | } |
| 1155 | if( stat(zRepo, &sStat)!=0 ){ |
| 1156 | fossil_fatal("cannot stat() repository: %s", zRepo); |
| 1157 | } |
| 1158 | i = setgid(sStat.st_gid); |
| 1159 | i = i || setuid(sStat.st_uid); |
| 1160 | if(i){ |
| 1161 | fossil_fatal("setgid/uid() failed with errno %d", errno); |
| 1162 | } |
| 1163 | if( g.db!=0 ){ |
| 1164 | db_close(1); |
| 1165 | db_open_repository(zRepo); |
| 1166 | } |
| 1167 | } |
| 1168 |