fixed segfault if the root of the airsonic folder has music file

This commit is contained in:
Fufu Fang 2019-10-25 02:55:41 +01:00
parent 93b4711d75
commit 647b106a7c
No known key found for this signature in database
GPG Key ID: 0F6BB5EF6F8BB729
2 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -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;
}