X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ED2KLink.cpp;h=47f3af8f0b8849a96728cf16e75bca1f592a16a3;hb=3cf3d0fbb0576ab0eaa3f9f0f0ca19d15192d0d0;hp=e1ec2ffba7070b5554dcb7cde130fe5695aa545b;hpb=dc3a8cc1faaeb0b9fd1c65d88b04000ac57519eb;p=ecparse.git diff --git a/ED2KLink.cpp b/ED2KLink.cpp index e1ec2ff..47f3af8 100644 --- a/ED2KLink.cpp +++ b/ED2KLink.cpp @@ -72,6 +72,7 @@ ED2KLink* ED2KLink::parseED2KLink(const char* buffer) { growingBuffer.write(tempBuffer, (char*) pipeIndex - tempBuffer); filename = (char*) malloc(growingBuffer.getLimit() + 1); growingBuffer.read(filename, growingBuffer.getLimit()); + sizeString[growingBuffer.getLimit()] = '\0'; growingBuffer.clear(); tempBuffer = pipeIndex + 1; @@ -85,6 +86,7 @@ ED2KLink* ED2KLink::parseED2KLink(const char* buffer) { growingBuffer.write(tempBuffer, (char*) pipeIndex - tempBuffer); sizeString = (char*) malloc(growingBuffer.getLimit() + 1); growingBuffer.read(sizeString, growingBuffer.getLimit()); + sizeString[growingBuffer.getLimit()] = '\0'; growingBuffer.clear(); tempBuffer = pipeIndex + 1; @@ -96,7 +98,10 @@ ED2KLink* ED2KLink::parseED2KLink(const char* buffer) { char byteBuffer[3]; byteBuffer[2] = '\0'; memcpy(byteBuffer, tempBuffer + hashIndex * 2, 2); - sscanf(byteBuffer, "%hhX", &hash[hashIndex]); + if (sscanf(byteBuffer, "%hhX", &hash[hashIndex]) != 1) { + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] could not parse ‘%c%c’ into a byte.\n", __FILE__, __LINE__, *(byteBuffer), *(byteBuffer + 1)); + return NULL; + } GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] parsed ‘%c%c’ as %02x.\n", __FILE__, __LINE__, *(byteBuffer), *(byteBuffer + 1), hash[hashIndex]); }