Re: PATCH: overflow behavior in malloc(9)

2014-07-21 Thread Jean-Philippe Ouellet
On Mon, Jul 21, 2014 at 06:59:12AM +, Doug Hogan wrote:
> -objects and checks for arithmetic overflow.
> +objects and calls
> +.Xr panic 9
> +on arithmetic overflow.


That is misleading in the M_CANFAIL case.

I'm not terribly good at wording things, but I suggest something
more like this instead:


Index: malloc.9
===
RCS file: /cvs/src/share/man/man9/malloc.9,v
retrieving revision 1.56
diff -u -p -r1.56 malloc.9
--- malloc.912 Jul 2014 18:51:10 -  1.56
+++ malloc.922 Jul 2014 06:48:28 -
@@ -97,16 +97,14 @@ or
 .Dv M_WAITOK
 must be specified.
 .It Dv M_CANFAIL
-In the
+If using
+.Fn mallocarray
+and arithmetic would overflow, or if
 .Dv M_WAITOK
-case, if not enough memory is available, return
+is also specified and not enough memory is available, then
 .Dv NULL
-instead of calling
+is returned instead of calling
 .Xr panic 9 .
-.Dv M_CANFAIL
-has no effect if
-.Dv M_NOWAIT
-is specified.
 .It Dv M_ZERO
 Causes
 .Fn malloc



PATCH: Avoid useless if != NULL check on BUF_MEM_free() in LibreSSL

2014-07-21 Thread Doug Hogan
BUF_MEM_free() only has one parameter and it returns immediately
if it is NULL.


Index: src/crypto/asn1/a_d2i_fp.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/asn1/a_d2i_fp.c,v
retrieving revision 1.11
diff -u -p -d -r1.11 a_d2i_fp.c
--- src/crypto/asn1/a_d2i_fp.c  13 Jul 2014 11:10:20 -  1.11
+++ src/crypto/asn1/a_d2i_fp.c  22 Jul 2014 06:12:57 -
@@ -99,8 +99,7 @@ ASN1_d2i_bio(void *(*xnew)(void), d2i_of
ret = d2i(x, &p, len);
 
 err:
-   if (b != NULL)
-   BUF_MEM_free(b);
+   BUF_MEM_free(b);
return (ret);
 }
 
@@ -122,8 +121,7 @@ ASN1_item_d2i_bio(const ASN1_ITEM *it, B
ret = ASN1_item_d2i(x, &p, len, it);
 
 err:
-   if (b != NULL)
-   BUF_MEM_free(b);
+   BUF_MEM_free(b);
return (ret);
 }
 
@@ -265,7 +263,6 @@ asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
return off;
 
 err:
-   if (b != NULL)
-   BUF_MEM_free(b);
+   BUF_MEM_free(b);
return -1;
 }
Index: src/crypto/conf/conf_def.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/conf/conf_def.c,v
retrieving revision 1.28
diff -u -p -d -r1.28 conf_def.c
--- src/crypto/conf/conf_def.c  11 Jul 2014 15:38:03 -  1.28
+++ src/crypto/conf/conf_def.c  22 Jul 2014 06:13:02 -
@@ -412,14 +412,12 @@ again:
v = NULL;
}
}
-   if (buff != NULL)
-   BUF_MEM_free(buff);
+   BUF_MEM_free(buff);
free(section);
return (1);
 
 err:
-   if (buff != NULL)
-   BUF_MEM_free(buff);
+   BUF_MEM_free(buff);
free(section);
if (line != NULL)
*line = eline;
@@ -614,8 +612,7 @@ str_copy(CONF *conf, char *section, char
return (1);
 
 err:
-   if (buf != NULL)
-   BUF_MEM_free(buf);
+   BUF_MEM_free(buf);
return (0);
 }
 
Index: src/crypto/txt_db/txt_db.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/txt_db/txt_db.c,v
retrieving revision 1.18
diff -u -p -d -r1.18 txt_db.c
--- src/crypto/txt_db/txt_db.c  11 Jul 2014 08:44:49 -  1.18
+++ src/crypto/txt_db/txt_db.c  22 Jul 2014 06:13:06 -
@@ -287,8 +287,7 @@ TXT_DB_write(BIO *out, TXT_DB *db)
ret = tot;
 
 err:
