=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/cmp/cmp.c,v retrieving revision 1.17 retrieving revision 1.18 diff -c -r1.17 -r1.18 *** src/usr.bin/cmp/cmp.c 2018/03/05 16:53:39 1.17 --- src/usr.bin/cmp/cmp.c 2018/03/05 16:57:37 1.18 *************** *** 1,4 **** ! /* $OpenBSD: cmp.c,v 1.17 2018/03/05 16:53:39 cheloha Exp $ */ /* $NetBSD: cmp.c,v 1.7 1995/09/08 03:22:56 tls Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: cmp.c,v 1.18 2018/03/05 16:57:37 cheloha Exp $ */ /* $NetBSD: cmp.c,v 1.7 1995/09/08 03:22:56 tls Exp $ */ /* *************** *** 34,40 **** --- 34,42 ---- #include #include + #include #include + #include #include #include #include *************** *** 44,49 **** --- 46,52 ---- int lflag, sflag; + static off_t get_skip(const char *, const char *); static void __dead usage(void); int *************** *** 98,105 **** if (pledge("stdio", NULL) == -1) err(ERR_EXIT, "pledge"); ! skip1 = argc > 2 ? strtoll(argv[2], NULL, 0) : 0; ! skip2 = argc == 4 ? strtoll(argv[3], NULL, 0) : 0; if (!special) { if (fstat(fd1, &sb1) == -1) --- 101,108 ---- if (pledge("stdio", NULL) == -1) err(ERR_EXIT, "pledge"); ! skip1 = (argc > 2) ? get_skip(argv[2], "skip1") : 0; ! skip2 = (argc == 4) ? get_skip(argv[3], "skip2") : 0; if (!special) { if (fstat(fd1, &sb1) == -1) *************** *** 120,125 **** --- 123,145 ---- c_regular(fd1, file1, skip1, sb1.st_size, fd2, file2, skip2, sb2.st_size); return 0; + } + + static off_t + get_skip(const char *arg, const char *name) + { + off_t skip; + char *ep; + + errno = 0; + skip = strtoll(arg, &ep, 0); + if (arg[0] == '\0' || *ep != '\0') + fatalx("%s is invalid: %s", name, arg); + if (skip < 0) + fatalx("%s is too small: %s", name, arg); + if (skip == LLONG_MAX && errno == ERANGE) + fatalx("%s is too large: %s", name, arg); + return skip; } static void __dead