clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name nsUnixRemoteServer.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/components/remote -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/components/remote -resource-dir /usr/lib/llvm-20/lib/clang/20 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D _GLIBCXX_ASSERTIONS -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/remote -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/components/remote -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/profile -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/cloudproviders -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/gtk-3.0/unix-print -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-20/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2025-01-20-090804-167946-1 -x c++ /var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/remote/nsUnixRemoteServer.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | #include "nsUnixRemoteServer.h" |
| 9 | #include "nsGTKToolkit.h" |
| 10 | #include "nsCOMPtr.h" |
| 11 | #include "nsICommandLineRunner.h" |
| 12 | #include "nsCommandLine.h" |
| 13 | #include "nsIFile.h" |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | void nsUnixRemoteServer::SetStartupTokenOrTimestamp( |
| 22 | const nsACString& aStartupToken, uint32_t aTimestamp) { |
| 23 | nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit(); |
| 24 | if (!toolkit) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | if (!aStartupToken.IsEmpty()) { |
| 29 | toolkit->SetStartupToken(aStartupToken); |
| 30 | } |
| 31 | |
| 32 | toolkit->SetFocusTimestamp(aTimestamp); |
| 33 | } |
| 34 | |
| 35 | static bool FindExtensionParameterInCommand(const char* aParameterName, |
| 36 | const nsACString& aCommand, |
| 37 | char aSeparator, |
| 38 | nsACString* aValue) { |
| 39 | nsAutoCString searchFor; |
| 40 | searchFor.Append(aSeparator); |
| 41 | searchFor.Append(aParameterName); |
| 42 | searchFor.Append('='); |
| 43 | |
| 44 | nsACString::const_iterator start, end; |
| 45 | aCommand.BeginReading(start); |
| 46 | aCommand.EndReading(end); |
| 47 | if (!FindInReadable(searchFor, start, end)) return false; |
| 48 | |
| 49 | nsACString::const_iterator charStart, charEnd; |
| 50 | charStart = end; |
| 51 | aCommand.EndReading(charEnd); |
| 52 | nsACString::const_iterator idStart = charStart, idEnd; |
| 53 | if (FindCharInReadable(aSeparator, charStart, charEnd)) { |
| 54 | idEnd = charStart; |
| 55 | } else { |
| 56 | idEnd = charEnd; |
| 57 | } |
| 58 | *aValue = nsDependentCSubstring(idStart, idEnd); |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | const char* nsUnixRemoteServer::HandleCommandLine( |
| 63 | mozilla::Span<const char> aBuffer, uint32_t aTimestamp) { |
| 64 | nsCOMPtr<nsICommandLineRunner> cmdline(new nsCommandLine()); |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | if (aBuffer.size() < sizeof(uint32_t)) { |
| 1 | Assuming the condition is false | |
|
| |
| 72 | return "500 command not parseable"; |
| 73 | } |
| 74 | |
| 75 | uint32_t argc = |
| 76 | TO_LITTLE_ENDIAN32(*reinterpret_cast<const uint32_t*>(aBuffer.data())); |
| 77 | uint32_t offsetFilelist = ((argc + 1) * sizeof(uint32_t)); |
| 78 | if (offsetFilelist >= aBuffer.size()) { |
| 3 | | Assuming the condition is false | |
|
| |
| 79 | return "500 command not parseable"; |
| 80 | } |
| 81 | const char* workingDir = aBuffer.data() + offsetFilelist; |
| 82 | |
| 83 | nsCOMPtr<nsIFile> lf; |
| 84 | nsresult rv = |
| 85 | NS_NewNativeLocalFile(nsDependentCString(workingDir), getter_AddRefs(lf)); |
| 86 | if (NS_FAILED(rv)) { |
| 5 | | Assuming the condition is true | |
|
| |
| 87 | return "509 internal error"; |
| 88 | } |
| 89 | |
| 90 | const char** argv = (const char**)malloc(sizeof(char*) * argc); |
| |
| 91 | if (!argv) { |
| 8 | | Assuming 'argv' is non-null | |
|
| |
| 92 | return "509 internal error"; |
| 93 | } |
| 94 | |
| 95 | const uint32_t* offset = |
| 96 | reinterpret_cast<const uint32_t*>(aBuffer.data()) + 1; |
| 97 | nsAutoCString desktopStartupID; |
| 98 | |
| 99 | for (unsigned int i = 0; i < argc; ++i) { |
| 10 | | Assuming 'i' is < 'argc' | |
|
| 11 | | Loop condition is true. Entering loop body | |
|
| 100 | uint32_t argvOffset = TO_LITTLE_ENDIAN32(offset[i]); |
| 101 | if (argvOffset >= aBuffer.size()) { |
| 12 | | Assuming the condition is true | |
|
| |
| 102 | return "500 command not parseable"; |
| 14 | | Potential leak of memory pointed to by 'argv' |
|
| 103 | } |
| 104 | |
| 105 | argv[i] = aBuffer.data() + argvOffset; |
| 106 | |
| 107 | if (i == 0) { |
| 108 | nsDependentCString cmd(argv[0]); |
| 109 | FindExtensionParameterInCommand("STARTUP_TOKEN", cmd, ' ', |
| 110 | &desktopStartupID); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | rv = cmdline->Init(argc, argv, lf, nsICommandLine::STATE_REMOTE_AUTO); |
| 115 | |
| 116 | free(argv); |
| 117 | if (NS_FAILED(rv)) { |
| 118 | return "509 internal error"; |
| 119 | } |
| 120 | |
| 121 | SetStartupTokenOrTimestamp(desktopStartupID, aTimestamp); |
| 122 | |
| 123 | rv = cmdline->Run(); |
| 124 | |
| 125 | if (NS_ERROR_ABORT == rv) { |
| 126 | return "500 command not parseable"; |
| 127 | } |
| 128 | |
| 129 | if (NS_FAILED(rv)) { |
| 130 | return "509 internal error"; |
| 131 | } |
| 132 | |
| 133 | return "200 executed command"; |
| 134 | } |