From 963eefcae53396ee9d4d580726ab196e569eaa75 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 22 Jul 2015 23:46:44 +0200 Subject: [PATCH] miniupnpc.c: dont break if USN is not set USN is mandatory, but don't break if the packet don't follow the standard and misses USN: header --- miniupnpc/miniupnpc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/miniupnpc/miniupnpc.c b/miniupnpc/miniupnpc.c index 83401db..035533b 100644 --- a/miniupnpc/miniupnpc.c +++ b/miniupnpc/miniupnpc.c @@ -701,17 +701,17 @@ upnpDiscoverDevices(const char * const deviceTypes[], const char * usn=NULL; int usnsize=0; parseMSEARCHReply(bufr, n, &descURL, &urlsize, &st, &stsize, &usn, &usnsize); - if(st&&descURL&&usn) { + if(st&&descURL) { #ifdef DEBUG printf("M-SEARCH Reply:\n ST: %.*s\n USN: %.*s\n Location: %.*s\n", - stsize, st, usnsize, usn, urlsize, descURL); + stsize, st, usnsize, (usn?usn:""), urlsize, descURL); #endif /* DEBUG */ for(tmp=devlist; tmp; tmp = tmp->pNext) { if(memcmp(tmp->descURL, descURL, urlsize) == 0 && tmp->descURL[urlsize] == '\0' && memcmp(tmp->st, st, stsize) == 0 && tmp->st[stsize] == '\0' && - memcmp(tmp->usn, usn, usnsize) == 0 && + (usnsize == 0 || memcmp(tmp->usn, usn, usnsize) == 0) && tmp->usn[usnsize] == '\0') break; } @@ -734,7 +734,8 @@ upnpDiscoverDevices(const char * const deviceTypes[], tmp->buffer[urlsize] = '\0'; memcpy(tmp->st, st, stsize); tmp->buffer[urlsize+1+stsize] = '\0'; - memcpy(tmp->usn, usn, usnsize); + if(usn != NULL) + memcpy(tmp->usn, usn, usnsize); tmp->buffer[urlsize+1+stsize+1+usnsize] = '\0'; tmp->scope_id = scope_id; devlist = tmp;