-   if (buf != NULL)
-   BUF_MEM_free(buf);
+   BUF_MEM_free(buf);
return (ret);
 }
 
Index: src/crypto/x509/by_dir.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/x509/by_dir.c,v
retrieving revision 1.32
diff -u -p -d -r1.32 by_dir.c
--- src/crypto/x509/by_dir.c11 Jul 2014 08:44:49 -  1.32
+++ src/crypto/x509/by_dir.c22 Jul 2014 06:13:08 -
@@ -200,8 +200,7 @@ free_dir(X509_LOOKUP *lu)
a = (BY_DIR *)lu->method_data;
if (a->dirs != NULL)
sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free);
-   if (a->buffer != NULL)
-   BUF_MEM_free(a->buffer);
+   BUF_MEM_free(a->buffer);
free(a);
 }
 
@@ -426,7 +425,6 @@ get_cert_by_subject(X509_LOOKUP *xl, int
}
}
 finish:
-   if (b != NULL)
-   BUF_MEM_free(b);
+   BUF_MEM_free(b);
return (ok);
 }
Index: src/crypto/x509/x509_obj.c
===
RCS file: /cvs/src/lib/libssl/src/crypto/x509/x509_obj.c,v
retrieving revision 1.16
diff -u -p -d -r1.16 x509_obj.c
--- src/crypto/x509/x509_obj.c  11 Jul 2014 08:44:49 -  1.16
+++ src/crypto/x509/x509_obj.c  22 Jul 2014 06:13:08 -
@@ -173,7 +173,6 @@ X509_NAME_oneline(X509_NAME *a, char *bu
 
 err:
X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);
-   if (b != NULL)
-   BUF_MEM_free(b);
+   BUF_MEM_free(b);
return (NULL);
 }
Index: src/ssl/d1_clnt.c
===
RCS file: /cvs/src/lib/libssl/src/ssl/d1_clnt.c,v
retrieving revision 1.31
diff -u -p -d -r1.31 d1_clnt.c
--- src/ssl/d1_clnt.c   12 Jul 2014 22:33:39 -  1.31
+++ src/ssl/d1_clnt.c   22 Jul 2014 06:13:30 -
@@ -747,8 +747,7 @@ end:
s->in_handshake, NULL);
 #endif
 
-   if (buf != NULL)
-   BUF_MEM_free(buf);
+   BUF_MEM_free(buf);
if (cb != NULL)
cb(s, SSL_CB_CONNECT_EXIT, ret);
return (ret);
Index: src/ssl/s23_clnt.c
===
RCS file: /cvs/src/lib/libssl/src/ssl/s23_clnt.c,v
retrieving revision 1.31
diff -u -p -d -r1.31 s23_clnt.c
--- src/ssl/s23_clnt.c  11 Jul 2014 08:17:36 -  1.31
+++ src/ssl/s23_clnt.c  22 Jul 2014 06:13:33 -
@@ -278,8 +278,7 @@ ssl23_connect(SSL *s)
}
 end:
s->in_handshake--;
-   if (buf != NULL)
-   BUF_MEM_free(buf)

Re: PATCH: overflow behavior in malloc(9)

2014-07-21 Thread Jason McIntyre
On Mon, Jul 21, 2014 at 06:59:12AM +, Doug Hogan wrote:
> Make it clear what check implies for mallocarray.  Thanks to dlg@ for
> pointing this behavior out.
> 

some take this, please.
jmc

> 
> Index: share/man/man9/malloc.9
> ===
> RCS file: /cvs/src/share/man/man9/malloc.9,v
> retrieving revision 1.56
> diff -u -p -d -r1.56 malloc.9
> --- share/man/man9/malloc.9   12 Jul 2014 18:51:10 -  1.56
> +++ share/man/man9/malloc.9   21 Jul 2014 06:39:36 -
> @@ -57,7 +57,9 @@ function is the same as
>  .Fn malloc ,
>  except it allocates space for an array of
>  .Fa nmemb
> -objects and checks for arithmetic overflow.
> +objects and calls
> +.Xr panic 9
> +on arithmetic overflow.
>  .Pp
>  The
>  .Fn free
> 



