[Xorp-hackers] fix for xorpsh if TERM env variable is not set
Pavlin Radoslavov
pavlin at icir.org
Mon Aug 21 12:43:03 PDT 2006
> Here's a small fix for the xorpsh when the TERM environmental variable is not set:
>
> --- cli_node_net.cc_orig 2006-08-21 10:21:52.000000000 -0700
> +++ cli_node_net.cc 2006-08-21 10:17:53.000000000 -0700
> @@ -514,8 +514,8 @@
>
> ; // do nothing
> #else
> - term_name = getenv("TERM");
> - if (term_name.empty())
> + char *term = getenv("TERM");
> + if (term == NULL || string(term).empty() == true)
> term_name = DEFAULT_TERM_TYPE; // Set to default
> #endif
> }
>
> The getenv is returning a NULL ptr which causes a crash when the
> assignment is applied to the string term_name. The fix is to check
> for NULL prior to testing for an empty string.
Yes, it is a bug, though the fix should be slightly different so
term_name is properly assigned if TERM is valid. E.g., see the
following patch (note that term_name was set its default value
before this code is reached):
Index: cli_node_net.cc
===================================================================
RCS file: /usr/local/share/doc/apache/cvs/xorp/cli/cli_node_net.cc,v
retrieving revision 1.52
diff -u -p -r1.52 cli_node_net.cc
--- cli_node_net.cc 24 Jul 2006 21:25:42 -0000 1.52
+++ cli_node_net.cc 21 Aug 2006 19:37:57 -0000
@@ -514,9 +514,9 @@ CliClient::start_connection(string& erro
; // do nothing
#else
- term_name = getenv("TERM");
- if (term_name.empty())
- term_name = DEFAULT_TERM_TYPE; // Set to default
+ char *term = getenv("TERM");
+ if ((term != NULL) && (! string(term).empty()))
+ term_name = string(term);
#endif
}
Anyway, I committed the fix to CVS:
Revision Changes Path
1.53 +4 -4; commitid: d0f144ea0af37ea6; xorp/cli/cli_node_net.cc
Thanks,
Pavlin
More information about the Xorp-hackers
mailing list