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 683118 - gvfs-sftpd crashes in g_utf8_validate() if the target host is not in .ssh/known_hosts
gvfs-sftpd crashes in g_utf8_validate() if the target host is not in .ssh/kno...
Status: RESOLVED FIXED
Product: gvfs
Classification: Core
Component: sftp backend
1.13.x
Other Linux
: Normal major
: ---
Assigned To: gvfs-maint
gvfs-maint
: 683334 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-08-31 15:33 UTC by Martin Pitt
Modified: 2012-09-04 16:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
sftp: Fix crash if the target host is not in .ssh/known_hosts (1.29 KB, patch)
2012-08-31 15:57 UTC, Martin Pitt
none Details | Review
gmountsource: Always use NULL-terminated arrays (8.19 KB, patch)
2012-08-31 16:04 UTC, Tomas Bzatek
committed Details | Review

Description Martin Pitt 2012-08-31 15:33:11 UTC
Originally reported in https://launchpad.net/bugs/1033275:

When trying to connect to an ssh server with nautilus or "gvfs-mount sftp://...", gvfs-sftpd crashes if the target host is not in ~/.ssh/known_hosts.

Trace:

  • #0 fast_validate
    at /build/buildd/glib2.0-2.33.10/./glib/gutf8.c line 1461
  • #1 g_utf8_validate
    at /build/buildd/glib2.0-2.33.10/./glib/gutf8.c line 1629
  • #2 g_variant_new_string
    at /build/buildd/glib2.0-2.33.10/./glib/gvariant.c line 1270
  • #3 g_variant_new_strv
    at /build/buildd/glib2.0-2.33.10/./glib/gvariant.c line 1497
  • #4 g_variant_valist_new_leaf
    at /build/buildd/glib2.0-2.33.10/./glib/gvariant.c line 4311
  • #5 g_variant_valist_new
    at /build/buildd/glib2.0-2.33.10/./glib/gvariant.c line 4493
  • #6 g_variant_valist_new
    at /build/buildd/glib2.0-2.33.10/./glib/gvariant.c line 4545
  • #7 g_variant_new_va
  • #8 g_variant_new
  • #9 gvfs_dbus_mount_operation_call_ask_question
  • #10 g_mount_source_ask_question_async
    at gmountsource.c line 629
  • #11 g_mount_source_ask_question
  • #12 handle_login
    at gvfsbackendsftp.c line 1074
  • #13 do_mount
    at gvfsbackendsftp.c line 1602
  • #14 real_do_mount
    at gvfsbackendsftp.c line 1715
  • #15 g_vfs_job_run
    at gvfsjob.c line 197

Comment 1 Martin Pitt 2012-08-31 15:38:32 UTC
This is the crux of the problem:

in g_mount_source_ask_question() we get a valid char** choices and n_choices == 2:

(gdb) p choices[0]
$13 = 0x423a5c "Log In Anyway"
(gdb) p choices[1]
$14 = 0x423a6a "Cancel Login"
(gdb) p choices[2]
$15 = 0x6874756120656854 <Address 0x6874756120656854 out of bounds>
(gdb) p n_choices
$16 = 2

Then this gets passed to g_mount_source_ask_question_async(), which however entirely ignores n_choices and just passes choices on to gvfs_dbus_mount_operation_call_ask_question() in the autogenerated common/gvfsdbus.c. This calls g_variant_new(), which expects a NULL terminated array. With the simple g_variant_new() API we cannot actually pass an array length (unlike with g_variant_new_strv()), so I think gvfs should just ensure that choices is NULL-terminated.

I'll work on a patch for this.
Comment 2 Tomas Bzatek 2012-08-31 15:52:37 UTC
Yes, came across this two days ago, preparing a patch, give me few minutes.

But yes, you got the point, we need NULL-terminated arrays for the gdbus calls.
Comment 3 Martin Pitt 2012-08-31 15:57:41 UTC
Created attachment 223079 [details] [review]
sftp: Fix crash if the target host is not in .ssh/known_hosts

This is the simplest possible patch, and it fixes the problem.

It's not terribly elegant, though. A better approach might be to drop the n_choices argument from all the internal API completely, and just demand NULL termination.
Comment 4 Tomas Bzatek 2012-08-31 16:04:02 UTC
Created attachment 223080 [details] [review]
gmountsource: Always use NULL-terminated arrays

(In reply to comment #3)
> It's not terribly elegant, though. A better approach might be to drop the
> n_choices argument from all the internal API completely, and just demand NULL
> termination.

Thanks for the patch, breaking internal API was my intention actually. We don't transfer the n_choices argument over d-bus anyway.
Comment 5 Tomas Bzatek 2012-08-31 16:05:34 UTC
Bug 682496 is related issue.
Comment 6 Martin Pitt 2012-08-31 16:09:09 UTC
Thanks Tomas. I had a similar patch, but currently struggling with a build failure as gvfs master doesn't build against glib 2.33.10. I'm just building in jhbuild, but seems you beat me to it anyway now. :-)

Sorry for the mid-air collision, and thanks for the super-fast response!
Comment 7 Martin Pitt 2012-08-31 16:35:15 UTC
For the record, I reproduced this bug in a test case in the integration test suite that I'm developing:

http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/quantal/gvfs/quantal/revision/232

(see https://mail.gnome.org/archives/gvfs-list/2012-August/msg00000.html for the beginnings of dicussions in which form to get that upstream).

test_rsa (__main__.Sftp)
sftp://localhost with RSA authentication ... ok
test_unknown_host (__main__.Sftp)
sftp:// with RSA authentication for unknown host ... FAIL

======================================================================
FAIL: test_unknown_host (__main__.Sftp)
sftp:// with RSA authentication for unknown host
----------------------------------------------------------------------
Traceback (most recent call last):
  • File "/home/gvfs-testbed-script", line 270 in test_unknown_host
    self.assertTrue('Login dialog cancelled' in err, err)
AssertionError: False is not true : Error mounting location: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message did not receive a reply (timeout by message bus)


----------------------------------------------------------------------
Ran 2 tests in 3.073s


With the fix, the test case works. I also verified it manually by temporarily moving away my ~/.ssh/known_hosts file.
Comment 8 William Jon McCann 2012-09-04 16:27:54 UTC
*** Bug 683334 has been marked as a duplicate of this bug. ***
Comment 9 Tomas Bzatek 2012-09-04 16:46:29 UTC
Oh, nice catch with the test suite. I'll follow up in the list in next few days, trying to get more QA people involved. It certainly looks good!

I've pushed the patch in comment 4 as commit 085c2885ff7f1acaf7a5238f85732d361ad55fc9. Thanks for confirming it works.