PATCH: Remove useless if !NULL check before BIO_free() in LibreSSL

2014-07-21 Thread Doug Hogan
BIO_free() returns immediately when the sole input is NULL.


Index: lib/libssl/src/apps/apps.c
===
RCS file: /cvs/src/lib/libssl/src/apps/apps.c,v
retrieving revision 1.68
diff -u -p -d -r1.68 apps.c
--- lib/libssl/src/apps/apps.c  19 Jul 2014 03:40:26 -  1.68
+++ lib/libssl/src/apps/apps.c  22 Jul 2014 05:14:46 -
@@ -669,8 +669,7 @@ end:
BIO_printf(err, "unable to load certificate\n");
ERR_print_errors(err);
}
-   if (cert != NULL)
-   BIO_free(cert);
+   BIO_free(cert);
return (x);
 }
 
@@ -745,8 +744,7 @@ load_key(BIO *err, const char *file, int
goto end;
}
 end:
-   if (key != NULL)
-   BIO_free(key);
+   BIO_free(key);
if (pkey == NULL) {
BIO_printf(err, "unable to load %s\n", key_descrip);
ERR_print_errors(err);
@@ -833,8 +831,7 @@ load_pubkey(BIO *err, const char *file, 
}
 
 end:
-   if (key != NULL)
-   BIO_free(key);
+   BIO_free(key);
if (pkey == NULL)
BIO_printf(err, "unable to load %s\n", key_descrip);
return (pkey);
Index: lib/libssl/src/apps/dh.c
===
RCS file: /cvs/src/lib/libssl/src/apps/dh.c,v
retrieving revision 1.25
diff -u -p -d -r1.25 dh.c
--- lib/libssl/src/apps/dh.c14 Jul 2014 00:35:10 -  1.25
+++ lib/libssl/src/apps/dh.c22 Jul 2014 05:14:46 -
@@ -297,8 +297,7 @@ bad:
ret = 0;
 
 end:
-   if (in != NULL)
-   BIO_free(in);
+   BIO_free(in);
if (out != NULL)
BIO_free_all(out);
if (dh != NULL)
Index: lib/libssl/src/apps/dhparam.c
===
RCS file: /cvs/src/lib/libssl/src/apps/dhparam.c,v
retrieving revision 1.33
diff -u -p -d -r1.33 dhparam.c
--- lib/libssl/src/apps/dhparam.c   14 Jul 2014 00:35:10 -  1.33
+++ lib/libssl/src/apps/dhparam.c   22 Jul 2014 05:14:47 -
@@ -441,8 +441,7 @@ bad:
ret = 0;
 
 end:
-   if (in != NULL)
-   BIO_free(in);
+   BIO_free(in);
if (out != NULL)
BIO_free_all(out);
if (dh != NULL)
Index: lib/libssl/src/apps/dsa.c
===
RCS file: /cvs/src/lib/libssl/src/apps/dsa.c,v
retrieving revision 1.28
diff -u -p -d -r1.28 dsa.c
--- lib/libssl/src/apps/dsa.c   14 Jul 2014 00:35:10 -  1.28
+++ lib/libssl/src/apps/dsa.c   22 Jul 2014 05:14:55 -
@@ -320,8 +320,7 @@ bad:
} else
ret = 0;
 end:
-   if (in != NULL)
-   BIO_free(in);
+   BIO_free(in);
if (out != NULL)
BIO_free_all(out);
if (dsa != NULL)
Index: lib/libssl/src/apps/dsaparam.c
===
RCS file: /cvs/src/lib/libssl/src/apps/dsaparam.c,v
retrieving revision 1.34
diff -u -p -d -r1.34 dsaparam.c
--- lib/libssl/src/apps/dsaparam.c  14 Jul 2014 00:35:10 -  1.34
+++ lib/libssl/src/apps/dsaparam.c  22 Jul 2014 05:15:02 -
@@ -382,8 +382,7 @@ bad:
ret = 0;
 
 end:
