Bug 553032 - fix calls to printf-likes for -Wformat-security; r?evilpie draft
authorTom Tromey <tom@tromey.com>
Mon, 17 Oct 2016 16:37:35 -0600
changeset 426585 ab50ed1b2ae4f5a87d1b98f7e9a0b191be18f684
parent 426584 a05135cf885c28e2e7291c30ab6d3fcaf776fa45
child 426586 677bf039291c0c133c2e1f3d7d542ad6674235eb
push id32752
push userbmo:ttromey@mozilla.com
push dateTue, 18 Oct 2016 20:29:12 +0000
reviewersevilpie
bugs553032
milestone52.0a1
Bug 553032 - fix calls to printf-likes for -Wformat-security; r?evilpie MozReview-Commit-ID: D3AFsWzHTEF
dom/plugins/base/nsJSNPRuntime.cpp
js/src/asmjs/WasmBinaryIterator.h
js/src/asmjs/WasmTextToBinary.cpp
js/src/irregexp/RegExpEngine.cpp
js/src/jit/Ion.cpp
js/src/jit/JSONSpewer.cpp
js/xpconnect/src/XPCWrappedJSClass.cpp
js/xpconnect/wrappers/AccessCheck.cpp
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -633,17 +633,17 @@ ThrowJSExceptionASCII(JSContext *cx, con
 
     if (str) {
       JS::Rooted<JS::Value> exn(cx, JS::StringValue(str));
       ::JS_SetPendingException(cx, exn);
     }
 
     PopException();
   } else {
-    ::JS_ReportErrorASCII(cx, message);
+    ::JS_ReportErrorASCII(cx, "%s", message);
   }
 }
 
 static bool
 ReportExceptionIfPending(JSContext *cx)
 {
   const char *ex = PeekException();
 
--- a/js/src/asmjs/WasmBinaryIterator.h
+++ b/js/src/asmjs/WasmBinaryIterator.h
@@ -720,17 +720,17 @@ ExprIter<Policy>::unrecognizedOpcode(Exp
 
     return fail(error.get());
 }
 
 template <typename Policy>
 bool
 ExprIter<Policy>::fail(const char* msg)
 {
-    return d_.fail(msg);
+    return d_.fail("%s", msg);
 }
 
 template <typename Policy>
 inline bool
 ExprIter<Policy>::pushControl(LabelKind kind, ExprType type, bool reachable)
 {
     return controlStack_.emplaceBack(kind, type, reachable, valueStack_.length());
 }
--- a/js/src/asmjs/WasmTextToBinary.cpp
+++ b/js/src/asmjs/WasmTextToBinary.cpp
@@ -1483,17 +1483,17 @@ struct WasmParseContext
     WasmParseContext(const char16_t* text, LifoAlloc& lifo, UniqueChars* error)
       : ts(text, error),
         lifo(lifo),
         error(error),
         dtoaState(NewDtoaState())
     {}
 
     bool fail(const char* message) {
-        error->reset(JS_smprintf(message));
+        error->reset(js_strdup(message));
         return false;
     }
     ~WasmParseContext() {
         DestroyDtoaState(dtoaState);
     }
 };
 
 } // end anonymous namespace
--- a/js/src/irregexp/RegExpEngine.cpp
+++ b/js/src/irregexp/RegExpEngine.cpp
@@ -1867,17 +1867,17 @@ irregexp::CompilePattern(JSContext* cx, 
     }
 
     if (node == nullptr)
         node = alloc.newInfallible<EndNode>(&alloc, EndNode::BACKTRACK);
 
     Analysis analysis(cx, ignore_case, is_ascii, unicode);
     analysis.EnsureAnalyzed(node);
     if (analysis.has_failed()) {
-        JS_ReportErrorASCII(cx, analysis.errorMessage());
+        JS_ReportErrorASCII(cx, "%s", analysis.errorMessage());
         return RegExpCode();
     }
 
     Maybe<jit::JitContext> ctx;
     Maybe<NativeRegExpMacroAssembler> native_assembler;
     Maybe<InterpretedRegExpMacroAssembler> interpreted_assembler;
 
     RegExpMacroAssembler* assembler;
--- a/js/src/jit/Ion.cpp
+++ b/js/src/jit/Ion.cpp
@@ -2132,17 +2132,17 @@ TrackIonAbort(JSContext* cx, JSScript* s
     void* ptr = script->baselineScript()->method()->raw();
     JitcodeGlobalEntry& entry = table->lookupInfallible(ptr);
     entry.baselineEntry().trackIonAbort(pc, message);
 }
 
 static void
 TrackAndSpewIonAbort(JSContext* cx, JSScript* script, const char* message)
 {
-    JitSpew(JitSpew_IonAbort, message);
+    JitSpew(JitSpew_IonAbort, "%s", message);
     TrackIonAbort(cx, script, script->code(), message);
 }
 
 static AbortReason
 IonCompile(JSContext* cx, JSScript* script,
            BaselineFrame* baselineFrame, jsbytecode* osrPc, bool constructing,
            bool recompile, OptimizationLevel optimizationLevel)
 {
--- a/js/src/jit/JSONSpewer.cpp
+++ b/js/src/jit/JSONSpewer.cpp
@@ -153,17 +153,17 @@ JSONSpewer::beginFunction(JSScript* scri
         stringProperty("name", "asm.js compilation");
     beginListProperty("passes");
 }
 
 void
 JSONSpewer::beginPass(const char* pass)
 {
     beginObject();
-    stringProperty("name", pass);
+    stringProperty("name", "%s", pass);
 }
 
 void
 JSONSpewer::spewMResumePoint(MResumePoint* rp)
 {
     if (!rp)
         return;
 
--- a/js/xpconnect/src/XPCWrappedJSClass.cpp
+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
@@ -966,17 +966,17 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWra
         return NS_ERROR_FAILURE;
 
     // [implicit_jscontext] and [optional_argc] have a different calling
     // convention, which we don't support for JS-implemented components.
     if (info->WantsOptArgc() || info->WantsContext()) {
         const char* str = "IDL methods marked with [implicit_jscontext] "
                           "or [optional_argc] may not be implemented in JS";
         // Throw and warn for good measure.
-        JS_ReportErrorASCII(cx, str);
+        JS_ReportErrorASCII(cx, "%s", str);
         NS_WARNING(str);
         return CheckForException(ccx, aes, name, GetInterfaceName());
     }
 
     RootedValue fval(cx);
     RootedObject obj(cx, wrapper->GetJSObject());
     RootedObject thisObj(cx, obj);
 
--- a/js/xpconnect/wrappers/AccessCheck.cpp
+++ b/js/xpconnect/wrappers/AccessCheck.cpp
@@ -266,20 +266,20 @@ AccessCheck::checkPassToPrivilegedCode(J
             return false;
     }
     return true;
 }
 
 enum Access { READ = (1<<0), WRITE = (1<<1), NO_ACCESS = 0 };
 
 static void
-EnterAndThrowASCII(JSContext* cx, JSObject* wrapper, const char* msg)
+EnterAndThrowASCII(JSContext* cx, JSObject* wrapper, const char* msg, ...)
 {
     JSAutoCompartment ac(cx, wrapper);
-    JS_ReportErrorASCII(cx, msg);
+    JS_ReportErrorASCII(cx, "%s", msg);
 }
 
 bool
 ExposedPropertiesOnly::check(JSContext* cx, HandleObject wrapper, HandleId id, Wrapper::Action act)
 {
     RootedObject wrappedObject(cx, Wrapper::wrappedObject(wrapper));
 
     if (act == Wrapper::CALL)