Subject: uucp patch for division by zero
To: None <tech-userlevel@netbsd.org>
From: Ignatios Souvatzis <is@netbsd.org>
List: tech-userlevel
Date: 04/27/2001 23:15:22
Hi,
I've been hit by the uucp over pipe leads to div by zero bug, so I looked up,
didn't find, asked on the uucp list and got the mail forwarded ...
basically, sometimes q->ibaud is zero in this case, and uucp divides by it to
generate a reasonable timeout value for select() and friends, when it needs
one.
I've tried a (simplified) patch for this, similar to the one originally
suggested by Felix Schroeter, and it surely cures my problem.
Here's the diff --- any objections?
Regards,
-is
Index: libunix/serial.c
===================================================================
RCS file: /cvsroot/gnusrc/gnu/libexec/uucp/libunix/serial.c,v
retrieving revision 1.5
diff -u -r1.5 serial.c
--- libunix/serial.c 1998/02/14 07:25:55 1.5
+++ libunix/serial.c 2001/04/27 21:08:48
@@ -2376,7 +2376,7 @@
else
csleepchars = MAX_INPUT - 10;
- isleep = (int) (((long) csleepchars * 10000L) / q->ibaud);
+ isleep = q->ibaud ? (int) (((long) csleepchars * 10000L) / q->ibaud) : 1;
isleep -= 10;
if (isleep > 10)
@@ -2778,9 +2778,14 @@
/ baud bits/sec)
* 10 bits/byte)
*/
- stime.tv_sec = (long) 10240 / q->ibaud;
- stime.tv_usec = ((((long) 1024000000 / q->ibaud) * (long) 10)
- % (long) 1000000);
+ if (q->ibaud) {
+ stime.tv_sec = (long) 10240 / q->ibaud;
+ stime.tv_usec = ((((long) 1024000000 / q->ibaud) * (long) 10)
+ % (long) 1000000);
+ } else {
+ stime.tv_sec = 1;
+ stime.tv_usec = 0;
+ }
imask = 1 << q->o;
if (imask == 0)
@@ -2851,7 +2856,7 @@
we don't need to use the catch stuff, since we know
that HAVE_RESTARTABLE_SYSCALLS is 0. */
usset_signal (SIGALRM, usalarm, TRUE, (boolean *) NULL);
- alarm ((int) ((long) 10240 / q->ibaud) + 1);
+ alarm ( q->ibaud ? (int) ((long) 10240 / q->ibaud) + 1 : 1);
/* There is a race condition here: on a severely loaded
system, we could get the alarm before we start the