-   if (in != NULL)
-   BIO_free(in);
+   BIO_free(in);
if (out != NULL)
BIO_free_all(out);
if (dsa != NULL)
Index: lib/libssl/src/apps/ec.c
===
RCS file: /cvs/src/lib/libssl/src/apps/ec.c,v
retrieving revision 1.16
diff -u -p -d -r1.16 ec.c
--- lib/libssl/src/apps/ec.c14 Jul 2014 00:35:10 -  1.16
+++ lib/libssl/src/apps/ec.c22 Jul 2014 05:15:02 -
@@ -328,8 +328,7 @@ bad:
} else
ret = 0;
 end:
-   if (in)
-   BIO_free(in);
+   BIO_free(in);
if (out)
BIO_free_all(out);
if (eckey)
Index: lib/libssl/src/apps/ecparam.c
===
RCS file: /cvs/src/lib/libssl/src/apps/ecparam.c,v
retrieving revision 1.23
diff -u -p -d -r1.23 ecparam.c
--- lib/libssl/src/apps/ecparam.c   14 Jul 2014 00:35:10 -  1.23
+++ lib/libssl/src/apps/ecparam.c   22 Jul 2014 05:15:03 -
@@ -578,8 +578,7 @@ end:
if (ec_cofactor)
BN_free(ec_cofactor);
free(buffer);
-   if (in != NULL)
-   BIO_free(in);
+   BIO_free(in);
if (out != NULL)
BIO_free_all(out);
if (group != NULL)
Index: lib/libssl/src/apps/enc.c
===
RCS file: /cvs/src/lib/libssl/src/apps/enc.c,v
retrieving revision 1.38
diff -u -p -d -r1.38 enc.c
--- lib/libssl/src/apps/enc.c   14 Jul 2014 00:35:10 -  1.38
+++ lib/libssl/src/apps/enc.c   22 Jul 2014 05:15:04 -
@@ -600,17 +600,13 @@ end:
ERR_prin

PATCH: reallocarray in a few places in sys/

2014-07-21 Thread Doug Hogan
Use reallocarray() in a few places in sys.


Index: sys/arch/hppa/stand/mkboot/mkboot.c
===
RCS file: /cvs/src/sys/arch/hppa/stand/mkboot/mkboot.c,v
retrieving revision 1.18
diff -u -p -d -r1.18 mkboot.c
--- sys/arch/hppa/stand/mkboot/mkboot.c 22 Jan 2014 09:18:04 -  1.18
+++ sys/arch/hppa/stand/mkboot/mkboot.c 22 Jul 2014 01:11:23 -
@@ -204,10 +204,11 @@ putfile(char *from_file, int to)
if (n != sizeof (elf_header))
err(1, "%s: reading ELF header", from_file);
header_count = ntohs(elf_header.e_phnum);
-   memory_needed = header_count * sizeof (*elf_segments);
-   elf_segments = malloc(memory_needed);
+   elf_segments = reallocarray(NULL, header_count,
+   sizeof(*elf_segments));
if (elf_segments == NULL)
err(1, "malloc");
+   memory_needed = header_count * sizeof(*elf_segments);
(void) lseek(from, ntohl(elf_header.e_phoff), SEEK_SET);
n = read(from, elf_segments, memory_needed);
if (n != memory_needed)
Index: sys/arch/hppa64/stand/mkboot/mkboot.c
===
RCS file: /cvs/src/sys/arch/hppa64/stand/mkboot/mkboot.c,v
retrieving revision 1.4
diff -u -p -d -r1.4 mkboot.c
--- sys/arch/hppa64/stand/mkboot/mkboot.c   22 Jan 2014 09:26:55 -  
1.4
+++ sys/arch/hppa64/stand/mkboot/mkboot.c   22 Jul 2014 01:11:24 -
@@ -204,10 +204,11 @@ putfile(char *from_file, int to)
if (n != sizeof (elf_header))
err(1, "%s: reading ELF header", from_file);
header_count = betoh32(elf_header.e_phnum);
-   memory_needed = header_count * sizeof (*elf_segments);
-   elf_segments = malloc(memory_needed);
+   elf_segments = reallocarray(NULL, header_count,
+   sizeof(*elf_segments));
if (elf_segments == NULL)
err(1, "malloc");
+   memory_needed = header_count * sizeof(*elf_segments);
(void) lseek(from, betoh32(elf_header.e_phoff), SEEK_SET);
n = read(from, elf_segments, memory_needed);
if (n != memory_needed)
Index: sys/dev/microcode/bwi/extract/extract.c
===
RCS file: /cvs/src/sys/dev/microcode/bwi/extract/extract.c,v
retrieving revision 1.3
diff -u -p -d -r1.3 extract.c
--- sys/dev/microcode/bwi/extract/extract.c 12 Jul 2014 19:01:49 -  
1.3
+++ sys/dev/microcode/bwi/extract/extract.c 22 Jul 2014 01:14:43 -
@@ -53,7 +53,7 @@ main(int argc, char *argv[])
nfiles = ntohl(nfiles);
 
