-
Notifications
You must be signed in to change notification settings - Fork 87
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
Segmentation fault when using g15 driver #188
Comments
I peeked at that commit - looks like they refactored the rendering routine. I do not have a G15 so I cannot test. Are you able to do some digging to narrow down what section it's failing on? |
@toams how did you verify, that this commit causes the problem? |
I just double checked the commit and I cannot see anything wrong with it. I suspect this really is an issue with libg15render, @toams where does your libg15render come from? Note that both Fedora and Debian are shipping a svn snapshot of svn revision 316 which they are calling version 1.3.0 because upstream libg15render never did a proper 1.3.0 release before basically stopping all development. Ah I remember something now. And I think I know what is going on. The definition of the g15canvas struct looks like this:
Notice the In commit a9c0472 (which is older then commit 71a3c09) I added the following to lcdproc's
So if you are using a pre-build lib15grender from your distro that likely has TTF support enabled and if your local system does not have the necessary headers installed for lcdproc's ./configure to set HAVE_FT2, then this is the likely problem. Please check config,h in the directory where you are building lcdproc and check that it contains: Malloc will typically leave some free space after the allocated object, where as by packing them into the struct there is very little free space if any behind the g15canvas struct, increasing the chances of memory corruption when TTF_SUPPORT is not defined when including the header. Note that during my original work on this I hit a heap corruption issues because of this before the refactoring to not malloc these 2 structs. I guess the refactoring makes this problem easier to hit, which is causing you to think that commit 71a3c09 is the problem, but in reality reverting that commit really just papers over the problem and leads to crashes later. |
@toams if the above comment does not help, then please provide some more info about your setup to help debug this, like:
|
@toams, one more remark if my hunch about |
Reverting the commit is probably not the correct way to solve this but it might give a hint to what is wrong I can't find any mention of have_ft2 in the config.log and the config.h but I have libfreetype-dev installed. Version 2.10.1-2ubuntu0.1. Maybe here is something wrong? I tried debugging with gdb:
This makes me believe the problem is indeed with libg15render |
If you look at your config.h you will see that HAVE_FT2 is not defined there, as I already suspected. This means that your system is lacking the freetype2 headers / .pc files please make sure you have those installed; and then rebuild everything from scratch. As long as you don't have HAVE_FT2 defined in your config.h you will get libg15render crashes, reverting 71a3c09 means that you are now malloc-ing a too small struct instead of embedding it in another struct, which means that you are now corrupting your heap which usually takes a bit longer to cause a crash; but you are still using the wrong size for the struct. The only fix for this is to make sure your build environment matches the one used to build libg15render, which means that HAVE_FT2 should be defined in your config.h . Quoting from your config.log:
You need to fix that WARNING and then check that HAVE_FT2 is present in config.log after fixing the warning. |
@jwrdegoede thanks for clearing this up. I agree that libg15render does something very stupid and should be fixed. Regarding the upstream situation there seems to be a fork now that does regular releases: However I also wonder whether we can work around this problem on the lcdproc side: Is there anything stopping us from defining TTF_SUPPORT unconditionally before including the header file? |
@haraldg wrote:
Unfortunately yes there is, 2 of the extra struct g15canvas members have types defined in the freetype2 headers, so defining TTF_SUPPORT also actives including the freetype2 headers, quoting from libg15render.h :
And this will fail on systems without the freetype2 headers installed, that is why I made the lcdproc g15 code do things like this:
The proper fix for this would be to give libg15render a libg15render.h.in which gets processed by its ./configure script and which then generates a libg15render.h without the #ifdef-s which matches the compile time config of libg15render. As such it is good to know that there is a new upstream. I'll file an issue for this with the new upstream. But since most distros ship the svn316 snapshot we will still need the workaround on the lcdproc side. |
Thanks for the clarification. Can we figure out the compile time config of libg15render in ./configure? If yes, then maybe we can just use this to set TTF_SUPPORT for the build? Otherwise I think the g15 driver has an undeclared build dependency on freetype2. We could work around the issue by making the dependency explicit in autoconf. |
No I'm afraid we cannot, once the upstream issue is fixed, then we should be able to detect this because then code doing Oh wait, I'm wrong there actually is a way, sort of. libg15render has a helper program called g15fontconvert, which to my surprise even gets build when there is no TTF support, but then the entire code of the program is this;
So we could use this, but that depends on this helper being installed, which I'm not sure all distro packages do, also see below.
Yes I agree that this would be the best thing to do, at least all distro packages of libg15render have freetype support enabled AFAIK, Note I'm afraid I don't really have time to write a patch to add the freetype2 builddep myself, so I hope that you can take care of that. |
Nobody ever wants to work on our autoconf code. I myself can't do much more than intelligent copy&paste and trial&error. Also I don't really understand, why your safeguard isn't enough: If the distros compile libg15render against freetype2, don't they make libg15render-dev depend on libfreetype2-dev, so that HAVE_FT2 should always be defined when building the g15 driver? But yes, I can provide a PR for you and @toams to test and improve upon. |
This is a workaround for an upstream bug. For details see the following issue. (Closes: lcdproc#188) Signed-off-by: Harald Geyer <harald@ccbib.org>
The thing that confuses me right now is that autoconf doesnt detect freetype being installed on my system. I searched for freetype.h and freetype.pc and they are both installed.:
but ./configure doesnt detect them I will try #190 later this evening |
Nice to see this being resolved so quickly, |
I got a segmentation fault when trying to run lcdproc on my logitech g15 keyboard.
I compiled lcdproc from latest master
I traced back the issue to this commit: 71a3c09
backtrace:
The text was updated successfully, but these errors were encountered: