Running ADSserver fails with SEGFAULT

94 views
Skip to first unread message

Ronny Schröder

unread,
Mar 5, 2013, 4:16:48 PM3/5/13
to beckhof...@googlegroups.com
Hi,

I compiled the libads package downloaded from github.
When I try to run the ADSserver from examples folder the binary crashes immediately after startup:

See the log running ADSserver with gdb:
> Starting program: /.../libads-master/examples/.libs/ADSserver 48898
> [Thread debugging using libthread_db enabled]
>
> Breakpoint 1, ADSGetLocalAMSId (id=0x804b228) at ads.c:833
> 833 {
> (gdb) n
> 839 if (getifaddrs(&list) < 0) {
> (gdb)
> 844 for (cur = list; cur != NULL; cur = cur->ifa_next) {
> (gdb)
> 846 && (strcmp(cur->ifa_name, "lo") != 0)) {
> (gdb)
> 844 for (cur = list; cur != NULL; cur = cur->ifa_next) {
> (gdb)
> 845 if ((cur->ifa_addr->sa_family == AF_INET)
> (gdb)
> 857 if (cur->ifa_next == NULL)
> (gdb)
> 844 for (cur = list; cur != NULL; cur = cur->ifa_next) {
> (gdb)
> 845 if ((cur->ifa_addr->sa_family == AF_INET)
> (gdb)
> 857 if (cur->ifa_next == NULL)
> (gdb)
> 844 for (cur = list; cur != NULL; cur = cur->ifa_next) {
> (gdb)
> 845 if ((cur->ifa_addr->sa_family == AF_INET)
> (gdb)
> 857 if (cur->ifa_next == NULL)
> (gdb)
> 844 for (cur = list; cur != NULL; cur = cur->ifa_next) {
> (gdb)
> 845 if ((cur->ifa_addr->sa_family == AF_INET)
> (gdb)
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x0012f8ab in ADSGetLocalAMSId (id=0x804b228) at ads.c:845
> 845 if ((cur->ifa_addr->sa_family == AF_INET)

System: Reelbox (generic x86 linux PC running ubuntu)

Any ideas what I am doing wrong here?

BR Ronny

Håkon Nessjøen

unread,
Mar 6, 2013, 3:50:32 AM3/6/13
to beckhof...@googlegroups.com
Do a check that:

cur->ifa_addr != NULL before checking cur->ifa_addr->sa_family == AF_INET
--
You received this message because you are subscribed to the Google Groups "Beckhoff Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beckhoff-linu...@googlegroups.com.
To post to this group, send email to beckhof...@googlegroups.com.
Visit this group at http://groups.google.com/group/beckhoff-linux?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




--
Håkon

Luis Matos

unread,
Mar 6, 2013, 10:57:14 AM3/6/13
to beckhof...@googlegroups.com
I'll add that check in the code!

Thanks!
Do a check that:

To unsubscribe from this group and stop receiving emails from it, send an email to beckhoff-linux+unsubscribe@googlegroups.com.
To post to this group, send email to beckhoff-linux@googlegroups.com.


--
Håkon

Luis Matos

unread,
Mar 7, 2013, 11:53:05 AM3/7/13
to beckhof...@googlegroups.com
can it be like this:
diff --git a/src/ads.c b/src/ads.c
index 2f0e1a1..3a14e3c 100755
@@ -842,6 +842,9 @@ int ADSGetLocalAMSId(AMSNetID * id)
 
     struct ifaddrs *cur;

     for (cur = list; cur != NULL; cur = cur->ifa_next) {
+        if (cur->ifa_addr == NULL) {
+            break;
+        }

         if ((cur->ifa_addr->sa_family == AF_INET)
             && (strcmp(cur->ifa_name, "lo") != 0)) {
             addrStruct = (struct sockaddr_in *)cur->ifa_addr;

if ifa_addr is null, it means that it is an ethernet link that is down, right?

Cheers,
Luis Matos

Ronny Schroeder

unread,
Mar 7, 2013, 3:35:05 PM3/7/13
to beckhof...@googlegroups.com
Hi Luis,

Am Donnerstag, 7. März 2013 17:53:05 UTC+1 schrieb Luis Matos:
can it be like this:
diff --git a/src/ads.c b/src/ads.c
index 2f0e1a1..3a14e3c 100755
@@ -842,6 +842,9 @@ int ADSGetLocalAMSId(AMSNetID * id)
 
     struct ifaddrs *cur;
     for (cur = list; cur != NULL; cur = cur->ifa_next) {
+        if (cur->ifa_addr == NULL) {
+            break;
+        }
         if ((cur->ifa_addr->sa_family == AF_INET)
             && (strcmp(cur->ifa_name, "lo") != 0)) {
             addrStruct = (struct sockaddr_in *)cur->ifa_addr;


Great this fix works fine.
 
if ifa_addr is null, it means that it is an ethernet link that is down, right?

No idea, but in my case it was this tun device:
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:192.168.99.130  P-t-P:192.168.99.130  Mask:255.255.255.252
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:8300  Metric:1
          RX packets:1057 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1056 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:33847 (33.8 KB)  TX bytes:574017 (574.0 KB)

BR Ronny

Håkon Nessjøen

unread,
Mar 7, 2013, 5:59:14 PM3/7/13
to beckhof...@googlegroups.com
You should not "break" it, but "continue;"

If you break, it will not find any more interfaces after the first interface without an address.

Håkon
--
You received this message because you are subscribed to the Google Groups "Beckhoff Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beckhoff-linu...@googlegroups.com.
To post to this group, send email to beckhof...@googlegroups.com.


--
Håkon

Luis Matos

unread,
Mar 7, 2013, 6:49:32 PM3/7/13
to beckhof...@googlegroups.com
True ... my bad.
Uploaded.
To unsubscribe from this group and stop receiving emails from it, send an email to beckhoff-linux+unsubscribe@googlegroups.com.
To post to this group, send email to beckhoff-linux@googlegroups.com.


--
Håkon

Luis Matos

unread,
Mar 7, 2013, 6:54:49 PM3/7/13
to beckhof...@googlegroups.com
humm ... thinking again ...
The correct way to handle this just check first for if_addr being NULL and later for the AF_NET.
Because, if this is the last network device, then, all would be messed anyway.

please check:
https://github.com/gass/libads/commit/f7febfe2a0171a18db793c00e080a207ee495420

Håkon Nessjøen

unread,
Mar 8, 2013, 2:58:35 AM3/8/13
to beckhof...@googlegroups.com
Yes, this is how i originally wanted you to do it :)


To unsubscribe from this group and stop receiving emails from it, send an email to beckhoff-linu...@googlegroups.com.
To post to this group, send email to beckhof...@googlegroups.com.



--
Håkon

Håkon Nessjøen

unread,
Mar 8, 2013, 4:40:48 AM3/8/13
to beckhof...@googlegroups.com
I have sent you a pull request, and added some code in my own repo, which you can pull if you want.



On 8 March 2013 00:54, Luis Matos <ga...@otiliamatos.ath.cx> wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to beckhoff-linu...@googlegroups.com.
To post to this group, send email to beckhof...@googlegroups.com.



--
Håkon

Luis Matos

unread,
Mar 8, 2013, 11:42:42 AM3/8/13
to beckhof...@googlegroups.com
Hello,

Thank you for your contribution.

I've commented there that the only thing i disagree is the new dump function you created.

The ads dump function should changed to accomodate the number of items to dump.

cheers,
Luis Matos

Håkon Nessjøen

unread,
Mar 8, 2013, 11:57:33 AM3/8/13
to beckhof...@googlegroups.com
The ads dump function only work when adsdebug is on. So the example doesn't show anything if debug is not on. So I copied out the dump function from ads.c and removed the if expression.

I agree that it should be changed to only dump what is needed to dump.


--
Håkon

Reply all
Reply to author
Forward
0 new messages