hbons / SparkleShare

Share and collaborate by syncing with any Git repository instantly. Linux, macOS, and Windows.
https://sparkleshare.org
Other
4.88k stars 579 forks source link

Improve error handling of command line arguments #1840

Closed Ppjet6 closed 6 years ago

Ppjet6 commented 6 years ago

Running on Arch with flatpak 0.11.7 and SparkleShare 2.0.1.

What happened:

curl: no URL specified!                                                                                                                                                                                                                        
curl: try 'curl --help' or 'curl --manual' for more information                                                                                                                                                                                
17:42:01 Environment | SparkleShare 2.0.1 (Flatpak)                                                                                                                                                                                            
17:42:01 Environment | Git LFS 2.3.0                                                                                                                                                                                                           
17:42:01 Environment | Git 2.14.1                                                                                                                                                                                                              
17:42:01 Environment | GNOME (Unix 4.16.7.1)                                                                                                                                                                                                   
17:42:01 Cmd |  | gvfs-set-attribute "/home/user/SparkleShare" metadata::custom-icon-name org.sparkleshare.SparkleShare
Stacktrace:                                                                                              

  at <unknown> <0xffffffff>                                                                              
  at (wrapper managed-to-native) Gtk.Label.gtk_label_new_with_mnemonic (intptr) [0x00002] in <ab3825aa736a42a5a70c42e4d085cf34>:0
  at Gtk.Label..ctor (string) [0x00062] in <ab3825aa736a42a5a70c42e4d085cf34>:0                             
  at Gtk.Label..ctor () [0x00000] in <ab3825aa736a42a5a70c42e4d085cf34>:0                                   
  at SparkleShare.UserInterface..ctor () [0x0003c] in <b66dafb1300f4b69b42eb35ce4d1136b>:0                  
  at SparkleShare.SparkleShare.Main (string[]) [0x00128] in <b66dafb1300f4b69b42eb35ce4d1136b>:0                          
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x0004e] in <b66dafb1300f4b69b42eb35ce4d1136b>:0

Native stacktrace:                             

        mono() [0x4b7538]                                                                         
        mono() [0x50e68e]                                                                                                    
        mono() [0x42aca0]
        /lib/libpthread.so.0() [0x3154211800]
        /lib/libgtk-3.so.0(+0x2e4889) [0x7f053d5ad889]
        /lib/libgtk-3.so.0(+0x17d048) [0x7f053d446048]
        /lib/libgtk-3.so.0(+0x192154) [0x7f053d45b154]
        /lib/libgtk-3.so.0(+0x17e37c) [0x7f053d44737c]
        /lib/libgtk-3.so.0(+0x19207c) [0x7f053d45b07c]
        /lib/libgtk-3.so.0(+0x1920d5) [0x7f053d45b0d5]
        /lib/libgtk-3.so.0(+0x17ece2) [0x7f053d447ce2]
        /lib/libgobject-2.0.so.0(g_type_create_instance+0x1cf) [0x7f053f1bb76f]
        /lib/libgobject-2.0.so.0(+0x1464b) [0x7f053f19d64b]
        /lib/libgobject-2.0.so.0(g_object_newv+0x1dd) [0x7f053f19f05d]
        /lib/libgobject-2.0.so.0(g_object_new+0x104) [0x7f053f19f814]
        /lib/libgtk-3.so.0(+0x19a5ba) [0x7f053d4635ba]
        /lib/libgtk-3.so.0(+0x37bdd7) [0x7f053d644dd7]
        /lib/libgobject-2.0.so.0(g_type_create_instance+0x1cf) [0x7f053f1bb76f]
        /lib/libgobject-2.0.so.0(+0x1464b) [0x7f053f19d64b]
        /lib/libgobject-2.0.so.0(g_object_newv+0x1dd) [0x7f053f19f05d]
        /lib/libgobject-2.0.so.0(g_object_new+0x104) [0x7f053f19f814]
        /lib/libgtk-3.so.0(gtk_label_new_with_mnemonic+0x19) [0x7f053d4e4a59]
        [0x41b69650]

What I expected to happen:

Get the usage/help informations. Better error handling.

This happens when:

  1. flatpak run org.sparkleshare.SparkleShare open

Since it seems to be passing everything to curl, with open --help, I get curl's help and about the same segfault. It might be better to add error handling here, and/or use libcurl directly.

glunardi commented 6 years ago

Seems it is a rather simple use of curl here when invoked with --open:

case $1 in open|--open) invite=date -u +%N open=echo $2 | sed 's/sparkleshare:\/\/addProject\///' curl --insecure --output ~/SparkleShare/.$invite.xml $open mono "@ABS_INSTALL_DIR@/SparkleShare.exe" ;; help|--help|version|--version) mono "@ABS_INSTALL_DIR@/SparkleShare.exe" help ;; *) mono "@ABS_INSTALL_DIR@/SparkleShare.exe" $2 ;; esac

Not sure what the intended use is here but it could check that there is "$2" argument. Something like this could work:

diff --git a/SparkleShare/Linux/sparkleshare.in b/SparkleShare/Linux/ sparkleshare.in index 06217ea9..0f1692a3 100755 --- a/SparkleShare/Linux/sparkleshare.in +++ b/SparkleShare/Linux/sparkleshare.in @@ -1,12 +1,17 @@

!/usr/bin/env bash

if [[ $UID -eq 0 ]]; then

On Fri, May 4, 2018 at 12:59 PM, Maxime Buquet notifications@github.com wrote:

Running on Arch with flatpak 0.11.7 and SparkleShare 2.0.1. What happened:

  • Sparkleshare segfaults

curl: no URL specified! curl: try 'curl --help' or 'curl --manual' for more information 17:42:01 Environment | SparkleShare 2.0.1 (Flatpak) 17:42:01 Environment | Git LFS 2.3.0 17:42:01 Environment | Git 2.14.1 17:42:01 Environment | GNOME (Unix 4.16.7.1) 17:42:01 Cmd | | gvfs-set-attribute "/home/user/SparkleShare" metadata::custom-icon-name org.sparkleshare.SparkleShare Stacktrace:

at <0xffffffff> at (wrapper managed-to-native) Gtk.Label.gtk_label_new_with_mnemonic (intptr) [0x00002] in :0 at Gtk.Label..ctor (string) [0x00062] in :0 at Gtk.Label..ctor () [0x00000] in :0 at SparkleShare.UserInterface..ctor () [0x0003c] in :0 at SparkleShare.SparkleShare.Main (string[]) [0x00128] in :0 at (wrapper runtime-invoke) .runtime_invoke_void_object (object,intptr,intptr,intptr) [0x0004e] in :0

Native stacktrace:

    mono() [0x4b7538]
    mono() [0x50e68e]
    mono() [0x42aca0]
    /lib/libpthread.so.0() [0x3154211800]
    /lib/libgtk-3.so.0(+0x2e4889) [0x7f053d5ad889]
    /lib/libgtk-3.so.0(+0x17d048) [0x7f053d446048]
    /lib/libgtk-3.so.0(+0x192154) [0x7f053d45b154]
    /lib/libgtk-3.so.0(+0x17e37c) [0x7f053d44737c]
    /lib/libgtk-3.so.0(+0x19207c) [0x7f053d45b07c]
    /lib/libgtk-3.so.0(+0x1920d5) [0x7f053d45b0d5]
    /lib/libgtk-3.so.0(+0x17ece2) [0x7f053d447ce2]
    /lib/libgobject-2.0.so.0(g_type_create_instance+0x1cf) [0x7f053f1bb76f]
    /lib/libgobject-2.0.so.0(+0x1464b) [0x7f053f19d64b]
    /lib/libgobject-2.0.so.0(g_object_newv+0x1dd) [0x7f053f19f05d]
    /lib/libgobject-2.0.so.0(g_object_new+0x104) [0x7f053f19f814]
    /lib/libgtk-3.so.0(+0x19a5ba) [0x7f053d4635ba]
    /lib/libgtk-3.so.0(+0x37bdd7) [0x7f053d644dd7]
    /lib/libgobject-2.0.so.0(g_type_create_instance+0x1cf) [0x7f053f1bb76f]
    /lib/libgobject-2.0.so.0(+0x1464b) [0x7f053f19d64b]
    /lib/libgobject-2.0.so.0(g_object_newv+0x1dd) [0x7f053f19f05d]
    /lib/libgobject-2.0.so.0(g_object_new+0x104) [0x7f053f19f814]
    /lib/libgtk-3.so.0(gtk_label_new_with_mnemonic+0x19) [0x7f053d4e4a59]
    [0x41b69650]

What I expected to happen:

Get the usage/help informations. Better error handling. This happens when:

  1. flatpak run org.sparkleshare.SparkleShare open

Since it seems to be passing everything to curl, with open --help, I get curl's help and about the same segfault. It might be better to add error handling here, and/or use libcurl directly.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hbons/SparkleShare/issues/1840, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlxFMntE6yv7MT-23tKUrE1doy2PYlmks5tvIj2gaJpZM4Ty9-b .

glunardi commented 6 years ago
diff --git a/SparkleShare/Linux/sparkleshare.in b/SparkleShare/Linux/sparkleshare.in
index 06217ea9..0f1692a3 100755
--- a/SparkleShare/Linux/sparkleshare.in
+++ b/SparkleShare/Linux/sparkleshare.in
@@ -1,12 +1,17 @@
 #!/usr/bin/env bash

 if [[ $UID -eq 0 ]]; then
-  echo "Please don't run SparkleShare as root. Things would go utterly wrong."
+  echo "Please don't run SparkleShare as root. Things would go utterly wrong. Exiting."
   exit 1
 fi

 case $1 in
   open|--open)
+
+     if [[ -z "$2" ]]; then
+       echo "An argument is required when using SparkleShare --open. Exiting."
+      exit 1
+     fi
     invite=`date -u +%N`
     open=`echo $2 | sed 's/sparkleshare:\/\/addProject\///'`
     curl --insecure --output ~/SparkleShare/.$invite.xml $open
Ppjet6 commented 6 years ago

On 2018/05/04, Guy Lunardi wrote:

diff --git a/SparkleShare/Linux/sparkleshare.in b/SparkleShare/Linux/sparkleshare.in
index 06217ea9..0f1692a3 100755
--- a/SparkleShare/Linux/sparkleshare.in
+++ b/SparkleShare/Linux/sparkleshare.in
@@ -1,12 +1,17 @@
 #!/usr/bin/env bash

 if [[ $UID -eq 0 ]]; then
-  echo "Please don't run SparkleShare as root. Things would go utterly wrong."
+  echo "Please don't run SparkleShare as root. Things would go utterly wrong. Exiting."
   exit 1
 fi

 case $1 in
   open|--open)
+
+     if [[ -z "$2" ]]; then
+       echo "An argument is required when using SparkleShare --open. Exiting."
+      exit 1
+     fi
     invite=`date -u +%N`
     open=`echo $2 | sed 's/sparkleshare:\/\/addProject\///'`
     curl --insecure --output ~/SparkleShare/.$invite.xml $open

It's not just an argument that is required. SparkleShare also segfaults running flatpak run org.sparkleshare.SparkleShare open --help.

I have to point out that I have sparkleshare running in the background already, with no folder setup yet. I assume the segfault is not directly related to what curl downloads or not. Maybe it doesn't like to be called twice?

-- Maxime “pep” Buquet

glunardi commented 6 years ago

I have to point out that I have sparkleshare running in the background already, with no folder setup yet. I assume the segfault is not directly related to what curl downloads or not. Maybe it doesn't like to be called twice?

Never tried before to run two instances of sparkleshare at the same time (why would you? :-) ).

It crashes outside of silly flatpak as well but maybe a little more gracefully:

[glunardi@bibou7 SparkleShare]$ 13:27:08 Environment | SparkleShare 3.28.0
13:27:08 Environment | Git LFS 
13:27:08 Environment | Git 2.14.3
13:27:08 Environment | GNOME (Unix 4.16.5.200)
13:27:08 Cmd |  | gvfs-set-attribute "/home/glunardi/SparkleShare" metadata::custom-icon-name org.sparkleshare.SparkleShare
13:27:08 Environment | GTK+ 3.22.26

(process:26338): Gtk-CRITICAL **: gtk_icon_theme_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
exception inside UnhandledException handler: Sharing violation on path /home/glunardi/.config/org.sparkleshare.SparkleShare/logs/log_2018-05-04.2.txt

[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at SparkleShare.UserInterface..ctor () [0x0008e] in <eb92d30b59994552b0bd642044229b0f>:0 
  at SparkleShare.SparkleShare.Main (System.String[] args) [0x00128] in <eb92d30b59994552b0bd642044229b0f>:0
hbons commented 6 years ago

I think the crash and the curl command failing are not related. It looks like an instance of #1778. The open command is used to handle invite files from the web browser and isn't really for manual use. What were you trying to do here?

You're right that the error handling should be better here. I'll rename this issue to track this process.

hbons commented 6 years ago

Took @glunardi's patch: 14353388e0eaf8d32198a71ca18a25e48da26a49 This will be fixed once the appindicator branch (which also includes command line usage improvements) is merged.