]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
flockc: segfaults when file name is not given
authorKarel Zak <kzak@redhat.com>
Wed, 11 Mar 2009 11:49:50 +0000 (12:49 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Mar 2009 12:37:40 +0000 (13:37 +0100)
$ flock -s
Segmentation fault

ltrace:
__libc_start_main(0x8048870, 2, 0xbfe9f404, 0x8049070, 0x8049060 <unfinished ...>
getopt_long(2, 0xbfe9f404, "+sexnouw:hV?", 0x80494e0, 0xbfe9f354) = 115
getopt_long(2, 0xbfe9f404, "+sexnouw:hV?", 0x80494e0, 0xbfe9f354) = -1
strtol(0, 0xbfe9f34c, 10, 0x80494e0, 0xbfe9f354 <unfinished ...>
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++

Addresses-Red-Had-Bugzilla: #489672
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/flock.c

index 029e4364729d54fa92b86c059a323834fac381f0..3386e15b40ec9f7fc9fd291c0a019c3d343678ef 100644 (file)
@@ -217,7 +217,7 @@ int main(int argc, char *argv[])
           EX_NOINPUT);
     }
 
-  } else {
+  } else if (optind < argc) {
     /* Use provided file descriptor */
 
     fd = (int)strtol(argv[optind], &eon, 10);
@@ -226,8 +226,15 @@ int main(int argc, char *argv[])
       exit(EX_USAGE);
     }
 
+  } else {
+    /* Bad options */
+
+    fprintf(stderr, "%s: requires file descriptor, file or directory\n",
+               program);
+    exit(EX_USAGE);
   }
 
+
   if ( have_timeout ) {
     if ( timeout.it_value.tv_sec == 0 &&
         timeout.it_value.tv_usec == 0 ) {