Hello all,
Attached is a test C++ app to check if your specific implementation is
affected.
The test doesn't guarantee it's not affected, but it does reproduce the
error for me.
Basically, it contains both the old and the new strf function, and the
result on my Debian unstable AMD64 system looks like this:
---
Trying new strf function.
New function completed successfully.
Trying old strf function.
[1] 29011 segmentation fault ./a.out
---
I.e. the new code completed, the old code segfaulted.
So if you are the maintainer of Enigma packages (as I am for the Debian
packages, and the Ubuntu packages are directly derived without major
modifications), you can use this to check if you should do an update.
Note that you should check on all architectures, in particular on AMD64.
P.S. Debian and Fedora are so far reported affected.
best regards,
Erich Schubert
#include <stdio.h>
#include <string>
#include <cassert>
#include <cstdarg>
using namespace std;
string vstrf(const char *format, va_list argPtr) {
static size_t buf_size = 16;
static char *buffer = new char[buf_size];
size_t length;
while (1) {
if (!buffer) {
assert(buffer); // to stop when debugging
return "<alloc problem>";
}
length = vsnprintf(buffer, buf_size, format, argPtr);
if (length < buf_size) break; // string fits into current buffer
// otherwise resize buffer :
buf_size += buf_size/2;
// fprintf(stderr, "Reallocating vstrf-buffer to size=%u\n", buf_size);
delete [] buffer;
buffer = new char[buf_size];
}
return string(buffer, length);
}
string strf(const char *format, ...)
{
va_list argPtr;
va_start(argPtr, format);
string result = vstrf(format, argPtr);
va_end(argPtr);
return result;
}
string strf2(const char *format, ...) {
static size_t buf_size = 512;
static char *buffer = new char[buf_size];
va_list argPtr;
size_t length;
while (true) {
if (!buffer) {
assert(buffer); // to stop when debugging
return "<alloc problem>";
}
va_start(argPtr, format);
length = vsnprintf(buffer, buf_size, format, argPtr);
va_end(argPtr);
if (length >= 0 && length < buf_size - 1)
// string fits into current buffer
return std::string(buffer, length);
// otherwise resize buffer :
buf_size *= 2;
// fprintf(stderr, "Reallocating vstrf-buffer to size=%u\n", buf_size);
delete [] buffer;
buffer = new char[buf_size];
}
}
#define FOO "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
int main(int argc, char** argv) {
fprintf(stderr, "Trying new strf function.\n");
strf2("%s%s%s",FOO FOO FOO FOO, FOO FOO FOO FOO, FOO FOO FOO FOO);
fprintf(stderr, "New function completed successfully.\n");
fprintf(stderr, "Trying old strf function.\n");
strf("%s%s%s",FOO FOO FOO FOO, FOO FOO FOO FOO, FOO FOO FOO FOO);
fprintf(stderr, "Old function completed successfully.\n");
}
_______________________________________________
Enigma-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/enigma-devel