gethostbyname(3) MAXADDRS/ALIASES bug.

2015-03-01 Thread Bryan Steele
It seems gethostbyname(3) fails if the answer returned is too big, for
example "chat.freenode.net" contains a lot of records that will easily
trigger this.

This was introduced as part of the asr libc resolver rewrite.

$ ping chat.freenode.net
ping: unknown host: chat.freenode.net
$ host chat.freenode.net | wc -l
22
$ 

I've doubled the value for MAXALIASES/MAXADDRS, which is closer
to the original of 35 (..in the Attic)

ok?

Index: gethostnamadr_async.c
===
RCS file: /cvs/src/lib/libc/asr/gethostnamadr_async.c,v
retrieving revision 1.34
diff -u -p -u -r1.34 gethostnamadr_async.c
--- gethostnamadr_async.c   16 Jan 2015 16:48:51 -  1.34
+++ gethostnamadr_async.c   1 Mar 2015 22:52:17 -
@@ -41,8 +41,8 @@
 
 #include "asr_private.h"
 
-#define MAXALIASES 16
-#define MAXADDRS   16
+#define MAXALIASES 32
+#define MAXADDRS   32
 
 struct hostent_ext {
struct hostent   h;



df: division by zero on invalid ext2fs

2015-03-01 Thread Tobias Stoeckmann
Hi,

it is possible to trigger a floating point exception in df when it is
used to retrieve information from a raw device with a broken ext2
file system.

These are steps to prepare a file system with an invalid entry for
"e2fs_log_bsize" (0xFF):

$ dd if=/dev/zero of=ext2.fs bs=1K count=1440
# vnconfig vnd0c ext2.fs
# newfs_ext2fs -I vnd0c
$ dd if=/dev/zero bs=1 count=4 | tr '\0' '\777' | \
>dd of=ext2.fs conv=notrunc seek=1048 bs=1 count=4

If this raw device is accessed with df, the call will result in a
floating point exception:

$ df /dev/vnd0c
Floating point exception (core dumped)

With applied diff, the raw device is considered invalid, which leads to
same behavior as with unknown file systems:

$ /usr/obj/bin/df/df /dev/vnd0c
$ echo $?
1

The fix is simple: Avoid division by zero by explicitly checking that
we won't divide by zero. The results can always be weird with broken
file systems, but at least df won't crash.


Tobias

Index: ext2fs_df.c
===
RCS file: /cvs/src/bin/df/ext2fs_df.c,v
retrieving revision 1.12
diff -u -p -r1.12 ext2fs_df.c
--- bin/df/ext2fs_df.c  16 Jan 2015 06:39:31 -  1.12
+++ bin/df/ext2fs_df.c  1 Mar 2015 11:09:42 -
@@ -77,8 +77,9 @@ e2fs_df(int rfd, char *file, struct stat
sfsp->f_bsize = 1024 << sblock.e2fs_log_bsize;
sfsp->f_iosize = 1024 << sblock.e2fs_log_bsize;
 
-   ipb = sfsp->f_bsize / sizeof(struct ext2fs_dinode);
-   itpg = sblock.e2fs_ipg/ipb;
+   if ((ipb = sfsp->f_bsize / sizeof(struct ext2fs_dinode)) == 0)
+   return (-1);
+   itpg = sblock.e2fs_ipg / ipb;
 
ncg = howmany(sblock.e2fs_bcount - sblock.e2fs_first_dblock,
sblock.e2fs_bpg);



pax/tar/cpio: use stdout if TAPE is set to -

2015-03-01 Thread Dmitrij D. Czarkoff
Hi!

The diff below makes tar treat "-" in TAPE environment variable as
stdout, making it consistant with "-f" argument.  Could be a sane
default for those who have no tape device.

-- 
Dmitrij D. Czarkoff

Index: bin/pax/options.c
===
RCS file: /var/cvs/src/bin/pax/options.c,v
retrieving revision 1.86
diff -u -p -r1.86 options.c
--- bin/pax/options.c   24 May 2014 18:51:00 -  1.86
+++ bin/pax/options.c   1 Mar 2015 08:27:13 -
@@ -1006,6 +1006,8 @@ tar_options(int argc, char **argv)
arcname = getenv("TAPE");
if ((arcname == NULL) || (*arcname == '\0'))
arcname = _PATH_DEFTAPE;
+   else if ((arcname[0] == '-') && (arcname[1]== '\0'))
+   arcname = NULL;
}
 }