svn commit: r306911 - stable/9/usr.sbin/fifolog/lib

Pedro F. Giffuni pfg at FreeBSD.org
Sun Oct 9 19:59:22 UTC 2016


Author: pfg
Date: Sun Oct  9 19:59:20 2016
New Revision: 306911
URL: https://svnweb.freebsd.org/changeset/base/306911

Log:
  MFC r305812:
  
  fifolog(1): invert order of calloc(3) arguments.
  
  The second argument to calloc(3) should be the size, make it so.
  
  While here be a little bit more cautious in fifolog_reader_open()
  to protect in the unlikely event of an overflowed allocation.

Modified:
  stable/9/usr.sbin/fifolog/lib/fifolog_create.c
  stable/9/usr.sbin/fifolog/lib/fifolog_reader.c
  stable/9/usr.sbin/fifolog/lib/fifolog_write_poll.c
  stable/9/usr.sbin/fifolog/lib/miniobj.h

Modified: stable/9/usr.sbin/fifolog/lib/fifolog_create.c
==============================================================================
--- stable/9/usr.sbin/fifolog/lib/fifolog_create.c	Sun Oct  9 19:58:27 2016	(r306910)
+++ stable/9/usr.sbin/fifolog/lib/fifolog_create.c	Sun Oct  9 19:59:20 2016	(r306911)
@@ -97,7 +97,7 @@ fifolog_create(const char *fn, off_t siz
 	if (S_ISREG(st.st_mode) && ftruncate(fd, size) < 0)
 		return ("Could not ftrunc");
 
-	buf = calloc(recsize, 1);
+	buf = calloc(1, recsize);
 	if (buf == NULL)
 		return ("Could not malloc");
 

Modified: stable/9/usr.sbin/fifolog/lib/fifolog_reader.c
==============================================================================
--- stable/9/usr.sbin/fifolog/lib/fifolog_reader.c	Sun Oct  9 19:58:27 2016	(r306910)
+++ stable/9/usr.sbin/fifolog/lib/fifolog_reader.c	Sun Oct  9 19:59:20 2016	(r306911)
@@ -67,10 +67,10 @@ fifolog_reader_open(const char *fname)
 	if (retval != NULL)
 		err(1, "%s", retval);
 
-	fr->olen = fr->ff->recsize * 16;
-	fr->obuf = calloc(fr->olen, 1);
+	fr->obuf = calloc(16, fr->ff->recsize);
 	if (fr->obuf == NULL)
 		err(1, "Cannot malloc");
+	fr->olen = fr->ff->recsize * 16;
 
 	i = inflateInit(fr->ff->zs);
 	assert(i == Z_OK);

Modified: stable/9/usr.sbin/fifolog/lib/fifolog_write_poll.c
==============================================================================
--- stable/9/usr.sbin/fifolog/lib/fifolog_write_poll.c	Sun Oct  9 19:58:27 2016	(r306910)
+++ stable/9/usr.sbin/fifolog/lib/fifolog_write_poll.c	Sun Oct  9 19:59:20 2016	(r306911)
@@ -45,7 +45,7 @@
 static int fifolog_write_gzip(struct fifolog_writer *f, time_t now);
 
 #define ALLOC(ptr, size) do {                   \
-	(*(ptr)) = calloc(size, 1);             \
+	(*(ptr)) = calloc(1, size);             \
 	assert(*(ptr) != NULL);                 \
 } while (0)
 

Modified: stable/9/usr.sbin/fifolog/lib/miniobj.h
==============================================================================
--- stable/9/usr.sbin/fifolog/lib/miniobj.h	Sun Oct  9 19:58:27 2016	(r306910)
+++ stable/9/usr.sbin/fifolog/lib/miniobj.h	Sun Oct  9 19:59:20 2016	(r306911)
@@ -28,7 +28,7 @@
 
 #define ALLOC_OBJ(to, type_magic)					\
 	do {								\
-		(to) = calloc(sizeof *(to), 1);				\
+		(to) = calloc(1, sizeof *(to));				\
 		if ((to) != NULL)					\
 			(to)->magic = (type_magic);			\
 	} while (0)


More information about the svn-src-stable-9 mailing list