From 495125415b10d57b7b90d39a54e727b63b0d2c93 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Fri, 22 Jul 2011 23:59:57 +0000 Subject: [PATCH] * src/faillog.c: Add annotations to indicate that usage() does not return. * src/faillog.c: Fix message: this is faillog, not lastlog. * src/faillog.c: Check that there are no extra arguments after parsing the options. --- ChangeLog | 8 ++++++++ src/faillog.c | 16 +++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a0a7234b..8cae8a14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-07-23 Nicolas François + + * src/faillog.c: Add annotations to indicate that usage() does not + return. + * src/faillog.c: Fix message: this is faillog, not lastlog. + * src/faillog.c: Check that there are no extra arguments after + parsing the options. + 2011-07-23 Nicolas François * src/chgpasswd.c: Add annotations to indicate that usage() does diff --git a/src/faillog.c b/src/faillog.c index 2742f2ee..7d3aa62e 100644 --- a/src/faillog.c +++ b/src/faillog.c @@ -2,7 +2,7 @@ * Copyright (c) 1989 - 1993, Julianne Frances Haugh * Copyright (c) 1996 - 2000, Marek Michałkiewicz * Copyright (c) 2002 - 2006, Tomasz Kłoczko - * Copyright (c) 2007 - 2010, Nicolas François + * Copyright (c) 2007 - 2011, Nicolas François * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -48,7 +48,7 @@ #include "exitcodes.h" /* local function prototypes */ -static void usage (int status); +static /*@noreturn@*/void usage (int status); static void print_one (/*@null@*/const struct passwd *pw, bool force); static void set_locktime (long locktime); static bool set_locktime_one (uid_t uid, long locktime); @@ -80,7 +80,7 @@ static struct stat statbuf; /* fstat buffer for file size */ #define NOW (time((time_t *) 0)) -static void usage (int status) +static /*@noreturn@*/void usage (int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; (void) fprintf (usageout, @@ -587,7 +587,7 @@ int main (int argc, char **argv) break; case 'h': usage (E_SUCCESS); - break; + /*@notreached@*/break; case 'l': if (getlong (optarg, &fail_locktime) == 0) { fprintf (stderr, @@ -643,7 +643,7 @@ int main (int argc, char **argv) &umin, &has_umin, &umax, &has_umax) == 0) { fprintf (stderr, - _("lastlog: Unknown user or range: %s\n"), + _("faillog: Unknown user or range: %s\n"), optarg); exit (E_BAD_ARG); } @@ -655,6 +655,12 @@ int main (int argc, char **argv) usage (E_USAGE); } } + if (argc > optind) { + fprintf (stderr, + _("faillog: unexpected argument: %s\n"), + argv[optind]); + usage (EXIT_FAILURE); + } } if (tflg && (lflg || mflg || rflg)) {