Skip to content

Commit

Permalink
Fix empty hostname bug
Browse files Browse the repository at this point in the history
The read statement will evaulate the lines[n++] expression for
each line in the input wordlist that does not start with #. It
will however also evaluate the expression when it reads an EOF
from the stream. This means that n will equal the number of
entries in lines plus one, which in turn means that when rand
returns n-1 in r, the resulting line will be empty.

Signed-off-by: Jonas Eriksson <zqad@acc.umu.se>
  • Loading branch information
zqad authored and elasticdog committed Sep 22, 2014
1 parent 8412bfe commit 1ff2ba8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions genhost
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ fi
# read the word list into memory, removing commented words
unset lines n
while IFS= read -r 'lines[n++]'; do :; done < <(sed '/^#/d' "$wordlist")
# since $n gets incremented even by the EOF character, remove 1 from n
n=$(( n - 1 ))

# output the random hostname(s)
for i in $(seq $1); do
Expand Down

0 comments on commit 1ff2ba8

Please sign in to comment.