stack corruption in the webservice code
Dirk Hohndel
dirk at hohndel.org
Tue Dec 10 12:24:33 UTC 2013
On Tue, 2013-12-10 at 10:18 -0800, Linus Torvalds wrote:
> Basically, every time you convert from QString to a "normal" string,
> you need to keep the QString around as long as that string is used. Or
> do a strdup(). Or just not convert at all, and keep it as a QString,
> so that the compiler will do the proper liveness analysis and keep it
> around.
>
> Too bad we don't get compiler warnings for things like this. And
> apparently malloc library debugging doesn't work very well for
> automatic C++ objects (since the compiler presumably just allocates
> them on the stack).
>
> There might be more of these hiding. But the minimal patch would
> appear to be something like the following (totally untested and
> whitespace-damaged) diff.
This looks correct to me.
May I whitespacify it and add you SOB?
/D
> ---
>
> qt-ui/subsurfacewebservices.cpp | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
> index a8421def936f..f3d03eb602ac 100644
> --- a/qt-ui/subsurfacewebservices.cpp
> +++ b/qt-ui/subsurfacewebservices.cpp
> @@ -115,7 +115,7 @@ static char *prepare_dives_for_divelogs(const bool selected)
>
> /* generate a random filename and create/open that file with zip_open */
> QString tempfileQ = QDir::tempPath() + "/import-" +
> QString::number(qrand() % 99999999) + ".dld";
> - tempfile = tempfileQ.toLocal8Bit().data();
> + tempfile = strdup(tempfileQ.toLocal8Bit().data());
> zip = zip_open(tempfile, ZIP_CREATE, NULL);
>
> if (!zip) {
> @@ -184,8 +184,6 @@ static char *prepare_dives_for_divelogs(const bool selected)
> }
> }
> zip_close(zip);
> - /* let's call this again */
> - tempfile = tempfileQ.toLocal8Bit().data();
> return tempfile;
> }
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
More information about the subsurface
mailing list