summaryrefslogtreecommitdiff
path: root/zhm/zhm.c
diff options
context:
space:
mode:
authorGravatar John Kohl <jtkohl@mit.edu>1989-03-23 04:25:18 +0000
committerGravatar John Kohl <jtkohl@mit.edu>1989-03-23 04:25:18 +0000
commitc752761b7c46e65a3c49a6327f840f48e02bf2a6 (patch)
tree4c089c12dfc41b8105635d20b67f9f3cc7048481 /zhm/zhm.c
parent8d5c5935b03ba589e04ec0d14e5f8f35f4bb0e1e (diff)
Fix printing of unknown server names
avoid div0 and/or random array indexing when j is not initialized
Diffstat (limited to 'zhm/zhm.c')
-rw-r--r--zhm/zhm.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/zhm/zhm.c b/zhm/zhm.c
index 992be05..16aa493 100644
--- a/zhm/zhm.c
+++ b/zhm/zhm.c
@@ -60,7 +60,7 @@ char *argv[];
Code_t ret;
int opt, pak_len;
extern int optind;
- register int i, j;
+ register int i, j = 0;
if (gethostname(hostname, MAXHOSTNAMELEN) < 0) {
printf("Can't find my hostname?!\n");
@@ -99,7 +99,7 @@ char *argv[];
/* Override server argument? */
if (optind < argc) {
if ((hp = gethostbyname(argv[optind++])) == NULL) {
- printf("Unknown server name: %s\n", prim_serv);
+ printf("Unknown server name: %s\n", argv[optind-1]);
} else
(void) strcpy(prim_serv, hp->h_name);
/* argc-optind is the # of other servers on the command line */
@@ -179,7 +179,7 @@ char *argv[];
clust_info[j] = NULL;
serv_list = clust_info;
}
- if (!prim_serv[0]) {
+ if (!prim_serv[0] && j) {
srandom(time((long *) 0));
(void) strcpy(prim_serv, serv_list[random() % j]);
}