cd $(DESTDIR)$(usrbin_execdir) && ln -sf last lastb
INSTALL_EXEC_HOOKS += install-exec-hook-last
+
+if FUZZING_ENGINE
+check_PROGRAMS += test_last_fuzz
+
+# https://google.github.io/oss-fuzz/getting-started/new-project-guide/#Requirements
+nodist_EXTRA_test_last_fuzz_SOURCES = dummy.cxx
+
+test_last_fuzz_SOURCES = login-utils/last.c
+test_last_fuzz_CFLAGS = $(AM_CFLAGS) -DFUZZ_TARGET
+test_last_fuzz_LDADD = $(LDADD) libcommon.la $(LIB_FUZZING_ENGINE)
+endif
+
endif
if BUILD_SULOGIN
#include "timeutils.h"
#include "monotonic.h"
+#ifdef FUZZ_TARGET
+#include "fuzz.h"
+#endif
+
#ifndef SHUTDOWN_TIME
# define SHUTDOWN_TIME 254
#endif
static time_t lastdate; /* Last date we've seen */
static time_t currentdate; /* date when we started processing the file */
+#ifndef FUZZ_TARGET
/* --time-format=option parser */
static int which_time_format(const char *s)
{
}
errx(EXIT_FAILURE, _("unknown time format: %s"), s);
}
+#endif
/*
* Read one utmp entry, return in new format.
return 1;
}
+#ifndef FUZZ_TARGET
/*
* Print a short date.
*/
warnx(_("Interrupted %s"), showdate());
signal(SIGQUIT, quit_handler);
}
+#endif
/*
* Lookup a host with DNS.
return 0;
}
-
+#ifndef FUZZ_TARGET
static void __attribute__((__noreturn__)) usage(const struct last_control *ctl)
{
FILE *out = stdout;
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
+#endif
static int is_phantom(const struct last_control *ctl, struct utmpx *ut)
{
int quit = 0; /* Flag */
int down = 0; /* Down flag */
+#ifndef FUZZ_TARGET
time(&lastdown);
+#else
+ lastdown = 1596001948;
+#endif
/*
* Fill in 'lastdate'
*/
lastdate = currentdate = lastrch = lastdown;
+#ifndef FUZZ_TARGET
/*
* Install signal handlers
*/
signal(SIGINT, int_handler);
signal(SIGQUIT, quit_handler);
+#endif
/*
* Open the utmp file
}
}
+#ifdef FUZZ_TARGET
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ struct last_control ctl = {
+ .showhost = TRUE,
+ .name_len = LAST_LOGIN_LEN,
+ .time_fmt = LAST_TIMEFTM_SHORT,
+ .domain_len = LAST_DOMAIN_LEN,
+ .boot_time = {
+ .tv_sec = 1595978419,
+ .tv_usec = 816074
+ }
+ };
+ char name[] = "/tmp/test-last-fuzz.XXXXXX";
+ int fd;
+ ssize_t n;
+
+ fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
+ assert(fd >= 0);
+
+ n = write(fd, data, size);
+ assert(n == (ssize_t) size);
+
+ process_wtmp_file(&ctl, name);
+
+ close(fd);
+ unlink(name);
+
+ return 0;
+}
+#else
int main(int argc, char **argv)
{
struct last_control ctl = {
free(files);
return EXIT_SUCCESS;
}
+#endif