/* allocate space for header struct */
-   if ((h = malloc(nfiles * sizeof(*h))) == NULL)
+   if ((h = reallocarray(NULL, nfiles, sizeof(*h))) == NULL)
err(1, "malloc");
for (i = 0; i < nfiles; i++) {
if ((h[i] = malloc(sizeof(struct header))) == NULL)



LibreSSL 2.0.3 released

2014-07-21 Thread Bob Beck

We have released an update, LibreSSL 2.0.3 - which should
be arriving in the LibreSSL directory of an OpenBSD mirror near
you very soon. 

This release includes a number of portability fixes based on the
the feedback we have received from the community. It also includes
some improvements to the fork detection support. 

As noted before, we welcome feedback from the broader community.

Enjoy,  

-Bob
  



Re: res_random.c: 'static' is not at beginning of declaration

2014-07-21 Thread Theo de Raadt
revision 1.21
date: 2014/07/20 04:22:34;  author: guenther;  state: Exp;  lines: +2 -2;  
commitid: x7aBoxPF8nZvW5Z0;
>From ISO/IEC 9899:1999 and 9899:201x,
6.11.5 - Storage-class specifiers:
The placement of a storage-class specifier other than at the
beginning of the declaration specifiers in a declaration is
an obsolescent feature.

Diff from Jean-Philippe Ouellet (jean-philippe (at) ouellet.biz)


This got fixed a few days ago.




/etc/rc nit

2014-07-21 Thread Alex Holst
Shouldn't /etc/rc check for executable bits in these two cases?

Index: etc/rc
===
RCS file: /var/cvsync/src/etc/rc,v
retrieving revision 1.437
diff -u -p -r1.437 rc
--- etc/rc  19 Jul 2014 21:27:16 -  1.437
+++ etc/rc  21 Jul 2014 15:59:29 -
@@ -322,7 +322,7 @@ rm -f /fastboot # XXX (root now writeab
 echo 'setting tty flags'
 ttyflags -a
 
-if [ -f /sbin/kbd -a -f /etc/kbdtype ]; then
+if [ -x /sbin/kbd -a -f /etc/kbdtype ]; then
kbd `cat /etc/kbdtype`
 fi
 
@@ -485,7 +485,7 @@ if [ X"${accounting}" = X"YES" ]; then
echo 'turning on accounting';   accton /var/account/acct
 fi
 
-if [ -f /sbin/ldconfig ]; then
+if [ -x /sbin/ldconfig ]; then
echo 'creating runtime link editor directory cache.'
if [ -d /usr/local/lib ]; then
shlib_dirs="/usr/local/lib $shlib_dirs"



finger: Merge extern.h and finger.h

2014-07-21 Thread Tristan Le Guern
Hi,

This patch merges finger.h and extern.h, has they are always included
together. It also declares static functions as such and removes them
from the prototype list.

Index: finger.c
===
RCS file: /home/tleguern/proj/perso/cvs/src/usr.bin/finger/finger.c,v
retrieving revision 1.18
diff -u -p -r1.18 finger.c
--- finger.c12 Nov 2009 15:33:21 -  1.18
+++ finger.c21 Jul 2014 10:09:46 -
@@ -66,7 +66,9 @@
 #include 
 #include 
 #include "finger.h"
-#include "extern.h"
+
+static void loginlist(void);
+static void userlist(int, char **);

 time_t now;
 int entries, lflag, sflag, mflag, oflag, pplan, Mflag;
@@ -158,7 +160,7 @@ main(int argc, char *argv[])
exit(0);
 }

