Bug#340384: net-tools: arp Bus Error
On Fri, Dec 02, 2005 at 11:00:28PM -0800, Jurij Smakov wrote: In that case the cast from sockaddr to sockaddr_in is a problem. The sockaddr structure consists of a short (2 bytes) and an array of 14 chars, so it is allowed to be aligned (and is, in fact, aligned) on the 2-byte boundary, Yes, probaly sockad should be changed to contain an array of longs instead of chars, since it is supposed to be castable I really hate C :) Gruss Bernd -- (OO) -- [EMAIL PROTECTED] -- ( .. )[EMAIL PROTECTED],linux.de,debian.org} http://www.eckes.org/ o--o 1024D/E383CD7E [EMAIL PROTECTED] v:+497211603874 f:+49721151516129 (OO) When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl! -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#340384: net-tools: arp Bus Error
On Sat, 3 Dec 2005, Bernd Eckenfels wrote: On Fri, Dec 02, 2005 at 11:00:28PM -0800, Jurij Smakov wrote: In that case the cast from sockaddr to sockaddr_in is a problem. The sockaddr structure consists of a short (2 bytes) and an array of 14 chars, so it is allowed to be aligned (and is, in fact, aligned) on the 2-byte boundary, Yes, probaly sockad should be changed to contain an array of longs instead of chars, since it is supposed to be castable I really hate C :) A somewhat cleaner solution (as pointed out by Steve again) would be to use struct sockaddr_storage instead of sockaddr, that will have the correct alignment and is guaranteed to have enough storage for both ipv4 and ipv6 sockets. Best regards, Jurij Smakov[EMAIL PROTECTED] Key: http://www.wooyd.org/pgpkey/ KeyID: C99E03CC -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#340384: net-tools: arp Bus Error
tag 340384 +patch thanks Hello Juri, thanks for all your help (and please say thanks to Steve). I didnt want to rewrite all of the code, so I just changed the alocation of the structures in the following way: Index: arp.c === RCS file: /cvsroot/net-tools/net-tools/arp.c,v retrieving revision 1.24 diff -u -r1.24 arp.c --- arp.c 16 May 2005 04:30:17 - 1.24 +++ arp.c 4 Dec 2005 02:49:42 - @@ -100,7 +100,8 @@ { char host[128]; struct arpreq req; -struct sockaddr sa; +struct sockaddr_storage ss; +struct sockaddr *sa; int flags = 0; int deleted = 0; @@ -112,12 +113,13 @@ return (-1); } safe_strncpy(host, *args, (sizeof host)); -if (ap-input(0, host, sa) 0) { +sa = (struct sockaddr *)ss; +if (ap-input(0, host, sa) 0) { ap-herror(host); return (-1); } /* If a host has more than one address, use the correct one! */ -memcpy((char *) req.arp_pa, (char *) sa, sizeof(struct sockaddr)); +memcpy((char *) req.arp_pa, (char *) sa, sizeof(struct sockaddr)); if (hw_set) req.arp_ha.sa_family = hw-type; @@ -177,11 +179,11 @@ usage(); if (strcmp(*args, 255.255.255.255) != 0) { strcpy(host, *args); - if (ap-input(0, host, sa) 0) { + if (ap-input(0, host, sa) 0) { ap-herror(host); return (-1); } - memcpy((char *) req.arp_netmask, (char *) sa, + memcpy((char *) req.arp_netmask, (char *) sa, sizeof(struct sockaddr)); req.arp_flags |= ATF_NETMASK; } @@ -266,7 +268,8 @@ { char host[128]; struct arpreq req; -struct sockaddr sa; +struct sockaddr_storage ss; +struct sockaddr *sa; int flags; memset((char *) req, 0, sizeof(req)); @@ -277,12 +280,13 @@ return (-1); } safe_strncpy(host, *args++, (sizeof host)); -if (ap-input(0, host, sa) 0) { +sa = (struct sockaddr *)ss; +if (ap-input(0, host, sa) 0) { ap-herror(host); return (-1); } /* If a host has more than one address, use the correct one! */ -memcpy((char *) req.arp_pa, (char *) sa, sizeof(struct sockaddr)); +memcpy((char *) req.arp_pa, (char *) sa, sizeof(struct sockaddr)); /* Fetch the hardware address. */ if (*args == NULL) { @@ -352,11 +356,11 @@ usage(); if (strcmp(*args, 255.255.255.255) != 0) { strcpy(host, *args); - if (ap-input(0, host, sa) 0) { + if (ap-input(0, host, sa) 0) { ap-herror(host); return (-1); } - memcpy((char *) req.arp_netmask, (char *) sa, + memcpy((char *) req.arp_netmask, (char *) sa, sizeof(struct sockaddr)); flags |= ATF_NETMASK; } @@ -525,7 +529,8 @@ static int arp_show(char *name) { char host[100]; -struct sockaddr sa; +struct sockaddr_storage ss; +struct sockaddr *sa; char ip[100]; char hwa[100]; char mask[100]; @@ -538,14 +543,15 @@ host[0] = '\0'; +sa = (struct sockaddr *)ss; if (name != NULL) { /* Resolve the host name. */ safe_strncpy(host, name, (sizeof host)); - if (ap-input(0, host, sa) 0) { + if (ap-input(0, host, sa) 0) { ap-herror(host); return (-1); } - safe_strncpy(host, ap-sprint(sa, 1), sizeof(host)); + safe_strncpy(host, ap-sprint(sa, 1), sizeof(host)); } /* Open the PROCps kernel table. */ if ((fp = fopen(_PATH_PROCNET_ARP, r)) == NULL) { @@ -581,10 +587,10 @@ if (opt_n) hostname = ?; else { - if (ap-input(0, ip, sa) 0) + if (ap-input(0, ip, sa) 0) hostname = ip; else - hostname = ap-sprint(sa, opt_n | 0x8000); + hostname = ap-sprint(sa, opt_n | 0x8000); if (strcmp(hostname, ip) == 0) hostname = ?; } this might not be the cleanest way, but i think it is ok this way. I hope arp is the only afected tool: I dont have yet a sparc64 account, but hopefully soon, and then i will test it before upload. Gruss Bernd -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#340384: net-tools: arp Bus Error
On Sun, 4 Dec 2005, Bernd Eckenfels wrote: tag 340384 +patch thanks Hello Juri, thanks for all your help (and please say thanks to Steve). I didnt want to rewrite all of the code, so I just changed the alocation of the structures in the following way: Hi Bernd, I've tried the package with this patch applied and now everything works as expected: [EMAIL PROTECTED]:~$ /usr/sbin/arp localhost localhost (127.0.0.1) -- no entry [EMAIL PROTECTED]:~$ Thanks for a quick reaction, Jurij Smakov[EMAIL PROTECTED] Key: http://www.wooyd.org/pgpkey/ KeyID: C99E03CC -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#340384: net-tools: arp Bus Error
Hi, As explained by Steve Langasek (thanks a lot!), this bug is a result of a recent change in gcc, which has switched from using glibc's memcpy() to an optimized inline memcpy() routine, which takes advantage of the knowledge about the alignment of source and destination, which gcc is tracking. In that case the cast from sockaddr to sockaddr_in is a problem. The sockaddr structure consists of a short (2 bytes) and an array of 14 chars, so it is allowed to be aligned (and is, in fact, aligned) on the 2-byte boundary, while the largest element of sockaddr_in is 4 bytes, so it is expected to be aligned on a 4-byte boundary. This alignment mismatch is what causing a bus error. According to Steve, C language specification makes such a cast illegal, so it needs to be fixed. Best regards, Jurij Smakov[EMAIL PROTECTED] Key: http://www.wooyd.org/pgpkey/ KeyID: C99E03CC -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#340384: net-tools: arp Bus Error
do you know if this was introduced in -16 (or earlier?) i.e. what was the last version which worked? #0 0x70104220 in inet_aton () from /lib/libc.so.6 #1 0x00014028 in ?? () #2 0x00014028 in ?? () if you have some time at hand you could try to debug this with a debug build, however it might also be obvious from source where the unaligned access happens, will check that at the weekend. Thanks for your report. Bernd -- (OO) -- [EMAIL PROTECTED] -- ( .. )[EMAIL PROTECTED],linux.de,debian.org} http://www.eckes.org/ o--o 1024D/E383CD7E [EMAIL PROTECTED] v:+497211603874 f:+49721151516129 (OO) When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl! -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Bug#340384: net-tools: arp Bus Error
Package: net-tools Version: 1.60-16 Severity: grave Justification: renders package unusable arp gives a Bus Error every time it is used. strace and gdb backtrace attached. Script started on Tue 22 Nov 2005 07:01:03 PM PST sundry:/home/pb# arp Bus error sundry:/home/pb# arp -a Bus error sundry:/home/pb# strace arp execve(/usr/sbin/arp, [arp], [/* 16 vars */]) = 0 uname({sys=Linux, node=sundry, ...}) = 0 brk(0) = 0x2c000 access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such file or directory) access(/etc/ld.so.preload, R_OK) = -1 ENOENT (No such file or directory) open(/etc/ld.so.cache, O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=21129, ...}) = 0 mmap(NULL, 21129, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7001c000 close(3)= 0 access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such file or directory) open(/lib/libc.so.6, O_RDONLY)= 3 read(3, \177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\2\0\0\0\1\0\1\312..., 512) = 512 fstat64(3, {st_mode=S_IFREG|0755, st_size=1199100, ...}) = 0 mmap(NULL, 1268776, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7003 mprotect(0x7015, 89128, PROT_NONE) = 0 mmap(0x7015e000, 24576, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11e000) = 0x7015e000 mmap(0x70164000, 7208, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x70164000 close(3)= 0 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x70166000 munmap(0x7001c000, 21129) = 0 open(/usr/lib/locale/locale-archive, O_RDONLY|O_LARGEFILE) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=290576, ...}) = 0 mmap2(NULL, 290576, PROT_READ, MAP_PRIVATE, 3, 0) = 0x70168000 close(3)= 0 brk(0) = 0x2c000 brk(0x4e000)= 0x4e000 open(/usr/share/locale/locale.alias, O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=2582, ...}) = 0 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x701b read(3, # Locale name alias data base.\n#..., 8192) = 2582 read(3, , 8192) = 0 close(3)= 0 munmap(0x701b, 8192)= 0 open(/usr/share/locale/en_US/LC_MESSAGES/net-tools.mo, O_RDONLY) = -1 ENOENT (No such file or directory) open(/usr/share/locale/en/LC_MESSAGES/net-tools.mo, O_RDONLY) = -1 ENOENT (No such file or directory) open(/usr/share/locale/en_GB/LC_MESSAGES/net-tools.mo, O_RDONLY) = -1 ENOENT (No such file or directory) socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3 open(/proc/net/arp, O_RDONLY) = 4 fstat64(4, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x701b read(4, IP address HW type Fla..., 1024) = 310 --- SIGBUS (Bus error) @ 0 (0) --- +++ killed by SIGBUS +++ sundry:/home/pb# gdb arp GNU gdb 6.3-debian Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type show copying to see the conditions. There is absolutely no warranty for GDB. Type show warranty for details. This GDB was configured as sparc-linux...(no debugging symbols found) Using host libthread_db library /lib/libthread_db.so.1. (gdb) run Starting program: /usr/sbin/arp (no debugging symbols found) (no debugging symbols found) Program received signal SIGBUS, Bus error. 0x70104220 in inet_aton () from /lib/libc.so.6 (gdb) bt #0 0x70104220 in inet_aton () from /lib/libc.so.6 #1 0x00014028 in ?? () #2 0x00014028 in ?? () Previous frame identical to this frame (corrupt stack?) (gdb) The program is running. Exit anyway? (y or n) y sundry:/home/pb# exit Script done on Tue 22 Nov 2005 07:01:56 PM PST -- System Information: Debian Release: testing/unstable APT prefers testing APT policy: (500, 'testing') Architecture: sparc (sparc64) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.12-1-sparc64-smp Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1) Versions of packages net-tools depends on: ii libc6 2.3.5-6GNU C Library: Shared libraries an net-tools recommends no packages. -- no debconf information -- Blars Blarson [EMAIL PROTECTED] http://www.blars.org/blars.html With Microsoft, failure is not an option. It is a standard feature. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]