Bug 2144

Summary: Segmentation fault from fwrite()
Product: netanim Reporter: zhuzhenglu <pan2za>
Component: animatorAssignee: John Abraham <john.abraham.in>
Status: RESOLVED INVALID    
Severity: normal CC: ns-bugs
Priority: P5    
Version: unspecified   
Hardware: PC   
OS: Linux   
Attachments: revised DCE quagga example

Description zhuzhenglu 2015-06-24 22:37:33 UTC
Created attachment 2073 [details]
revised DCE quagga example

Using the attached example will cause the segmentation fault of fwrite()
The attached file is a revised example from DCE.

Program received signal SIGSEGV, Segmentation fault.
0x000000318a66798a in fwrite () from /lib64/libc.so.6
(gdb) bt
#0  0x000000318a66798a in fwrite () from /lib64/libc.so.6
#1  0x00007ffff54adb5c in ns3::AnimationInterface::WriteN (this=0x7fffffffcb20, data=0x72bc98 "</anim>\n", count=8, f=0x777800)
    at ../src/netanim/model/animation-interface.cc:508
#2  0x00007ffff54adb01 in ns3::AnimationInterface::WriteN (this=0x7fffffffcb20, st=..., f=0x777800) at ../src/netanim/model/animation-interface.cc:494
#3  0x00007ffff54c40aa in ns3::AnimationInterface::WriteXmlClose (this=0x7fffffffcb20, name=..., routing=false) at ../src/netanim/model/animation-interface.cc:2062
#4  0x00007ffff54b8230 in ns3::AnimationInterface::StopAnimation (this=0x7fffffffcb20, onlyAnimation=false) at ../src/netanim/model/animation-interface.cc:1271
#5  0x00007ffff54a9e20 in ns3::AnimationInterface::~AnimationInterface (this=0x7fffffffcb20, __in_chrg=<optimized out>) at ../src/netanim/model/animation-interface.cc:87
#6  0x000000000041158f in main (argc=2, argv=0x7fffffffda38) at ../myscripts/ns-3-dce-quagga/example/dce-zebra-simple.cc:221
(gdb) 


(gdb) frame 1
#1  0x00007ffff54adb5c in ns3::AnimationInterface::WriteN (this=0x7fffffffcb20, data=0x72bc98 "</anim>\n", count=8, f=0x777800)
    at ../src/netanim/model/animation-interface.cc:508
508	      int n = std::fwrite (p, 1,  nLeft, f);
(gdb) p p
$1 = 0x72bc98 "</anim>\n"
(gdb) p nLeft 
$2 = 8
(gdb) p f
$3 = (FILE *) 0x777800
(gdb) 
(gdb) l
503	  uint32_t    nLeft   = count;
504	  const char* p       = data;
505	  uint32_t    written = 0;
506	  while (nLeft)
507	    {
508	      int n = std::fwrite (p, 1,  nLeft, f);
509	      if (n <= 0) 
510	        {
511	          return written;
512	        }
(gdb) 
513	      written += n;
514	      nLeft -= n;
515	      p += n;
516	    }
517	  return written;
518	}
519	
520	void 
521	AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements)
522	{
(gdb) 


About my system:

OS: Centos65, Linux gdc1000 2.6.32-504.8.1.el6.x86_64 #1 SMP Wed Jan 28 21:11:36 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
GCC:
[root@gdc1000 example]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.8.2/configure
Thread model: posix
gcc version 4.8.2 (GCC) 
[root@gdc1000 example]#
Comment 1 zhuzhenglu 2015-06-24 22:38:32 UTC
netanim revision : 3.106
Comment 2 John Abraham 2015-06-25 23:57:51 UTC
Hi, 

1. Can you give your dce and quagga version?
2. Can you try a this code in your example to see if basic file write works
  #include <cstdio>
  FILE * f = std::fopen ("test.xml", "w");
  std::fwrite ("some content", 1,  13, f);
  std::fclose (f);



I could not reproduce it on mine


Waf: Leaving directory `/home/john/ns3/dce/dce/source/ns-3-dce/build'
'build' finished successfully (4.010s)
Process exit path=/NodeList/8/$ns3::DceManager/Exit pid=23939 retcode=0
Process exit path=/NodeList/0/$ns3::DceManager/Exit pid=39061 retcode=256
Packet Number:0
Real duration : 40
DataRate:588235
Packets / second :0
Bytes / second0
Ratio : 0
KO 0 TAKE MORE TIME THAT REALITY
Packet Number:0
Real duration : 46
DataRate:588235
Packets / second :0
Bytes / second0
Ratio : 0
KO 0 TAKE MORE TIME THAT REALITY
Packet Number:0
Real duration : 41
DataRate:588235
Packets / second :0
Bytes / second0
Ratio : 0
KO 0 TAKE MORE TIME THAT REALITY
Packet Number:0
Real duration : 50
DataRate:588235
Packets / second :0
Bytes / second0
Ratio : 0
KO 0 TAKE MORE TIME THAT REALITY

john@john-VirtualBox:~/ns3/dce/dce/source/ns-3-dce$ ls *.xml
simple-anim.xml  simple-tracking.xml  test.xml
Comment 3 John Abraham 2016-01-05 22:31:45 UTC
Please re-open if seen again