-void
+static void
 loginlist(void)
 {
PERSON *pn;
@@ -184,7 +186,7 @@ loginlist(void)
enter_lastlog(pn);
 }

-void
+static void
 userlist(int argc, char **argv)
 {
int i;
Index: finger.h
===
RCS file: /home/tleguern/proj/perso/cvs/src/usr.bin/finger/finger.h,v
retrieving revision 1.6
diff -u -p -r1.6 finger.h
--- finger.h15 Mar 2004 02:50:29 -  1.6
+++ finger.h21 Jul 2014 10:20:20 -
@@ -77,3 +77,26 @@ typedef struct where {

 extern PERSON *htab[HSIZE];/* the buckets */
 extern PERSON *phead, *ptail;  /* the linked list of all people */
+
+extern time_t now; /* Current time. */
+extern char tbuf[1024];/* Temp buffer for anybody. */
+extern int entries;/* Number of people. */
+extern int lflag;
+extern int oflag;
+extern int pplan;
+
+struct storage;
+
+voidenter_lastlog(PERSON *);
+PERSON *enter_person(struct passwd *);
+voidenter_where(struct utmp *, PERSON *);
+PERSON *find_person(char *);
+voidlflag_print(void);
+int match(struct passwd *, char *);
+voidnetfinger(char *);
+PERSON *palloc(void);
+char   *prphone(char *);
+voidsflag_print(void);
+char   *vs(struct storage **, char *);
+voidfree_storage(struct storage *);
+
Index: lprint.c
===
RCS file: /home/tleguern/proj/perso/cvs/src/usr.bin/finger/lprint.c,v
retrieving revision 1.10
diff -u -p -r1.10 lprint.c
--- lprint.c27 Oct 2009 23:59:38 -  1.10
+++ lprint.c21 Jul 2014 10:10:38 -
@@ -44,13 +44,17 @@
 #include 
 #include 
 #include "finger.h"
-#include "extern.h"

 #defineLINE_LEN80
 #defineTAB_LEN 8   /* 8 spaces between tabs */
 #define_PATH_PLAN  ".plan"
 #define_PATH_PROJECT   ".project"

+static int  demi_print(char *, int);
+static void lprint(PERSON *);
+static int  show_text(char *, char *, char *);
+static void vputc(int);
+
 void
 lflag_print(void)
 {
@@ -69,7 +73,7 @@ lflag_print(void)
}
 }

-void
+static void
 lprint(PERSON *pn)
 {
struct tm *delta;
@@ -220,7 +224,7 @@ lprint(PERSON *pn)
}
 }

-int
+static int
 demi_print(char *str, int oddfield)
 {
static int lenlast;
@@ -258,7 +262,7 @@ demi_print(char *str, int oddfield)
return (oddfield);
 }

-int
+static int
 show_text(char *directory, char *file_name, char *header)
 {
int ch, lastc;
@@ -277,7 +281,7 @@ show_text(char *directory, char *file_na
return (1);
 }

-void
+static void
 vputc(int ch)
 {
char visout[5], *s2;
Index: net.c
===
RCS file: /home/tleguern/proj/perso/cvs/src/usr.bin/finger/net.c,v
retrieving revision 1.12
diff -u -p -r1.12 net.c
--- net.c   27 Oct 2009 23:59:38 -  1.12
+++ net.c   21 Jul 2014 09:56:12 -
@@ -43,7 +43,6 @@
 #include 
 #include 
 #include "finger.h"
-#include "extern.h"

 void
 netfinger(name)
Index: sprint.c
===
RCS file: /home/tleguern/proj/perso/cvs/src/usr.bin/finger/sprint.c,v
retrieving revision 1.13
diff -u -p -r1.13 sprint.c
--- sprint.c27 Oct 2009 23:59:38 -  1.13
+++ sprint.c21 Jul 2014 10:11:51 -
@@ -40,7 +40,10 @@
 #include 
 #include 
 #include "finger.h"
-#include "extern.h"
+
+static int   psort(const void *, const void *);
+static PERSON  **sort(void);
+static void  stimeprint(WHERE *);

 void
 sflag_print(void)
@@ -130,7 +133,7 @@ office:
}
 }

-PERSON **
+static PERSON **
 sort(void)
 {
PERSON *pn, **lp;
@@ -144,13 +147,13 @@ sort(void)
return (list);
 }

-int
+static int
 psort(const void *p, const void *t)
 {
return (strcmp((*(PERSON **)p)->name, (*(PERSON **)t)->name));
 }

-void
+static void
 stimeprint(WHERE *w)
 {
struct tm *delta;
Index: util.c
===
RCS file: /home/tleguern/proj/perso/cvs/src/usr.bin/finger/util.c,v
retrieving revision 1.24
diff -u 

finger: Add a dedicated usage()

2014-07-21 Thread Tristan Le Guern
Hi,

This patch adds a dedicated usage() function to finger(1), like most
other utilities do.

It also removes the unnecessary declaration of optind.

Index: finger.c
===
RCS file: /home/tleguern/proj/perso/cvs/src/usr.bin/finger/finger.c,v
retrieving revision 1.18
diff -u -p -r1.18 finger.c
--- finger.c12 Nov 2009 15:33:21 -  1.18
+++ finger.c21 Jul 2014 10:40:00 -
@@ -68,6 +68,8 @@
 #include "finger.h"
 #include "extern.h"

+__dead void usage(void);
+
 time_t now;
 int entries, lflag, sflag, mflag, oflag, pplan, Mflag;
 char tbuf[1024];
@@ -77,8 +79,6 @@ PERSON *phead, *ptail;
 int
 main(int argc, char *argv[])
 {
-   extern int optind;
-   extern char *__progname;
int ch;
char domain[MAXHOSTNAMELEN];
struct stat sb;
@@ -109,10 +109,10 @@ main(int argc, char *argv[])
oflag = 1;  /* office info */
break;
case '?':
+   /* FALLTHROUGH */
default:
-   (void)fprintf(stderr,
-   "usage: %s [-hlMmops] [login ...]\n", __progname);
-   exit(1);
+   usage();
+   /* NOTREACHED */
}
argc -= optind;
argv += optind;
@@ -265,3 +265,12 @@ net:   for (pn = nethead; pn; pn = pn->nex
for (pn = phead; pn != NULL; pn = pn->next)
enter_lastlog(pn);
 }
+
+void
+usage(void)
+{
+   (void)fprintf(stderr,
+   "usage: %s [-hlMmops] [login ...]\n", getprogname());
+   exit(1);
+}
+



PATCH: overflow behavior in malloc(9)

2014-07-21 Thread Doug Hogan
Make it clear what check implies for mallocarray.  Thanks to dlg@ for
pointing this behavior out.


Index: share/man/man9/malloc.9
===
RCS file: /cvs/src/share/man/man9/malloc.9,v
retrieving revision 1.56
diff -u -p -d -r1.56 malloc.9
--- share/man/man9/malloc.9 12 Jul 2014 18:51:10 -  1.56
+++ share/man/man9/malloc.9 21 Jul 2014 06:39:36 -
@@ -57,7 +57,9 @@ function is the same as
 .Fn malloc ,
 except it allocates space for an array of
 .Fa nmemb
-objects and checks for arithmetic overflow.
+objects and calls
+.Xr panic 9
+on arithmetic overflow.
 .Pp
 The
 .Fn free