git.fiddlerwoaroof.com
Browse code

fix string pointers in fakes

Greg Wiley authored on 27/04/2017 19:27:47
Showing 1 changed files
... ...
@@ -42,6 +42,7 @@ class match_buffer_pwd : public pwd_ifc
42 42
 {
43 43
 private:
44 44
     long int expected_buffer_sz_;
45
+    std::string charbuf_;
45 46
 public:
46 47
     match_buffer_pwd (long int buffer_sz) : expected_buffer_sz_ (buffer_sz) {}
47 48
     int getpwnam_r (const char *user_name, passwd *out, char *buffer,
... ...
@@ -49,6 +50,8 @@ public:
49 50
     {
50 51
 
51 52
         if (expected_buffer_sz_ == buffer_sz && buffer != 0) {
53
+            out->pw_name = const_cast<char *>(charbuf_.c_str());
54
+            out->pw_dir = const_cast<char *>(charbuf_.c_str());
52 55
             *result = out;
53 56
         } else {
54 57
             *result = 0;
... ...
@@ -162,9 +165,9 @@ RESET_VARS_END
162 165
 int run_tests()
163 166
 {
164 167
     test (find_user_happy);
165
-//    test (user_not_found);
166
-//    test (find_user_passes_buffer_and_size);
167
-//    test (find_user_fails_on_pwnam_r_error_and_result_ok);
168
+    test (user_not_found);
169
+    test (find_user_passes_buffer_and_size);
170
+    test (find_user_fails_on_pwnam_r_error_and_result_ok);
168 171
     succeed();
169 172
 }
170 173