free(p);
}
+static void *uwrap_setgid_syscall(void *arg)
+{
+ int rc;
+ gid_t g;
+ gid_t *gmp = (gid_t *) arg;
+
+ rc = syscall(SYS_setgid, 999);
+ assert_int_equal(rc, 0);
+
+ g = getgid();
+ assert_int_equal(g, *gmp);
+
+ return NULL;
+}
+
+static void test_sync_setgid_syscall(void **state)
+{
+ pthread_attr_t pthread_custom_attr;
+ pthread_t threads[NUM_THREADS];
+ gid_t go, gn;
+ gid_t *gtp;
+ int i;
+
+ gtp = malloc(sizeof(gid_t));
+ assert_non_null(gtp);
+
+ (void) state; /* unused */
+
+ pthread_attr_init(&pthread_custom_attr);
+
+ go = getgid();
+ *gtp = go;
+
+ for (i = 0; i < NUM_THREADS; i++) {
+ pthread_create(&threads[i],
+ &pthread_custom_attr,
+ uwrap_setgid_syscall,
+ gtp);
+ }
+
+ /* wait for threaads */
+ for (i = 0; i < NUM_THREADS; i++) {
+ pthread_join(threads[i], NULL);
+ }
+
+ gn = getgid();
+ assert_int_equal(gn, go);
+
+ free(gtp);
+ pthread_attr_destroy(&pthread_custom_attr);
+}
+
+static void *uwrap_setgid(void *arg)
+{
+ int rc;
+ (void) arg; /* unused */
+
+ rc = setgid(999);
+ assert_int_equal(rc, 0);
+
+ return NULL;
+}
+
+static void test_sync_setgid(void **state)
+{
+ pthread_attr_t pthread_custom_attr;
+ pthread_t threads[NUM_THREADS];
+ gid_t g;
+ int i;
+
+ (void) state; /* unused */
+
+ pthread_attr_init(&pthread_custom_attr);
+
+ for (i = 0; i < NUM_THREADS; i++) {
+ pthread_create(&threads[i],
+ &pthread_custom_attr,
+ uwrap_setgid,
+ NULL);
+ }
+
+ /* wait for threaads */
+ for (i = 0; i < NUM_THREADS; i++) {
+ pthread_join(threads[i], NULL);
+ }
+
+ g = getgid();
+ assert_int_equal(g, 999);
+
+ pthread_attr_destroy(&pthread_custom_attr);
+}
+
int main(void) {
int rc;
const UnitTest tests[] = {
unit_test(test_syscall_setreuid),
unit_test(test_sync_setreuid),
+ unit_test(test_sync_setgid),
+ unit_test(test_sync_setgid_syscall),
};
rc = run_tests(tests);