Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GM_log and GM_xhr truncates at NULL byte #1061

Closed
xobofni opened this issue Nov 30, 2009 · 5 comments
Closed

GM_log and GM_xhr truncates at NULL byte #1061

xobofni opened this issue Nov 30, 2009 · 5 comments
Milestone

Comments

@xobofni
Copy link

xobofni commented Nov 30, 2009

Strings with NULL bytes are truncated at the NULL byte. In the script below, the output of GM_log is truncated but alert() is not.

// ==UserScript==
// @name GM_log stops on null byte
// @namespace http://a.www.com
// @description GM_log does not display parts of a string after a null byte.
// @include *
// ==/UserScript==

// only "null byte here" shows up in the log
GM_log("null byte here\0words after");

// the full text "null byte herewords after" shows up
alert("null byte here\0words after");

I'm also seeing this with GM_xmlhttpRequest when trying to POST binary data.

edit: This is with GM 0.8.20090920.2 and Firefox 3.5.5

@arantius
Copy link
Collaborator

I'd love to see an example of what you're talking about with XHR like with log.

@erikvold
Copy link
Contributor

erikvold commented Apr 7, 2010

here is a patch to fix the issue for GM_log..

@erikvold
Copy link
Contributor

I'm not sure this should be changed for GM_xhr, the string received from the userscript is passed along to a standard component, why should GM mess with the string and not the userscript?

@tim-smart
Copy link

If you look at the C++ source this behavior is expected. logStringMessage implements a nsConsoleMessage which is just a pointer to a unsigned short array ( http://mxr.mozilla.org/mozilla-central/source/xpcom/base/nsConsoleMessage.cpp#51 ). Throwing a null byte in your string will obviously be interpreted directly as a memory allocation delimiter.

I'm not sure if we want to protect the user from this or not, but I agree it is inconsistent with other ECMAScript API's. Maybe this should be filed upstream as well?

I suspect it is a similar case for GM_xmlhttpRequest... Does XMLHttpRequest follow suit?

@erikvold
Copy link
Contributor

I suspect it is a similar case for GM_xmlhttpRequest... Does XMLHttpRequest follow suit?

GM_xhr is just feeding the values thru to XMLHttpRequest w/ a chrome principle, which I imagine works the same as w/ a page principle .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants