Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault when compiling under amd64 #72

Closed
SledgehammerPL opened this issue Dec 19, 2014 · 14 comments
Closed

segfault when compiling under amd64 #72

SledgehammerPL opened this issue Dec 19, 2014 · 14 comments

Comments

@SledgehammerPL
Copy link

Does any have an idea why rtl_444 generates segfault? I use it under i386, but moved into amd64, githubbed clean repo, cmake, make, rtl_433 ->
Registering protocol[01] Rubicson Temperature Sensor
Registering protocol[02] Prologue Temperature Sensor
Registering protocol[03] Silvercrest Remote Control
Registering protocol[04] ELV EM 1000
Registering protocol[05] ELV WS 2000
Registering protocol[06] Waveman Switch Transmitter
Registering protocol[07] Steffen Switch Transmitter
Registering protocol[08] Acurite 5n1 Weather Station
Segfault

dmesg shows:

[14190.217587] rtl_433[21585]: segfault at 0 ip 00007fa33d944294 sp 00007fff96da4e90 error 4 in libc-2.13.so[7fa33d89c000+182000]
[14195.813128] rtl_433[21586]: segfault at 0 ip 00007f163b58d294 sp 00007fff494fab00 error 4 in libc-2.13.so[7f163b4e5000+182000]
[14220.146136] rtl_433[21592]: segfault at 0 ip 00007f67074c7294 sp 00007fff670af930 error 4 in libc-2.13.so[7f670741f000+182000]
[14857.105725] rtl_433[22594]: segfault at 0 ip 00007f5a2bb51294 sp 00007fff6edad4e0 error 4 in libc-2.13.so[7f5a2baa9000+182000]

@Batilan
Copy link
Contributor

Batilan commented Dec 19, 2014

It is easier to troubleshoot when you enable core dumps (see e.g. http://www.akadia.com/services/ora_enable_core.html). Then a core file will be created on a segfault. With the core file you can get a stack trace and possibly the code location where the problem occurs (see e.g. http://stackoverflow.com/questions/5115613/core-dump-file-analysis). This might help find the issue. This might also help: http://stackoverflow.com/questions/2549214/interpreting-segfault-messages

@SledgehammerPL
Copy link
Author

bt full

#0 0x00007f0c1e1fb294 in opendir () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#1 0x00007f0c1e987a4e in ?? () from /lib/x86_64-linux-gnu/libusb-1.0.so.0
No symbol table info available.
#2 0x00007f0c1e9803bd in libusb_get_device_list ()
from /lib/x86_64-linux-gnu/libusb-1.0.so.0
No symbol table info available.
#3 0x00007f0c1eb9184b in rtlsdr_get_device_count ()
at /usr/src/rtl_433/src/librtlsdr.c:1167
i = 32524
ctx = 0xffffffff
list = 0x0
device_count = 0
dd = {bLength = 16 '\020', bDescriptorType = 240 '\360',
bcdUSB = 7926, bDeviceClass = 12 '\f', bDeviceSubClass = 127 '\177',
bDeviceProtocol = 0 '\000', bMaxPacketSize0 = 0 '\000',
idVendor = 61440, idProduct = 7926, bcdDevice = 32524,
iManufacturer = 0 '\000', iProduct = 0 '\000',
iSerialNumber = 3 '\003', bNumConfigurations = 0 '\000'}
cnt = 0
#4 0x0000000000405721 in main (argc=1, argv=0x7fff4d7b0728)
at /usr/src/rtl_433/src/rtl_433.c:1552
sigact = {__sigaction_handler = {sa_handler = 0x1,
sa_sigaction = 0x1}, sa_mask = {__val = {0, 140733193388033,
139690036163016, 139690027413984, 8388608, 139690029579232,
139690021258576, 0, 139690036163872, 140734493296144,
140734493296168, 4294967302, 140734493296174, 191, 4197466,
140734493296174}}, sa_flags = 505294876, sa_restorer = 0x7c}
filename = 0x0
test_mode_file = 0x0
test_mode = 0x7fff4d7b0738
n_read = 32524
r = 0
opt = -1
i = 4219040
gain = 0
sync_mode = 0
ppm_error = 0
demod = 0x7f0c1d74a010
buffer = 0x7f0c1ef6f010 ""
dev_index = 0
frequency_current = 0
out_block_size = 262144
device_count = 0
vendor = "\220\361\177M\377\177\000\000\240\004{M\377\177\000\000H6\373\036\f\177\000\000\b\000\000\000\000\000\000\000.N=\366\000\000\000\000\023x\332\036\f\177\000\000h\362\177M\377\177\000\000\000\000\000\000\000\000\000\000.\000\000\000\000\000\000\000\070\365\330\003\000\000\000\000lj\025\036\f\177\000\000\020\006{M\377\177\000\000l\025\036\f\177\000\000@\006{M\377\177\000\000H,\026\036\f\177\000\000X\367\373\036\f\177\000\000\000\000\000\000\000\000\000\000\220\066\373\036\f\177\000\000\270I\373\036\f\177\000\000Z\f@\000\000\000\000\000\000\070\026\036\f\177\000\000\270\005@\000\000\000\000\000\000\000\000\000\001\000\000\000\377\a\000\000\001", '\000' <repeats 11 times>, " \365\373\036\f\177\000\000\006{M\377\177\000\000\220\066\373\036\f\177\000\000\210\006{M\377\177"...
product = "x{\025\036\f\177\000\000 \365\373\036\f\177\000\000\000\000\000\000\000\000\000\0009\373\036\f\177\000\000\270I\373\036\f\177\000\000\372=v\036\f\177\000\000\000\070\026\036\f\177\000\000\230#v\036\f\177\000\000\000\000\000\000\001\000\000\000\241\000\000\000\001\000\000\000(\200\000\000\000\000\000XC\373\036\f\177\000\000\360\004{M\377\177\000\0009\373\036\f\177\000\000\030\005{M\377\177\000\000\nq\332\036\f\177\000\000\027\341/\261\000\000\000\000\060\004{M\377\177\000\000\000\000\000\000\000\000\000\000\060\004{M\377\177\000\000\200\367\373\036\f\177\000\000\001\000\000\000\000\000\000\000\177U\335q\000\000\000\000\221x\332\036\f\177\000\000\060\337\373\036\f\177\000\000\330\351\373\036\f\177\000\000?\000\000\000\f\177\000\000Uu\307\001", '\000' <repeats 12 times>, "\n"... serial = "0l\025\036\f\177\000\000\300\003{M\377\177\000\000l\025\036\f\177\000\000\000\000\200\003\366\232\376\377\340\066\026\036\f\177\000\000\310\361\373\036\f\177\000\000\000\000\000\000\000\000\000\000\260=\373\036\f\177\000\000\270I\373\036\f\177\000\000<\347\331\036\f\177\000\000\000\070\026\036\f\177\000\000\020\344\331\036\f\177\000\000\000\000\000\000\001\000\000\000p\b\000\000\001", '\000' <repeats 11 times>, "\nq\332\036\f\177\000\000\020\004{M\377\177\000\000\060\003{M\377\177\000\000\310\004{M\377\177\000\000\060\003{M\377\177\000\000H6\373\036\f\177\000\000\b\000\000\000\000\000\000\000\027\341/\261\000\000\000\000\023x\332\036\f\177\000\000\001", '\000' <repeats 15 times>, "\027\000\000\000\000\000\000\000\204\277\304\002\000\000\000\000\364L\025\036\f\177\000\000\240\004{M\377\177\000\000`"...

@SledgehammerPL
Copy link
Author

I have an idea - there's no permission to dir which is tried to open (by opendir) - but how to determine what file/dir is tried to open? Last call which can i modify is:
uint32_t rtlsdr_get_device_count(void)
{
int i;
libusb_context _ctx;
libusb_device *_list;
uint32_t device_count = 0;
struct libusb_device_descriptor dd;
ssize_t cnt;

libusb_init(&ctx);

cnt = libusb_get_device_list(ctx, &list);

@SledgehammerPL
Copy link
Author

DAMN IT!!!!
Good old strace points with big finger YOU FOOL! I use lxc-containers, and i prepare all permissions for /dev/bus/usb but decided to compile it on devel container and after test put only executable to prod container. But i forgot to copy /dev/bus/usb to devel container.. The only problem was:

open("/dev/bus/usb", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

@Batilan
Copy link
Contributor

Batilan commented Dec 20, 2014

I think this actually is a bug: a program should never end with a segfault. In this case it seems to be caused by the rtlsdr library. I think the problem is here: https://github.com/merbanan/rtl_433/blob/master/src/librtlsdr.c#L1165-1167
The rtlsdr_get_device_count routine does not check the result of the libusb_init call. If this fails because of permissions then the libusb_get_device_list call segfaults.

Indeed you can prevent this segfault by setting permissions correctly, however it still is a bug.

I was able to reproduce the the segfault by changing permissions on /dev/bus/usb and subsequently I could prevent the segfault by first checking the result from libusb_init to be OK before making the call to libusb_get_device_list.

Unfortunetely this pattern is used all over librtlsdr, even in more recent versions on https://github.com/steve-m/librtlsdr/blob/master/src/librtlsdr.c (which I understand is the most recent version of librtlsdr). Currently rtl_433 contains its own copy of librtlsdr.c which is already 2 years old, we can fix it in there, or try to get the original librtlsdr.c updated and get that into rtl_433.

Anyway: you did hit a bug in librtlsdr which should be fixed I think.

@rct
Copy link
Contributor

rct commented Dec 20, 2014

If there aren't compatibility problems, I'd be in favor of a rtl_433 package that just had rtl_433 and the necessary build files that would let it be compiled against the librtlsdr that is built separately from the main rtl_sdr package.

If people don't agree, then at a minimum, I think all the other rtl_ tools (frm, test, tcp, etc.) should be removed from rtl_433, because they are all old leaving just rtl_433 and librtlsdr.

@rct
Copy link
Contributor

rct commented Dec 20, 2014

Besides @steve-m's librtlsdr (1) it's also worth checking @keenerd's rtlsdr fork (2). He's done a bunch of clean up that was sponsored by the month of rtl-sdr (3)

  1. https://github.com/steve-m/librtlsdr
  2. https://github.com/keenerd/rtl-sdr
  3. https://www.indiegogo.com/projects/a-month-of-rtl-sdr

@Batilan
Copy link
Contributor

Batilan commented Dec 21, 2014

@rct Thanks for the references. Because the Osmocom page refers to the @steve-m repository I used that as a reference. I see the @keenerd repository uses the same pattern. I'm starting to wonder if this is indeed a bug, it's hard to imagine that such a seemingly obvious bug has made it through all that time. I will just file an issue on both and see what response I get.

@Batilan
Copy link
Contributor

Batilan commented Dec 21, 2014

@rct About the way to restructure rtl_433: indeed at least the other rtl_* tools should be removed from rtl_433 as we now risk overwriting more recent rtl_* tools by doing a make install. I believe some rtl_433 forks already have done this.

Also it would indeed be nice to be able to build against the "latest" librtlsdr, (librtlsdr-dev package), however this introduces an extra dependency on installed packages, or requires to download the latest librtlsdr sources and build them. This is easy for developers but rtl_433 is being used more and more with people who just want to type cmake and make and have the 'darn thing' run.

Maybe we can add it as an option in the Cmake files and keep the possibility to use rtl_433 'embedded' version of librtlsdr (this way we can fix issues like this one without depending on the systems default installed librtlsdr). It would be good to have a look at the latest librtlsdr forks and integrate the "best" (most active and responsive) version.

@SledgehammerPL
Copy link
Author

reinstructure rtl_433 - my proposal is create a completely new rtl_433 repo, where all of us will make own additions

@loewal
Copy link

loewal commented Jan 30, 2020

Hi there,
Having next problem running RTL_433 with a Hackrf (with Furrtek Havoc firmware):
[INFO] Opening HackRF One #0 223c69dc299f894f...
Using device HackRF One: clock source=external part id=a000cb3c0065434d serial=0000000000000000223c69dc299f894f version=local-79baef77
Found 1 antenna(s): TX/RX
Found 3 gain(s): LNA 0 - 116 (step 0) AMP 0 - 116 (step 0) VGA 0 - 116 (step 0)
Found 1 frequencies: RF
Found 1 frequency range(s): 0 - 7250000000 (step 0)
Found 20 sample rate range(s): 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 11000000 12000000 13000000 14000000 15000000 16000000 17000000 18000000 19000000 20000000
Found 16 bandwidth range(s): 1750000 - 1750000 (step 0) 2500000 - 2500000 (step 0) 3500000 - 3500000 (step 0) 5000000 - 5000000 (step 0) 5500000 - 5500000 (step 0) 6000000 - 6000000 (step 0) 7000000 - 7000000 (step 0) 8000000 - 8000000 (step 0) 9000000 - 9000000 (step 0) 10000000 - 10000000 (step 0) 12000000 - 12000000 (step 0) 14000000 - 14000000 (step 0) 15000000 - 15000000 (step 0) 20000000 - 20000000 (step 0) 24000000 - 24000000 (step 0) 28000000 - 28000000 (step 0)
Found current bandwidth 0
Found 4 stream format(s): CS8 CS16 CF32 CF64
Found native stream format: CS8 (full scale: 128.0)
zsh: segmentation fault rtl_433 -d driver="hackrf" -g "LNA=40,AMP=14,VGA=30" -M newmodel -vvv

What could be the problem.
My Hackrf is found, but the command

~/ soapysdrutil --probe="hackrf"
######################################################

Soapy SDR -- the SDR abstraction library

######################################################

Probe device hackrf
[INFO] Make connection: ''
Error probing device: Failed to make connection with ''

Gives no Hackrf....
Anyone??

@loewal
Copy link

loewal commented Jan 30, 2020

forgot this:
~/ hackrf_info
hackrf_info version: unknown
libhackrf version: unknown (0.5)
Found HackRF
Index: 0
Serial number: 0000000000000000223c69dc299f894f
Board ID Number: 2 (HackRF One)
Firmware Version: local-79baef77 (API:1.03)
Part ID Number: 0xa000cb3c 0x0065434d

@zuckschwerdt
Copy link
Collaborator

Can you try a full debug build (cmake -DCMAKE_BUILD_TYPE=Debug .. && make from the ./build dir)?

@loewal
Copy link

loewal commented Jan 30, 2020

The result:
Found current bandwidth 0
Found 4 stream format(s): CS8 CS16 CF32 CF64
Found native stream format: CS8 (full scale: 128.0)
AddressSanitizer:DEADLYSIGNAL

==18757==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fff66b27c92 bp 0x7ffee3bfa080 sp 0x7ffee3bfa080 T0)
==18757==The signal is caused by a READ memory access.
==18757==Hint: address points to the zero page.
#0 0x7fff66b27c91 in _platform_strlen (libsystem_platform.dylib:x86_64+0x1c91)
#1 0x10c660309 in wrap_strlen (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x18309)
#2 0x10c60c6f3 in SoapySDRDevice_setupStream (libSoapySDR.0.8.0.dylib:x86_64+0x1b6f3)
#3 0x10c1d678f in sdr_open_soapy sdr.c:692
#4 0x10c1d2f2e in sdr_open sdr.c:796
#5 0x10c1b42fa in main rtl_433.c:1476
#6 0x7fff669317fc in start (libdyld.dylib:x86_64+0x1a7fc)

==18757==Register values:
rax = 0x000000010d2f968c rbx = 0x0000615000005000 rcx = 0x0000000000000001 rdx = 0x0000000000000001
rdi = 0x0000000000000000 rsi = 0x00006070000007a0 rbp = 0x00007ffee3bfa080 rsp = 0x00007ffee3bfa080
r8 = 0x0000000000000000 r9 = 0x0000000000000000 r10 = 0x00007fff9075f1e0 r11 = 0x000000010c60c6a0
r12 = 0x000000010d2f9688 r13 = 0x0000000000000001 r14 = 0x0000000000000001 r15 = 0x0000000000000000
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (libsystem_platform.dylib:x86_64+0x1c91) in _platform_strlen
==18757==ABORTING
zsh: abort rtl_433 -d driver="hackrf" -g "LNA=40,AMP=14,VGA=30" -M newmodel -vvv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants