Page MenuHomeFreeBSD

fix atf on MIPS64
ClosedPublic

Authored by br on Sep 19 2016, 1:15 PM.
Tags
None
Referenced Files
F105707675: D7952.diff
Thu, Dec 19, 12:20 PM
Unknown Object (File)
Wed, Dec 4, 7:32 PM
Unknown Object (File)
Wed, Dec 4, 7:32 PM
Unknown Object (File)
Wed, Dec 4, 7:32 PM
Unknown Object (File)
Wed, Dec 4, 7:27 PM
Unknown Object (File)
Wed, Dec 4, 7:27 PM
Unknown Object (File)
Wed, Dec 4, 7:27 PM
Unknown Object (File)
Wed, Dec 4, 7:13 PM
Subscribers

Details

Summary

on MIPS64 we have "ZZZZZZZZ" instead of "/bin/sh", for example:
https://people.freebsd.org/~br/kyua_mips/bin_cat_cat_test_align.html

Using strdup helps

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

br retitled this revision from to fix atf on MIPS64.
br updated this object.
br edited the test plan for this revision. (Show Details)
br added a reviewer: jmmv.

Where's the "ZZZZZZZZ" coming from?

In D7952#164976, @ngie wrote:

Where's the "ZZZZZZZZ" coming from?

it comes from conversion from C++ std::string to C const char * using c_str()

This C++ function returns the correct value "/bin/sh":
std::string
impl::get(const std::string& name, const std::string& default_value)
{

const char *a;
a = atf_env_get_with_default(name.c_str(), default_value.c_str());
printf("a is %s\n", a);
return (a);

}

but then we converting it to C using c_str() here:
sh_argv[0] = atf::env::get("ATF_SHELL", ATF_SHELL).c_str();
and it gets to ZZZZZZZZZ

We use GCC 4.2.1 on MIPS, may be this is a reason ?
The only strdup() helps for me

contrib/atf/atf-sh/atf-check.cpp
351

The original code is bogus because this statement is constructing a temporary std::string and getting a pointer to its contents. When the assignment is complete, the temporary std::string is destroyed so the pointer is invalid.

I guess that the STL in your platform (or something else, who knows) is being compiled with a debug option that is zeroing out (with Zs) the std::string's contents to spot this use-after-free issue.

If you do the following right after the assignment of "cmd":

const std::string shell = atf::env::get("ATF_SHELL", ATF_SHELL).c_str();

then you can do:

sh_argv[0] = shell.c_str();

I bet this will work, and is better than the strdup hack.

use different workaround

Note that this is not a workaround: this is a proper fix for broken code.

contrib/atf/atf-sh/atf-check.cpp
351–354

For style reasons, please move this to right after line 348, as I previously said.

br edited edge metadata.

fix style

contrib/atf/atf-sh/atf-check.cpp
349

Remove the c_str() from here, or else you are creating an extra string for no reason.

jmmv edited edge metadata.
This revision is now accepted and ready to land.Sep 28 2016, 6:10 PM
This revision was automatically updated to reflect the committed changes.