LINBIT / csync2

file synchronization tool using librsync and current state databases
GNU General Public License v2.0
145 stars 39 forks source link

Assertion failure and segmentation fault on Alpine Linux 3.10/3.11 #25

Closed odi79 closed 4 years ago

odi79 commented 4 years ago

When trying to use csync2 on Alpine Linux (either with the Alpine csync2 community package or with the compiled current csync2 version here from Github), the tool stops with "Assertion failed: i == len-1 (checktxt.c: csync_genchecktxt: 94)".

I fixed this by changing the string format in two lines in "checktxt.c":

--- checktxt.c.orig
+++ checktxt.c
@@ -49,7 +49,7 @@
        xxprintf("v1");

        if ( !S_ISLNK(st->st_mode) && !S_ISDIR(st->st_mode) )
-               xxprintf(":mtime=%Ld", ign_mtime ? (long long)0 : (long long)st->st_mtime);
+               xxprintf(":mtime=%lld", ign_mtime ? (long long)0 : (long long)st->st_mtime);

        if ( !csync_ignore_mod )
                xxprintf(":mode=%d", (int)st->st_mode);
@@ -61,7 +61,7 @@
                xxprintf(":gid=%d", (int)st->st_gid);

        if ( S_ISREG(st->st_mode) )
-               xxprintf(":type=reg:size=%Ld", (long long)st->st_size);
+               xxprintf(":type=reg:size=%lld", (long long)st->st_size);

        if ( S_ISDIR(st->st_mode) )
                xxprintf(":type=dir");

The format specifiers listed in "http://www.cplusplus.com/reference/cstdio/printf/" were used for this.

Segmentation faults in a later phase of execution of "csync2 -xv" could be fixed in "update.c" accordingly:

--- update.c.orig
+++ update.c
@@ -469,7 +469,7 @@

 skip_action:
        if ( !S_ISLNK(st.st_mode) ) {
-               conn_printf("SETIME %s %s %Ld\n",
+               conn_printf("SETIME %s %s %lld\n",
                                url_encode(key), url_encode(filename),
                                (long long)st.st_mtime);
                last_conn_status = read_conn_status(filename, peername);

csync2 works for me on Alpine Linux with the changes shown above applied. Note that I neither checked on other platforms nor did I investigate on the root cause.