klange / nyancat

Nyancat in your terminal, rendered through ANSI escape sequences. This is the source for the Debian package `nyancat`.
http://nyancat.dakko.us/
1.45k stars 135 forks source link

SegFault if TERM variable is not set #13

Closed froller closed 12 years ago

froller commented 12 years ago

If neither TERM variable set nor -t option given nyancat crashes with SIG_SEGV.

Probably it does 'cause at nyancat.c:353 it tries to strcpy() from null-pointer nterm.

froller commented 12 years ago

Here's the patch

--- a/src/nyancat.c
+++ b/src/nyancat.c
@@ -350,7 +350,8 @@ int main(int argc, char ** argv) {
                /* We are running standalone, retrieve the
                 * terminal type from the environment. */
                char * nterm = getenv("TERM");
-               strcpy(term, nterm);
+               if (nterm)
+                       strcpy(term, nterm);
        }

        /*
klange commented 12 years ago

Huh. I thought I already merged a commit that "fixed" this (it's not necessarily a bug, having $TERM set is mandatory, so says POSIX.1-2008).

Send a pull request with this patch.

froller commented 12 years ago

xinetd probably doesn't respect POSIX.1-2008 and I got segfaults running nyancat with xinetd. Nevertheless reading from null-pointer is not quite a good practice.

klange commented 12 years ago

If you're running under xinetd, you really need to get that -t option passed ;)