After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 754194 - vino crashes on connect when resolver on the server is not using DNS
vino crashes on connect when resolver on the server is not using DNS
Status: RESOLVED FIXED
Product: vino
Classification: Applications
Component: Server
3.16.x
Other Linux
: Normal major
: ---
Assigned To: Vino Maintainer(s)
Vino Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-08-27 18:17 UTC by Dimitri Tarassenko
Modified: 2015-08-28 16:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch for the problem (583 bytes, patch)
2015-08-27 18:17 UTC, Dimitri Tarassenko
none Details | Review
garbage in notification (29.14 KB, image/png)
2015-08-27 18:18 UTC, Dimitri Tarassenko
  Details
.xsession-errors fragment (591.68 KB, image/png)
2015-08-27 18:19 UTC, Dimitri Tarassenko
  Details
code fragment (57.92 KB, image/png)
2015-08-27 18:20 UTC, Dimitri Tarassenko
  Details
improved patch (1.33 KB, patch)
2015-08-27 21:49 UTC, David King
none Details | Review
patch with inet_ntop() fallback (1.88 KB, patch)
2015-08-28 13:46 UTC, Dimitri Tarassenko
reviewed Details | Review
patch with second call to getnameinfo() with NI_NUMERICHOST (1.13 KB, patch)
2015-08-28 15:35 UTC, Dimitri Tarassenko
committed Details | Review

Description Dimitri Tarassenko 2015-08-27 18:17:16 UTC
Created attachment 310113 [details] [review]
patch for the problem

When a server does not have DNS configured and relies on hosts file for resolution, getnameinfo() in server/libvncserver/rfbserver.c(169) fails and leaves the variable "host" uninitialized.

Depending on your luck, this can either lead to garbage characters displayed in the notification bubble (and logged in ~/.xsession-errors) to vino crashing and terminating the session, to locking up and preventing the next copy to start.

The issue observed on Centos 6.7, vino 2.28.1, most recent vino version has the same problem. Patch and a few screenshots attached.
Comment 1 Dimitri Tarassenko 2015-08-27 18:18:24 UTC
Created attachment 310114 [details]
garbage in notification
Comment 2 Dimitri Tarassenko 2015-08-27 18:19:27 UTC
Created attachment 310115 [details]
.xsession-errors fragment
Comment 3 Dimitri Tarassenko 2015-08-27 18:20:03 UTC
Created attachment 310116 [details]
code fragment
Comment 4 David King 2015-08-27 21:49:57 UTC
Created attachment 310140 [details] [review]
improved patch

Thanks for the bug report and patch!

Upstream libvncserver also logs an error message, and does this slightly differently, by checking the return code of getnameinfo(). Does this patch work for you?
Comment 5 Dimitri Tarassenko 2015-08-28 13:45:22 UTC
David,

Can I suggest something like the attached patch? Not having DNS is technically not an error, but an unusual configuration. Even when the resolver is not using the DNS, we still have the IP/IPV6 address we can decode and show. The attached patch is doing just that using inet_ntop().

Thanks for your prompt response!
Comment 6 Dimitri Tarassenko 2015-08-28 13:46:08 UTC
Created attachment 310185 [details] [review]
patch with inet_ntop() fallback
Comment 7 David King 2015-08-28 14:22:16 UTC
Review of attachment 310185 [details] [review]:

::: vino-2.28.1/server/libvncserver/rfbserver.c.m1
@@ +178,3 @@
+        if (!gotHostName) {
+          struct sockaddr_in *addr_in = (struct sockaddr_in *)&addr;
+          inet_ntop(AF_INET, &(addr_in->sin_addr), host, INET_ADDRSTRLEN);

Can you call getnameinfo() with NI_NAMEREQD, and then repeat the call with NI_NUMERICHOST if it fails? Does that avoid the need to add the net_ntop() calls?
Comment 8 Dimitri Tarassenko 2015-08-28 14:50:18 UTC
The way I understand the getnameinfo() documentation, is that when you don't specify any flags, that's exactly what it tries to do, get the name first, when it fails, return numeric:

NI_NUMERICHOST
If set, then the numeric form of the hostname is returned. (When not set, this will still happen in case the node's name cannot be determined.)

That's in theory. In practice it just fails. I don't know. Maybe it's worth checking out how getnameinfo() is implemented.
Comment 9 David King 2015-08-28 15:05:15 UTC
(In reply to Dimitri Tarassenko from comment #8)
> The way I understand the getnameinfo() documentation, is that when you don't
> specify any flags, that's exactly what it tries to do, get the name first,
> when it fails, return numeric:
> 
> NI_NUMERICHOST
> If set, then the numeric form of the hostname is returned. (When not set,
> this will still happen in case the node's name cannot be determined.)
> 
> That's in theory. In practice it just fails. I don't know. Maybe it's worth
> checking out how getnameinfo() is implemented.

Does getnameinfo() fail to return the numeric form even when passing NI_NUMERICHOST? That would be unexpected. Does the error code returned by getnameinfo() suggest anything useful? 

he current implementation of getnameinfo() seems to be:

http://sourceware.org/git/?p=glibc.git;a=blob;f=inet/getnameinfo.c;h=0126f2032655e5bb4d610c9eddf22ae10ee54cf3;hb=HEAD#l173

I haven't had time to understand it completely, but it seems that the fallback behaviour (which uses inet_ntop()) should be triggered.
Comment 10 Dimitri Tarassenko 2015-08-28 15:21:22 UTC
I ran it under debugging - getnameinfo() returns -3 (EAI_AGAIN), which is returned from gethostbyaddr() (http://code.woboq.org/userspace/glibc/inet/getnameinfo.c.html line 272. Which is why it doesn't try to return the numeric hostname.
Comment 11 Dimitri Tarassenko 2015-08-28 15:24:28 UTC
I.e. your suggestion WOULD work, because with NI_NUMERICHOST set it bypasses this attempt and goes directly to using inet_ntop() calls.

There is some extra magic happening with IPV6 scopes, so doing what you suggested would be preferred to using inet_ntop() directly as in my patch. Let me try your suggestion today.
Comment 12 Dimitri Tarassenko 2015-08-28 15:34:31 UTC
Actually, worked great. Patch attached.
Comment 13 Dimitri Tarassenko 2015-08-28 15:35:11 UTC
Created attachment 310204 [details] [review]
patch with second call to getnameinfo() with NI_NUMERICHOST
Comment 14 David King 2015-08-28 16:05:24 UTC
Review of attachment 310204 [details] [review]:

Thanks for the testing! I pushed a slightly-modified version of your patch, with a commit message, to master.