diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-08 11:52:44 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-08 11:52:44 +0000 |
commit | 4ef5e2ba9546c3092a5abd7085b2371e3169c23d (patch) | |
tree | 8459df1312afa4e0bf5fa64d790eb4af93d5d377 | |
parent | f075da7a8927f75bc643254ead167bd9620aee1e (diff) | |
download | gnunet-4ef5e2ba9546c3092a5abd7085b2371e3169c23d.tar.gz gnunet-4ef5e2ba9546c3092a5abd7085b2371e3169c23d.zip |
- limit hostname as gethostname() has undefined behavior when hostname exceeds
- the given length
-rw-r--r-- | src/testbed/gnunet-service-testbed_cpustatus.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c index e024e8c38..77ba30c13 100644 --- a/src/testbed/gnunet-service-testbed_cpustatus.c +++ b/src/testbed/gnunet-service-testbed_cpustatus.c | |||
@@ -642,7 +642,8 @@ GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
642 | char *hostname; | 642 | char *hostname; |
643 | char *stats_dir; | 643 | char *stats_dir; |
644 | char *fn; | 644 | char *fn; |
645 | 645 | size_t len; | |
646 | |||
646 | #if MINGW | 647 | #if MINGW |
647 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 648 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
648 | "Load statistics logging now available for windows\n"); | 649 | "Load statistics logging now available for windows\n"); |
@@ -653,17 +654,20 @@ GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
653 | GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", | 654 | GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", |
654 | "STATS_DIR", &stats_dir)) | 655 | "STATS_DIR", &stats_dir)) |
655 | return; | 656 | return; |
656 | hostname = GNUNET_malloc (GNUNET_OS_get_hostname_max_length ()); | 657 | len = GNUNET_OS_get_hostname_max_length (); |
657 | if (0 != gethostname (hostname, GNUNET_OS_get_hostname_max_length ())) | 658 | hostname = GNUNET_malloc (len); |
659 | if (0 != gethostname (hostname, len)) | ||
658 | { | 660 | { |
659 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname"); | 661 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname"); |
660 | GNUNET_free (stats_dir); | 662 | GNUNET_free (stats_dir); |
663 | GNUNET_free (hostname); | ||
661 | return; | 664 | return; |
662 | } | 665 | } |
663 | fn = NULL; | 666 | fn = NULL; |
664 | (void) GNUNET_asprintf (&fn, "%s/%s-%jd.dat", stats_dir, | 667 | (void) GNUNET_asprintf (&fn, "%s/%.*s-%jd.dat", stats_dir, len, |
665 | hostname, (intmax_t) getpid()); | 668 | hostname, (intmax_t) getpid()); |
666 | GNUNET_free (stats_dir); | 669 | GNUNET_free (stats_dir); |
670 | GNUNET_free (hostname); | ||
667 | if (NULL == (bw = GNUNET_BIO_write_open (fn))) | 671 | if (NULL == (bw = GNUNET_BIO_write_open (fn))) |
668 | { | 672 | { |
669 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 673 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |