From 647b106a7cc2517ef4b9af6e0b7c607a7cfd4ac2 Mon Sep 17 00:00:00 2001 From: Fufu Fang Date: Fri, 25 Oct 2019 02:55:41 +0100 Subject: [PATCH] fixed segfault if the root of the airsonic folder has music file --- Makefile | 2 +- src/sonic.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b6583a1..85593de 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION=1.2.0 -CFLAGS+= -O2 -Wall -Wextra -Wshadow -rdynamic -D_GNU_SOURCE\ +CFLAGS+= -g3 -O2 -Wall -Wextra -Wshadow -rdynamic -D_GNU_SOURCE\ -D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\"\ `pkg-config --cflags-only-I gumbo libcurl fuse uuid expat` LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -luuid -lexpat diff --git a/src/sonic.c b/src/sonic.c index ec0f157..29c522e 100644 --- a/src/sonic.c +++ b/src/sonic.c @@ -139,6 +139,7 @@ static void XMLCALL XML_process_single_element(void *data, const char *elem, int linkname_set = 0; for (int i = 0; attr[i]; i += 2) { + printf("%s: %s\n", attr[i], attr[i+1]); if (!strcmp("id", attr[i])) { link->sonic_id = atoi(attr[i+1]); link->sonic_id_str = calloc(MAX_FILENAME_LEN, sizeof(char)); @@ -164,8 +165,13 @@ static void XMLCALL XML_process_single_element(void *data, const char *elem, */ if (!strcmp("path", attr[i])) { memset(link->linkname, 0, MAX_FILENAME_LEN); - strncpy(link->linkname, strrchr(attr[i+1], '/') + 1, - MAX_FILENAME_LEN); + /* Skip to the last '/' if it exists */ + char *s = strrchr(attr[i+1], '/'); + if (s) { + strncpy(link->linkname, s + 1, MAX_FILENAME_LEN); + } else { + strncpy(link->linkname, attr[i+1], MAX_FILENAME_LEN); + } linkname_set = 1; continue; }