Mercurial > dropbear
comparison fuzz/fuzz-common.c @ 1779:36d4c027cba7
fuzzing: add workaround getpwuid/getpwnam
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 16 Nov 2020 22:44:30 +0800 |
parents | 19cdeb3d2aac |
children | b5aedadc0008 |
comparison
equal
deleted
inserted
replaced
1778:19cdeb3d2aac | 1779:36d4c027cba7 |
---|---|
1 #define FUZZ_NO_REPLACE_STDERR | 1 #define FUZZ_NO_REPLACE_STDERR |
2 #define FUZZ_NO_REPLACE_GETPW | |
2 #include "includes.h" | 3 #include "includes.h" |
3 | 4 |
4 #include "includes.h" | 5 #include "includes.h" |
5 #include "dbutil.h" | 6 #include "dbutil.h" |
6 #include "runopts.h" | 7 #include "runopts.h" |
259 | 260 |
260 int fakesock = wrapfd_new_fuzzinput(); | 261 int fakesock = wrapfd_new_fuzzinput(); |
261 | 262 |
262 if (authdone) { | 263 if (authdone) { |
263 ses.authstate.authdone = 1; | 264 ses.authstate.authdone = 1; |
264 char *me = getpwuid(getuid())->pw_name; | 265 char *me = fuzz_getpwuid(getuid())->pw_name; |
265 fill_passwd(me); | 266 fill_passwd(me); |
266 } | 267 } |
267 | 268 |
268 m_malloc_set_epoch(1); | 269 m_malloc_set_epoch(1); |
269 fuzz.do_jmp = 1; | 270 fuzz.do_jmp = 1; |
330 TRACE(("dump %zu", len)) | 331 TRACE(("dump %zu", len)) |
331 if (fuzz.dumping) { | 332 if (fuzz.dumping) { |
332 assert(atomicio(vwrite, fuzz.recv_dumpfd, (void*)data, len) == len); | 333 assert(atomicio(vwrite, fuzz.recv_dumpfd, (void*)data, len) == len); |
333 } | 334 } |
334 } | 335 } |
336 | |
337 static struct passwd pwd_root = { | |
338 .pw_name = "root", | |
339 .pw_passwd = "!", | |
340 .pw_uid = 0, | |
341 .pw_gid = 0, | |
342 .pw_dir = "/root", | |
343 .pw_shell = "/bin/sh", | |
344 }; | |
345 | |
346 static struct passwd pwd_other = { | |
347 .pw_name = "other", | |
348 .pw_passwd = "!", | |
349 .pw_uid = 100, | |
350 .pw_gid = 100, | |
351 .pw_dir = "/home/other", | |
352 .pw_shell = "/bin/sh", | |
353 }; | |
354 | |
355 | |
356 /* oss-fuzz runs fuzzers under minijail, without /etc/passwd. | |
357 We provide sufficient values for the fuzzers to run */ | |
358 struct passwd* fuzz_getpwnam(const char *login) { | |
359 if (!fuzz.fuzzing) { | |
360 return getpwnam(login); | |
361 } | |
362 if (strcmp(login, pwd_other.pw_name) == 0) { | |
363 return &pwd_other; | |
364 } | |
365 if (strcmp(login, pwd_root.pw_name) == 0) { | |
366 return &pwd_root; | |
367 } | |
368 return NULL; | |
369 } | |
370 | |
371 struct passwd* fuzz_getpwuid(uid_t uid) { | |
372 if (!fuzz.fuzzing) { | |
373 return getpwuid(uid); | |
374 } | |
375 if (uid == pwd_other.pw_uid) { | |
376 return &pwd_other; | |
377 } | |
378 if (uid == pwd_root.pw_uid) { | |
379 return &pwd_root; | |
380 } | |
381 return NULL; | |
382 } | |
383 |