X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ED2KLink.cpp;h=47f3af8f0b8849a96728cf16e75bca1f592a16a3;hb=3cf3d0fbb0576ab0eaa3f9f0f0ca19d15192d0d0;hp=1a8206651f7edc5ff258c1bafb431db6eef2bc3e;hpb=87c3276013058baf0a606510737ae03ae1c79727;p=ecparse.git diff --git a/ED2KLink.cpp b/ED2KLink.cpp index 1a82066..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,21 +86,28 @@ 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; size = atol(sizeString); GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] parsed size “%s” into %d.\n", __FILE__, __LINE__, sizeString, size); + free(sizeString); for (hashIndex = 0; hashIndex < 16; hashIndex++) { 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]); } - return new ED2KLink(filename, size, hash); + ED2KLink* ed2kLink = new ED2KLink(filename, size, hash); + free(filename); + return ed2kLink; } const char* ED2KLink::getLink() {