Hi!
> 1. misusage of getpwnam causes ltpuser1 and ltpuser2 to point
> to same passwd structure, from getpwnam(3):
> "The return value may point to a static area, and may be overwritten by
> subsequent calls to getpwent(3)."
> Fix this by copying the results from returned pointer.

I see, that was caused by replacing the my_getpwnam() by
SAFE_GETPWNAM().

Anyway my_getpwnam() is wrong hackend interface, we should get rid of
it. For next time Garrett note that getpwnam() is one of these
non-reentrant interfaces and do it correctly ;).

> +void wait_for_flag(int value)
> +{
> +     while (1) {
> +             if (*flag == value)
> +                     break;
> +             else
> +                     sleep(1);
> +     }
> +}
> +
>  /*
>   * do_master_child()
>   */
> @@ -141,10 +158,16 @@ void do_master_child(char **av)
>       char user1name[] = "nobody";
>       char user2name[] = "bin";
>  
> -     struct passwd *ltpuser1, *ltpuser2;
> +     struct passwd *user;
> +     unsigned int uid1, uid2, gid1, gid2;

Technically these should be uid_t and gid_t.

> -     ltpuser1 = SAFE_GETPWNAM(NULL, user1name);
> -     ltpuser2 = SAFE_GETPWNAM(NULL, user2name);
> +     user = SAFE_GETPWNAM(NULL, user1name);
> +     uid1 = user->pw_uid;
> +     gid1 = user->pw_gid;
> +
> +     user = SAFE_GETPWNAM(NULL, user2name);
> +     uid2 = user->pw_uid;
> +     gid2 = user->pw_gid;
>  
>       TEST_EXP_ENOS(exp_enos);
>  
> @@ -158,11 +181,11 @@ void do_master_child(char **av)
>               tst_brkm(TBROK|TERRNO, cleanup, "Fork failed");
>  
>       if (pid1 == 0) {
> -
> -             if (setreuid(ltpuser1->pw_uid, ltpuser1->pw_uid) == -1) {
> +             if (setreuid(uid1, gid1) == -1) {
>                       perror("setreuid failed (in child)");
>                       exit(1);
>               }
> +             *flag = 1;
>  #ifdef UCLINUX
>               if (self_exec(av[0], "") < 0) {
>                       perror("self_exec failed");
> @@ -172,15 +195,18 @@ void do_master_child(char **av)
>               do_child();
>  #endif
>       }
> -     if (setreuid(ltpuser2->pw_uid, ltpuser2->pw_uid) == -1) {
> +     if (setreuid(uid2, gid2) == -1) {
>               perror("seteuid failed");
>               exit(1);
>       }
>  
> +     /* wait until child sets its euid */
> +     wait_for_flag(1);
> +
>       TEST(kill(pid1, TEST_SIG));
>  
>       /* signal the child that we're done */
> -     *flag = 1;
> +     *flag = 2;
>  
>       if (waitpid(pid1, &status, 0) == -1) {
>               perror("waitpid failed");
> @@ -209,12 +235,8 @@ void do_child()
>       pid_t my_pid;
>  
>       my_pid = getpid();
> -     while (1) {
> -             if (*flag == 1)
> -                     exit(0);
> -             else
> -                     sleep(1);
> -     }
> +     wait_for_flag(2);
> +     exit(0);
>  }
>  
>  void setup(void)

And the patch doesn't apply (as your source is older than current git).

Please use latest git sources when creating patches.

-- 
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to