From 761b4c87e8b0b426f93f635f5ec639102b41b0c1 Mon Sep 17 00:00:00 2001 From: "raveit65 (via Travis CI)" Date: Wed, 21 Feb 2024 17:14:24 +0000 Subject: Deploy mate-desktop/caja-extensions to github.com/mate-desktop/caja-extensions.git:gh-pages --- .../index.html | 102 ++ .../report-41c4fb.html | 1352 ++++++++++++++++++++ .../report-559a68.html | 1352 ++++++++++++++++++++ .../report-b7a538.html | 1034 +++++++++++++++ .../scanview.css | 62 + .../sorttable.js | 492 +++++++ 6 files changed, 4394 insertions(+) create mode 100644 2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/index.html create mode 100644 2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-41c4fb.html create mode 100644 2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-559a68.html create mode 100644 2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-b7a538.html create mode 100644 2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/scanview.css create mode 100644 2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/sorttable.js (limited to '2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1') diff --git a/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/index.html b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/index.html new file mode 100644 index 0000000..20a65b8 --- /dev/null +++ b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/index.html @@ -0,0 +1,102 @@ + + +rootdir - scan-build results + + + + + + +

rootdir - scan-build results

+ + + + + + + +
User:root@cef0633fd1b4
Working Directory:/rootdir
Command Line:make -j 2
Clang Version:clang version 17.0.6 (Fedora 17.0.6-1.fc39) +
Date:Sat Feb 3 19:07:45 2024
+

Bug Summary

+ + + + + + +
Bug TypeQuantityDisplay?
All Bugs3
Logic error
Out-of-bound access1
Security
Potential insecure memory buffer bounds restriction in call 'strcpy'2
+

Reports

+ + + + + + + + + + + + + + + + + + + + + + + +
Bug GroupBug Type ▾FileFunction/MethodLinePath Length
Logic errorOut-of-bound accessxattr-tags/caja-xattr-tags-extension.ccaja_xattr_tags_get_xdg_tags12314View Report
SecurityPotential insecure memory buffer bounds restriction in call 'strcpy'open-terminal/caja-open-terminal.cappend_sftp_info2931View Report
SecurityPotential insecure memory buffer bounds restriction in call 'strcpy'open-terminal/caja-open-terminal.cappend_sftp_info2941View Report
+ + diff --git a/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-41c4fb.html b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-41c4fb.html new file mode 100644 index 0000000..b6b7404 --- /dev/null +++ b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-41c4fb.html @@ -0,0 +1,1352 @@ + + + +caja-open-terminal.c + + + + + + + + + + + + + + + + + + + + + + + + + + +

Bug Summary

+ + + + +
File:open-terminal/caja-open-terminal.c
Warning:line 293, column 2
Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
+ +

Annotated Source Code

+

Press '?' + to see keyboard shortcuts

+ + +
clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name caja-open-terminal.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -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 -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/open-terminal -resource-dir /usr/bin/../lib/clang/17 -D HAVE_CONFIG_H -I . -I .. -D G_DISABLE_DEPRECATED -D GDK_PIXBUF_DISABLE_DEPRECATED -D MATELOCALEDIR="/usr/local/share/locale" -I .. -D G_LOG_DOMAIN="Caja-Open-Terminal" -D DATADIR="/usr/local/share" -I /usr/include/caja -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/at-spi-2.0 -I /usr/include/blkid -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/mate-desktop-2.0 -I /usr/include/gtk-3.0 -I /usr/include/startup-notification-1.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/dconf -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -D PIC -internal-isystem /usr/bin/../lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -fdebug-compilation-dir=/rootdir/open-terminal -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-checker security.insecureAPI.strcpy -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-03-190745-6463-1 -x c caja-open-terminal.c +
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1/*
2 * caja-open-terminal.c
3 *
4 * Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * Author: Christian Neumair <chris@gnome-de.org>
21 *
22 */
23
24#ifdef HAVE_CONFIG_H1
25#include <config.h>
26#endif
27
28#include <glib/gi18n-lib.h>
29
30#include "caja-open-terminal.h"
31
32#include <libcaja-extension/caja-menu-provider.h>
33#include <libcaja-extension/caja-configurable.h>
34
35#include <gtk/gtkicontheme.h>
36#include <gtk/gtkwidget.h>
37#include <gtk/gtkmain.h>
38
39#include <libmate-desktop/mate-desktop-item.h>
40#include <gio/gio.h>
41
42#include <errno(*__errno_location ()).h>
43#include <fcntl.h>
44#include <string.h> /* for strcmp, strdup, ... */
45#include <unistd.h> /* for chdir */
46#include <stdlib.h> /* for atoi */
47#include <sys/stat.h>
48
49#define COT_SCHEMA"org.mate.caja-open-terminal" "org.mate.caja-open-terminal"
50#define COT_DESKTOP_KEY"desktop-opens-home-dir" "desktop-opens-home-dir"
51#define CAJA_SCHEMA"org.mate.caja.preferences" "org.mate.caja.preferences"
52#define CAJA_DESKTOP_KEY"desktop-is-home-dir" "desktop-is-home-dir"
53#define TERM_SCHEMA"org.mate.applications-terminal" "org.mate.applications-terminal"
54#define TERM_EXEC_KEY"exec" "exec"
55
56static void caja_open_terminal_instance_init (CajaOpenTerminal *cvs);
57static void caja_open_terminal_class_init (CajaOpenTerminalClass *class);
58
59static GType terminal_type = 0;
60
61typedef enum {
62 FILE_INFO_LOCAL,
63 FILE_INFO_DESKTOP,
64 FILE_INFO_SFTP,
65 FILE_INFO_OTHER
66} TerminalFileInfo;
67
68static TerminalFileInfo
69get_terminal_file_info (CajaFileInfo *file_info)
70{
71 TerminalFileInfo ret;
72 char *uri;
73 char *uri_scheme;
74
75 uri = caja_file_info_get_activation_uri (file_info);
76 uri_scheme = g_uri_parse_scheme (uri);
77
78 if (strcmp (uri_scheme, "file") == 0) {
79 ret = FILE_INFO_LOCAL;
80 } else if (strcmp (uri_scheme, "x-caja-desktop") == 0) {
81 ret = FILE_INFO_DESKTOP;
82 } else if (strcmp (uri_scheme, "sftp") == 0 ||
83 strcmp (uri_scheme, "ssh") == 0) {
84 ret = FILE_INFO_SFTP;
85 } else {
86 ret = FILE_INFO_OTHER;
87 }
88
89 g_free (uri_scheme);
90 g_free (uri);
91
92 return ret;
93}
94
95static char *
96lookup_in_data_dir (const char *basename,
97 const char *data_dir)
98{
99 char *path;
100
101 path = g_build_filename (data_dir, basename, NULL((void*)0));
102 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
103 g_free (path);
104 return NULL((void*)0);
105 }
106
107 return path;
108}
109
110static char *
111lookup_in_data_dirs (const char *basename)
112{
113 const char * const *system_data_dirs;
114 const char *user_data_dir;
115 char *retval;
116 int i;
117
118 user_data_dir = g_get_user_data_dir ();
119 system_data_dirs = g_get_system_data_dirs ();
120
121 if ((retval = lookup_in_data_dir (basename, user_data_dir))) {
122 return retval;
123 }
124
125 for (i = 0; system_data_dirs[i]; i++) {
126 if ((retval = lookup_in_data_dir (basename, system_data_dirs[i])))
127 return retval;
128 }
129
130 return NULL((void*)0);
131}
132
133static inline gboolean
134desktop_opens_home_dir (void)
135{
136 gboolean result;
137 GSettings* settings;
138
139 settings = g_settings_new (COT_SCHEMA"org.mate.caja-open-terminal");
140 result = g_settings_get_boolean (settings, COT_DESKTOP_KEY"desktop-opens-home-dir");
141 g_object_unref (settings);
142 return result;
143}
144
145static inline gboolean
146set_desktop_opens_home_dir (gboolean val)
147{
148 gboolean result;
149 GSettings* settings;
150
151 settings = g_settings_new (COT_SCHEMA"org.mate.caja-open-terminal");
152 result = g_settings_set_boolean (settings, COT_DESKTOP_KEY"desktop-opens-home-dir", val);
153 g_object_unref (settings);
154 return result;
155}
156
157static inline gboolean
158desktop_is_home_dir (void)
159{
160 gboolean result;
161 GSettings* settings;
162
163 settings = g_settings_new (CAJA_SCHEMA"org.mate.caja.preferences");
164 result = g_settings_get_boolean (settings, CAJA_DESKTOP_KEY"desktop-is-home-dir");
165 g_object_unref (settings);
166 return result;
167}
168
169static inline gchar*
170default_terminal_application (void)
171{
172 gchar *result;
173 GSettings* settings;
174
175 settings = g_settings_new (TERM_SCHEMA"org.mate.applications-terminal");
176 result = g_settings_get_string (settings, TERM_EXEC_KEY"exec");
177 g_object_unref (settings);
178
179 if (result == NULL((void*)0) || strlen (result) == 0) {
180 g_free (result);
181 result = g_strdup ("mate-terminal")g_strdup_inline ("mate-terminal");
182 }
183
184 return result;
185}
186
187static inline gboolean
188set_default_terminal_application (const gchar* exec)
189{
190 gboolean result;
191 GSettings* settings;
192
193 settings = g_settings_new (TERM_SCHEMA"org.mate.applications-terminal");
194 result = g_settings_set_string (settings, TERM_EXEC_KEY"exec", exec);
195 g_object_unref (settings);
196 return result;
197}
198
199static void
200parse_sftp_uri (GFile *file, char **host, guint *port, char **user,
201 char **path)
202{
203 char *uri = g_file_get_uri (file);
204 char *u, *h, *s, *p;
205 char *h_end;
206
207 g_assert (uri != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_17
; if (uri != ((void*)0)) _g_boolean_var_17 = 1; else _g_boolean_var_17
= 0; _g_boolean_var_17; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 207, ((const char
*) (__func__)), "uri != NULL"); } while (0)
;
208
209 u = strchr(uri, ':');
210 g_assert (u != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_18
; if (u != ((void*)0)) _g_boolean_var_18 = 1; else _g_boolean_var_18
= 0; _g_boolean_var_18; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 210, ((const char
*) (__func__)), "u != NULL"); } while (0)
;
211 u += 3; /* Skip over :// to userid */
212
213 p = strchr (u, '/');
214 h = strchr(u, '@');
215
216 if (h && ((p == NULL((void*)0)) || (h < p))) {
217 *h='\0';
218 h++;
219 } else {
220 h = u;
221 u = NULL((void*)0);
222 }
223
224 s = strchr(h, ':');
225
226 if (s && (p == NULL((void*)0) || s < p)) {
227 h_end = s;
228 *s = '\0';
229 s++;
230 } else {
231 h_end = p;
232 s = NULL((void*)0);
233 }
234
235 if (h_end == NULL((void*)0)) {
236 h_end = h + strlen(h);
237 }
238
239 *user = g_strdup(u)g_strdup_inline (u);
240 *port = s == NULL((void*)0) ? 0 : atoi(s); /* FIXME: getservbyname ? */
241 *path = g_uri_unescape_string (p, "/");
242 *h_end = '\0';
243 *host = g_strdup(h)g_strdup_inline (h);
244
245 g_free (uri);
246}
247
248static void
249append_sftp_info (char **terminal_exec,
250 CajaFileInfo *file_info)
251{
252 GFile *vfs_uri;
253 char *host_name, *path, *user_name;
254 char *user_host, *cmd, *quoted_cmd;
255 char *host_port_switch;
256 char *quoted_path;
257 char *remote_cmd;
258 char *quoted_remote_cmd;
259 guint host_port;
260
261 g_assert (terminal_exec != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_19
; if (terminal_exec != ((void*)0)) _g_boolean_var_19 = 1; else
_g_boolean_var_19 = 0; _g_boolean_var_19; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 261, ((const char
*) (__func__)), "terminal_exec != NULL"); } while (0)
;
262 g_assert (file_info != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_20
; if (file_info != ((void*)0)) _g_boolean_var_20 = 1; else _g_boolean_var_20
= 0; _g_boolean_var_20; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 262, ((const char
*) (__func__)), "file_info != NULL"); } while (0)
;
263
264 vfs_uri = g_file_new_for_uri (caja_file_info_get_activation_uri (file_info));
265 g_assert (vfs_uri != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_21
; if (vfs_uri != ((void*)0)) _g_boolean_var_21 = 1; else _g_boolean_var_21
= 0; _g_boolean_var_21; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 265, ((const char
*) (__func__)), "vfs_uri != NULL"); } while (0)
;
266
267 g_assert (g_file_has_uri_scheme(vfs_uri, "sftp")==TRUE ||do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_22
; if (g_file_has_uri_scheme(vfs_uri, "sftp")==(!(0)) || g_file_has_uri_scheme
(vfs_uri, "ssh")==(!(0))) _g_boolean_var_22 = 1; else _g_boolean_var_22
= 0; _g_boolean_var_22; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 268, ((const char
*) (__func__)), "g_file_has_uri_scheme(vfs_uri, \"sftp\")==TRUE || g_file_has_uri_scheme(vfs_uri, \"ssh\")==TRUE"
); } while (0)
268 g_file_has_uri_scheme(vfs_uri, "ssh")==TRUE)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_22
; if (g_file_has_uri_scheme(vfs_uri, "sftp")==(!(0)) || g_file_has_uri_scheme
(vfs_uri, "ssh")==(!(0))) _g_boolean_var_22 = 1; else _g_boolean_var_22
= 0; _g_boolean_var_22; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 268, ((const char
*) (__func__)), "g_file_has_uri_scheme(vfs_uri, \"sftp\")==TRUE || g_file_has_uri_scheme(vfs_uri, \"ssh\")==TRUE"
); } while (0)
;
269
270 parse_sftp_uri (vfs_uri, &host_name, &host_port, &user_name, &path);
271
272 if (host_port == 0) {
273 host_port_switch = g_strdup ("")g_strdup_inline ("");
274 } else {
275 host_port_switch = g_strdup_printf ("-p %d", host_port);
276 }
277
278 if (user_name != NULL((void*)0)) {
279 user_host = g_strdup_printf ("%s@%s", user_name, host_name);
280 } else {
281 user_host = g_strdup (host_name)g_strdup_inline (host_name);
282 }
283
284 quoted_path = g_shell_quote (path);
285 remote_cmd = g_strdup_printf ("cd %s && $SHELL -l", quoted_path);
286 quoted_remote_cmd = g_shell_quote (remote_cmd);
287
288 cmd = g_strdup_printf ("ssh %s %s -t %s", user_host, host_port_switch, quoted_remote_cmd);
289 quoted_cmd = g_shell_quote (cmd);
290 g_free (cmd);
291
292 *terminal_exec = g_realloc (*terminal_exec, strlen (*terminal_exec) + strlen (quoted_cmd) + 4 + 1);
293 strcpy (*terminal_exec + strlen (*terminal_exec), " -e ");
Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
294 strcpy (*terminal_exec + strlen (*terminal_exec), quoted_cmd);
295
296 g_free (host_name);
297 g_free (user_name);
298 g_free (host_port_switch);
299 g_free (path);
300 g_free (quoted_path);
301
302 g_free (remote_cmd);
303 g_free (quoted_remote_cmd);
304 g_free (quoted_cmd);
305 g_free (user_host);
306 g_object_unref (vfs_uri);
307}
308
309static void
310open_terminal_callback (CajaMenuItem *item,
311 CajaFileInfo *file_info)
312{
313 GdkDisplay *display;
314 const gchar *display_str;
315 const gchar *old_display_str;
316 gchar *uri;
317 gchar **argv, *terminal_exec;
318 gchar *working_directory;
319 gchar *dfile;
320 MateDesktopItem *ditem;
321 GdkScreen *screen;
322
323 terminal_exec = default_terminal_application();
324
325 switch (get_terminal_file_info (file_info)) {
326 case FILE_INFO_LOCAL:
327 uri = caja_file_info_get_activation_uri (file_info);
328 if (uri != NULL((void*)0)) {
329 working_directory = g_filename_from_uri (uri, NULL((void*)0), NULL((void*)0));
330 } else {
331 working_directory = g_strdup (g_get_home_dir ())g_strdup_inline (g_get_home_dir ());
332 }
333 g_free (uri);
334 break;
335
336 case FILE_INFO_DESKTOP:
337 if (desktop_is_home_dir () || desktop_opens_home_dir ()) {
338 working_directory = g_strdup (g_get_home_dir ())g_strdup_inline (g_get_home_dir ());
339 } else {
340 working_directory = g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP))g_strdup_inline (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP
))
;
341 }
342 break;
343
344 case FILE_INFO_SFTP:
345 working_directory = NULL((void*)0);
346 append_sftp_info (&terminal_exec, file_info);
347 break;
348
349 case FILE_INFO_OTHER:
350 default:
351 g_assert_not_reached ()do { g_assertion_message_expr ("Caja-Open-Terminal", "caja-open-terminal.c"
, 351, ((const char*) (__func__)), ((void*)0)); } while (0)
;
352 }
353
354 if (g_str_has_prefix (terminal_exec, "mate-terminal")(__builtin_constant_p ("mate-terminal")? __extension__ ({ const
char * const __str = (terminal_exec); const char * const __prefix
= ("mate-terminal"); gboolean __result = (0); if (__builtin_expect
(__extension__ ({ int _g_boolean_var_23; if (__str == ((void
*)0) || __prefix == ((void*)0)) _g_boolean_var_23 = 1; else _g_boolean_var_23
= 0; _g_boolean_var_23; }), 0)) __result = (g_str_has_prefix
) (__str, __prefix); else { const size_t __str_len = strlen (
((__str) + !(__str))); const size_t __prefix_len = strlen (((
__prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (terminal_exec, "mate-terminal"
) )
) {
355 dfile = lookup_in_data_dirs ("applications/mate-terminal.desktop");
356 } else {
357 dfile = NULL((void*)0);
358 }
359
360 g_shell_parse_argv (terminal_exec, NULL((void*)0), &argv, NULL((void*)0));
361
362 display_str = NULL((void*)0);
363 old_display_str = g_getenv ("DISPLAY");
364
365 screen = g_object_get_data (G_OBJECT (item)((((GObject*) (void *) ((item))))), "CajaOpenTerminal::screen");
366 display = gdk_screen_get_display (screen);
367 if (screen != NULL((void*)0)) {
368 display_str = gdk_display_get_name (display);
369 g_setenv ("DISPLAY", display_str, TRUE(!(0)));
370 }
371
372 if (dfile != NULL((void*)0)) {
373 int orig_cwd = -1;
374
375 do {
376 orig_cwd = open (".", O_RDONLY00);
377 } while (orig_cwd == -1 && errno(*__errno_location ()) == EINTR4);
378
379 if (orig_cwd == -1) {
380 g_message ("CajaOpenTerminal: Failed to open current Caja working directory.");
381 } else if (working_directory != NULL((void*)0)) {
382
383 if (chdir (working_directory) == -1) {
384 int ret;
385
386 g_message ("CajaOpenTerminal: Failed to change Caja working directory to \"%s\".",
387 working_directory);
388
389 do {
390 ret = close (orig_cwd);
391 } while (ret == -1 && errno(*__errno_location ()) == EINTR4);
392
393 if (ret == -1) {
394 g_message ("CajaOpenTerminal: Failed to close() current Caja working directory.");
395 }
396
397 orig_cwd = -1;
398 }
399 }
400
401 ditem = mate_desktop_item_new_from_file (dfile, 0, NULL((void*)0));
402
403 mate_desktop_item_set_string (ditem, "Exec", terminal_exec);
404 if (gtk_get_current_event_time () > 0) {
405 mate_desktop_item_set_launch_time (ditem, gtk_get_current_event_time ());
406 }
407 mate_desktop_item_launch (ditem, NULL((void*)0), MATE_DESKTOP_ITEM_LAUNCH_USE_CURRENT_DIR, NULL((void*)0));
408 mate_desktop_item_unref (ditem);
409 g_free (dfile);
410
411 if (orig_cwd != -1) {
412 int ret;
413
414 ret = fchdir (orig_cwd);
415 if (ret == -1) {
416 g_message ("CajaOpenTerminal: Failed to change back Caja working directory to original location after changing it to \"%s\".",
417 working_directory);
418 }
419
420 do {
421 ret = close (orig_cwd);
422 } while (ret == -1 && errno(*__errno_location ()) == EINTR4);
423
424 if (ret == -1) {
425 g_message ("CajaOpenTerminal: Failed to close Caja working directory.");
426 }
427 }
428 } else {
429 g_spawn_async (working_directory,
430 argv,
431 NULL((void*)0),
432 G_SPAWN_SEARCH_PATH,
433 NULL((void*)0),
434 NULL((void*)0),
435 NULL((void*)0),
436 NULL((void*)0));
437 }
438
439 g_setenv ("DISPLAY", old_display_str, TRUE(!(0)));
440
441 g_strfreev (argv);
442 g_free (terminal_exec);
443 g_free (working_directory);
444}
445
446static CajaMenuItem *
447open_terminal_menu_item_new (CajaFileInfo *file_info,
448 TerminalFileInfo terminal_file_info,
449 GdkScreen *screen,
450 gboolean is_file_item)
451{
452 CajaMenuItem *ret;
453 const char *name;
454 const char *tooltip;
455
456 switch (terminal_file_info) {
457 case FILE_INFO_LOCAL:
458 case FILE_INFO_SFTP:
459 name = _("Open in _Terminal")((char *) g_dgettext ("caja-extensions", "Open in _Terminal")
)
;
460 if (is_file_item) {
461 tooltip = _("Open the currently selected folder in a terminal")((char *) g_dgettext ("caja-extensions", "Open the currently selected folder in a terminal"
))
;
462 } else {
463 tooltip = _("Open the currently open folder in a terminal")((char *) g_dgettext ("caja-extensions", "Open the currently open folder in a terminal"
))
;
464 }
465 break;
466
467 case FILE_INFO_DESKTOP:
468 if (desktop_opens_home_dir ()) {
469 name = _("Open _Terminal")((char *) g_dgettext ("caja-extensions", "Open _Terminal"));
470 tooltip = _("Open a terminal")((char *) g_dgettext ("caja-extensions", "Open a terminal"));
471 } else {
472 name = _("Open in _Terminal")((char *) g_dgettext ("caja-extensions", "Open in _Terminal")
)
;
473 tooltip = _("Open the currently open folder in a terminal")((char *) g_dgettext ("caja-extensions", "Open the currently open folder in a terminal"
))
;
474 }
475 break;
476
477 case FILE_INFO_OTHER:
478 default:
479 g_assert_not_reached ()do { g_assertion_message_expr ("Caja-Open-Terminal", "caja-open-terminal.c"
, 479, ((const char*) (__func__)), ((void*)0)); } while (0)
;
480 }
481
482 ret = caja_menu_item_new ("CajaOpenTerminal::open_terminal",
483 name, tooltip, "terminal");
484
485 g_object_set_data (G_OBJECT (ret)((((GObject*) (void *) ((ret))))),
486 "CajaOpenTerminal::screen",
487 screen);
488
489 g_object_set_data_full (G_OBJECT (ret)((((GObject*) (void *) ((ret))))), "file-info",
490 g_object_ref (file_info)((__typeof__ (file_info)) (g_object_ref) (file_info)),
491 (GDestroyNotify) g_object_unref);
492 g_signal_connect (ret, "activate",g_signal_connect_data ((ret), ("activate"), (((GCallback) (open_terminal_callback
))), (file_info), ((void*)0), (GConnectFlags) 0)
493 G_CALLBACK (open_terminal_callback),g_signal_connect_data ((ret), ("activate"), (((GCallback) (open_terminal_callback
))), (file_info), ((void*)0), (GConnectFlags) 0)
494 file_info)g_signal_connect_data ((ret), ("activate"), (((GCallback) (open_terminal_callback
))), (file_info), ((void*)0), (GConnectFlags) 0)
;
495
496 return ret;
497}
498
499static GList *
500caja_open_terminal_get_background_items (CajaMenuProvider *provider,
501 GtkWidget *window,
502 CajaFileInfo *file_info)
503{
504 CajaMenuItem *item;
505 TerminalFileInfo terminal_file_info;
506
507 terminal_file_info = get_terminal_file_info (file_info);
508 switch (terminal_file_info) {
509 case FILE_INFO_LOCAL:
510 case FILE_INFO_DESKTOP:
511 case FILE_INFO_SFTP:
512 item = open_terminal_menu_item_new (file_info, terminal_file_info, gtk_widget_get_screen (window), FALSE(0));
513 return g_list_append (NULL((void*)0), item);
514
515 case FILE_INFO_OTHER:
516 return NULL((void*)0);
517
518 default:
519 g_assert_not_reached ()do { g_assertion_message_expr ("Caja-Open-Terminal", "caja-open-terminal.c"
, 519, ((const char*) (__func__)), ((void*)0)); } while (0)
;
520 }
521}
522
523static GList *
524caja_open_terminal_get_file_items (CajaMenuProvider *provider,
525 GtkWidget *window,
526 GList *files)
527{
528 CajaMenuItem *item;
529 TerminalFileInfo terminal_file_info;
530
531 if (g_list_length (files) != 1 ||
532 (!caja_file_info_is_directory (files->data) &&
533 caja_file_info_get_file_type (files->data) != G_FILE_TYPE_SHORTCUT &&
534 caja_file_info_get_file_type (files->data) != G_FILE_TYPE_MOUNTABLE)) {
535 return NULL((void*)0);
536 }
537
538 terminal_file_info = get_terminal_file_info (files->data);
539 switch (terminal_file_info) {
540 case FILE_INFO_LOCAL:
541 case FILE_INFO_SFTP:
542 item = open_terminal_menu_item_new (files->data, terminal_file_info, gtk_widget_get_screen (window), TRUE(!(0)));
543 return g_list_append (NULL((void*)0), item);
544
545 case FILE_INFO_DESKTOP:
546 case FILE_INFO_OTHER:
547 return NULL((void*)0);
548
549 default:
550 g_assert_not_reached ()do { g_assertion_message_expr ("Caja-Open-Terminal", "caja-open-terminal.c"
, 550, ((const char*) (__func__)), ((void*)0)); } while (0)
;
551 }
552}
553
554static void
555caja_open_terminal_run_config (CajaConfigurable *provider)
556{
557 GtkWidget *extconf_dialog, *extconf_content, *extconf_desktophomedir, *extconf_inform1, *extconf_inform2, *extconf_exec;
558 gchar * terminal;
559
560 extconf_dialog = gtk_dialog_new ();
561 extconf_content = gtk_dialog_get_content_area (GTK_DIALOG (extconf_dialog)((((GtkDialog*) (void *) ((extconf_dialog))))));
562
563 extconf_desktophomedir = gtk_check_button_new_with_label (_("Open at Home if trying to open on desktop")((char *) g_dgettext ("caja-extensions", "Open at Home if trying to open on desktop"
))
);
564 extconf_exec = gtk_entry_new ();
565 extconf_inform1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
566 extconf_inform2 = gtk_label_new (_("Terminal application:")((char *) g_dgettext ("caja-extensions", "Terminal application:"
))
);
567
568 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (extconf_desktophomedir)((((GtkToggleButton*) (void *) ((extconf_desktophomedir))))), desktop_opens_home_dir ());
569
570 terminal = default_terminal_application();
571 gtk_entry_set_text (GTK_ENTRY (extconf_exec)((((GtkEntry*) (void *) ((extconf_exec))))), terminal);
572 g_free (terminal);
573
574 gtk_container_add (GTK_CONTAINER (extconf_inform1)((((GtkContainer*) (void *) ((extconf_inform1))))), extconf_inform2);
575 gtk_widget_show (extconf_inform2);
576 gtk_container_add (GTK_CONTAINER (extconf_inform1)((((GtkContainer*) (void *) ((extconf_inform1))))), extconf_exec);
577 gtk_widget_show (extconf_exec);
578 gtk_box_set_child_packing (GTK_BOX (extconf_inform1)((((GtkBox*) (void *) ((extconf_inform1))))), extconf_exec, FALSE(0), FALSE(0), 0, GTK_PACK_END);
579
580 gtk_container_add (GTK_CONTAINER (extconf_content)((((GtkContainer*) (void *) ((extconf_content))))), extconf_desktophomedir);
581 gtk_widget_show (extconf_desktophomedir);
582 gtk_container_add (GTK_CONTAINER (extconf_content)((((GtkContainer*) (void *) ((extconf_content))))), extconf_inform1);
583 gtk_widget_show (extconf_inform1);
584 gtk_container_add (GTK_CONTAINER (extconf_content)((((GtkContainer*) (void *) ((extconf_content))))), extconf_exec);
585 gtk_widget_show (extconf_exec);
586 gtk_dialog_add_buttons (GTK_DIALOG (extconf_dialog)((((GtkDialog*) (void *) ((extconf_dialog))))), _("Close")((char *) g_dgettext ("caja-extensions", "Close")), GTK_RESPONSE_OK, NULL((void*)0));
587
588 gtk_container_set_border_width (GTK_CONTAINER (extconf_inform1)((((GtkContainer*) (void *) ((extconf_inform1))))), 6);
589 gtk_container_set_border_width (GTK_CONTAINER (extconf_dialog)((((GtkContainer*) (void *) ((extconf_dialog))))), 6);
590 gtk_container_set_border_width (GTK_CONTAINER (extconf_content)((((GtkContainer*) (void *) ((extconf_content))))), 6);
591
592 gtk_window_set_title (GTK_WINDOW (extconf_dialog)((((GtkWindow*) (void *) ((extconf_dialog))))), _("open-terminal Configuration")((char *) g_dgettext ("caja-extensions", "open-terminal Configuration"
))
);
593 gtk_dialog_run (GTK_DIALOG (extconf_dialog)((((GtkDialog*) (void *) ((extconf_dialog))))));
594
595 set_default_terminal_application (gtk_entry_get_text (GTK_ENTRY (extconf_exec)((((GtkEntry*) (void *) ((extconf_exec)))))));
596 set_desktop_opens_home_dir (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (extconf_desktophomedir)((((GtkToggleButton*) (void *) ((extconf_desktophomedir)))))));
597
598 gtk_widget_destroy (GTK_WIDGET (extconf_dialog)((((GtkWidget*) (void *) ((extconf_dialog))))));
599}
600
601static void
602caja_open_terminal_menu_provider_iface_init (CajaMenuProviderIface *iface)
603{
604 iface->get_background_items = caja_open_terminal_get_background_items;
605 iface->get_file_items = caja_open_terminal_get_file_items;
606}
607
608static void
609caja_open_terminal_configurable_iface_init (CajaConfigurableIface *iface)
610{
611 iface->run_config = caja_open_terminal_run_config;
612}
613
614static void
615caja_open_terminal_instance_init (CajaOpenTerminal *cvs)
616{
617}
618
619static void
620caja_open_terminal_class_init (CajaOpenTerminalClass *class)
621{
622}
623
624GType
625caja_open_terminal_get_type (void)
626{
627 return terminal_type;
628}
629
630void
631caja_open_terminal_register_type (GTypeModule *module)
632{
633 static const GTypeInfo info = {
634 sizeof (CajaOpenTerminalClass),
635 (GBaseInitFunc) NULL((void*)0),
636 (GBaseFinalizeFunc) NULL((void*)0),
637 (GClassInitFunc) caja_open_terminal_class_init,
638 NULL((void*)0),
639 NULL((void*)0),
640 sizeof (CajaOpenTerminal),
641 0,
642 (GInstanceInitFunc) caja_open_terminal_instance_init,
643 NULL((void*)0)
644 };
645
646 static const GInterfaceInfo menu_provider_iface_info = {
647 (GInterfaceInitFunc) caja_open_terminal_menu_provider_iface_init,
648 NULL((void*)0),
649 NULL((void*)0)
650 };
651
652 static const GInterfaceInfo configurable_iface_info = {
653 (GInterfaceInitFunc) caja_open_terminal_configurable_iface_init,
654 NULL((void*)0),
655 NULL((void*)0)
656 };
657
658 terminal_type = g_type_module_register_type (module,
659 G_TYPE_OBJECT((GType) ((20) << (2))),
660 "CajaOpenTerminal",
661 &info, 0);
662
663 g_type_module_add_interface (module,
664 terminal_type,
665 CAJA_TYPE_MENU_PROVIDER(caja_menu_provider_get_type ()),
666 &menu_provider_iface_info);
667
668 g_type_module_add_interface (module,
669 terminal_type,
670 CAJA_TYPE_CONFIGURABLE(caja_configurable_get_type ()),
671 &configurable_iface_info);
672}
diff --git a/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-559a68.html b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-559a68.html new file mode 100644 index 0000000..32d8d58 --- /dev/null +++ b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-559a68.html @@ -0,0 +1,1352 @@ + + + +caja-open-terminal.c + + + + + + + + + + + + + + + + + + + + + + + + + + +

Bug Summary

+ + + + +
File:open-terminal/caja-open-terminal.c
Warning:line 294, column 2
Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
+ +

Annotated Source Code

+

Press '?' + to see keyboard shortcuts

+ + +
clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name caja-open-terminal.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -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 -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/open-terminal -resource-dir /usr/bin/../lib/clang/17 -D HAVE_CONFIG_H -I . -I .. -D G_DISABLE_DEPRECATED -D GDK_PIXBUF_DISABLE_DEPRECATED -D MATELOCALEDIR="/usr/local/share/locale" -I .. -D G_LOG_DOMAIN="Caja-Open-Terminal" -D DATADIR="/usr/local/share" -I /usr/include/caja -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/at-spi-2.0 -I /usr/include/blkid -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -I /usr/include/mate-desktop-2.0 -I /usr/include/gtk-3.0 -I /usr/include/startup-notification-1.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/dconf -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/blkid -I /usr/include/at-spi-2.0 -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -D PIC -internal-isystem /usr/bin/../lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -fdebug-compilation-dir=/rootdir/open-terminal -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-checker security.insecureAPI.strcpy -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-03-190745-6463-1 -x c caja-open-terminal.c +
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1/*
2 * caja-open-terminal.c
3 *
4 * Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * Author: Christian Neumair <chris@gnome-de.org>
21 *
22 */
23
24#ifdef HAVE_CONFIG_H1
25#include <config.h>
26#endif
27
28#include <glib/gi18n-lib.h>
29
30#include "caja-open-terminal.h"
31
32#include <libcaja-extension/caja-menu-provider.h>
33#include <libcaja-extension/caja-configurable.h>
34
35#include <gtk/gtkicontheme.h>
36#include <gtk/gtkwidget.h>
37#include <gtk/gtkmain.h>
38
39#include <libmate-desktop/mate-desktop-item.h>
40#include <gio/gio.h>
41
42#include <errno(*__errno_location ()).h>
43#include <fcntl.h>
44#include <string.h> /* for strcmp, strdup, ... */
45#include <unistd.h> /* for chdir */
46#include <stdlib.h> /* for atoi */
47#include <sys/stat.h>
48
49#define COT_SCHEMA"org.mate.caja-open-terminal" "org.mate.caja-open-terminal"
50#define COT_DESKTOP_KEY"desktop-opens-home-dir" "desktop-opens-home-dir"
51#define CAJA_SCHEMA"org.mate.caja.preferences" "org.mate.caja.preferences"
52#define CAJA_DESKTOP_KEY"desktop-is-home-dir" "desktop-is-home-dir"
53#define TERM_SCHEMA"org.mate.applications-terminal" "org.mate.applications-terminal"
54#define TERM_EXEC_KEY"exec" "exec"
55
56static void caja_open_terminal_instance_init (CajaOpenTerminal *cvs);
57static void caja_open_terminal_class_init (CajaOpenTerminalClass *class);
58
59static GType terminal_type = 0;
60
61typedef enum {
62 FILE_INFO_LOCAL,
63 FILE_INFO_DESKTOP,
64 FILE_INFO_SFTP,
65 FILE_INFO_OTHER
66} TerminalFileInfo;
67
68static TerminalFileInfo
69get_terminal_file_info (CajaFileInfo *file_info)
70{
71 TerminalFileInfo ret;
72 char *uri;
73 char *uri_scheme;
74
75 uri = caja_file_info_get_activation_uri (file_info);
76 uri_scheme = g_uri_parse_scheme (uri);
77
78 if (strcmp (uri_scheme, "file") == 0) {
79 ret = FILE_INFO_LOCAL;
80 } else if (strcmp (uri_scheme, "x-caja-desktop") == 0) {
81 ret = FILE_INFO_DESKTOP;
82 } else if (strcmp (uri_scheme, "sftp") == 0 ||
83 strcmp (uri_scheme, "ssh") == 0) {
84 ret = FILE_INFO_SFTP;
85 } else {
86 ret = FILE_INFO_OTHER;
87 }
88
89 g_free (uri_scheme);
90 g_free (uri);
91
92 return ret;
93}
94
95static char *
96lookup_in_data_dir (const char *basename,
97 const char *data_dir)
98{
99 char *path;
100
101 path = g_build_filename (data_dir, basename, NULL((void*)0));
102 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
103 g_free (path);
104 return NULL((void*)0);
105 }
106
107 return path;
108}
109
110static char *
111lookup_in_data_dirs (const char *basename)
112{
113 const char * const *system_data_dirs;
114 const char *user_data_dir;
115 char *retval;
116 int i;
117
118 user_data_dir = g_get_user_data_dir ();
119 system_data_dirs = g_get_system_data_dirs ();
120
121 if ((retval = lookup_in_data_dir (basename, user_data_dir))) {
122 return retval;
123 }
124
125 for (i = 0; system_data_dirs[i]; i++) {
126 if ((retval = lookup_in_data_dir (basename, system_data_dirs[i])))
127 return retval;
128 }
129
130 return NULL((void*)0);
131}
132
133static inline gboolean
134desktop_opens_home_dir (void)
135{
136 gboolean result;
137 GSettings* settings;
138
139 settings = g_settings_new (COT_SCHEMA"org.mate.caja-open-terminal");
140 result = g_settings_get_boolean (settings, COT_DESKTOP_KEY"desktop-opens-home-dir");
141 g_object_unref (settings);
142 return result;
143}
144
145static inline gboolean
146set_desktop_opens_home_dir (gboolean val)
147{
148 gboolean result;
149 GSettings* settings;
150
151 settings = g_settings_new (COT_SCHEMA"org.mate.caja-open-terminal");
152 result = g_settings_set_boolean (settings, COT_DESKTOP_KEY"desktop-opens-home-dir", val);
153 g_object_unref (settings);
154 return result;
155}
156
157static inline gboolean
158desktop_is_home_dir (void)
159{
160 gboolean result;
161 GSettings* settings;
162
163 settings = g_settings_new (CAJA_SCHEMA"org.mate.caja.preferences");
164 result = g_settings_get_boolean (settings, CAJA_DESKTOP_KEY"desktop-is-home-dir");
165 g_object_unref (settings);
166 return result;
167}
168
169static inline gchar*
170default_terminal_application (void)
171{
172 gchar *result;
173 GSettings* settings;
174
175 settings = g_settings_new (TERM_SCHEMA"org.mate.applications-terminal");
176 result = g_settings_get_string (settings, TERM_EXEC_KEY"exec");
177 g_object_unref (settings);
178
179 if (result == NULL((void*)0) || strlen (result) == 0) {
180 g_free (result);
181 result = g_strdup ("mate-terminal")g_strdup_inline ("mate-terminal");
182 }
183
184 return result;
185}
186
187static inline gboolean
188set_default_terminal_application (const gchar* exec)
189{
190 gboolean result;
191 GSettings* settings;
192
193 settings = g_settings_new (TERM_SCHEMA"org.mate.applications-terminal");
194 result = g_settings_set_string (settings, TERM_EXEC_KEY"exec", exec);
195 g_object_unref (settings);
196 return result;
197}
198
199static void
200parse_sftp_uri (GFile *file, char **host, guint *port, char **user,
201 char **path)
202{
203 char *uri = g_file_get_uri (file);
204 char *u, *h, *s, *p;
205 char *h_end;
206
207 g_assert (uri != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_24
; if (uri != ((void*)0)) _g_boolean_var_24 = 1; else _g_boolean_var_24
= 0; _g_boolean_var_24; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 207, ((const char
*) (__func__)), "uri != NULL"); } while (0)
;
208
209 u = strchr(uri, ':');
210 g_assert (u != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_25
; if (u != ((void*)0)) _g_boolean_var_25 = 1; else _g_boolean_var_25
= 0; _g_boolean_var_25; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 210, ((const char
*) (__func__)), "u != NULL"); } while (0)
;
211 u += 3; /* Skip over :// to userid */
212
213 p = strchr (u, '/');
214 h = strchr(u, '@');
215
216 if (h && ((p == NULL((void*)0)) || (h < p))) {
217 *h='\0';
218 h++;
219 } else {
220 h = u;
221 u = NULL((void*)0);
222 }
223
224 s = strchr(h, ':');
225
226 if (s && (p == NULL((void*)0) || s < p)) {
227 h_end = s;
228 *s = '\0';
229 s++;
230 } else {
231 h_end = p;
232 s = NULL((void*)0);
233 }
234
235 if (h_end == NULL((void*)0)) {
236 h_end = h + strlen(h);
237 }
238
239 *user = g_strdup(u)g_strdup_inline (u);
240 *port = s == NULL((void*)0) ? 0 : atoi(s); /* FIXME: getservbyname ? */
241 *path = g_uri_unescape_string (p, "/");
242 *h_end = '\0';
243 *host = g_strdup(h)g_strdup_inline (h);
244
245 g_free (uri);
246}
247
248static void
249append_sftp_info (char **terminal_exec,
250 CajaFileInfo *file_info)
251{
252 GFile *vfs_uri;
253 char *host_name, *path, *user_name;
254 char *user_host, *cmd, *quoted_cmd;
255 char *host_port_switch;
256 char *quoted_path;
257 char *remote_cmd;
258 char *quoted_remote_cmd;
259 guint host_port;
260
261 g_assert (terminal_exec != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_26
; if (terminal_exec != ((void*)0)) _g_boolean_var_26 = 1; else
_g_boolean_var_26 = 0; _g_boolean_var_26; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 261, ((const char
*) (__func__)), "terminal_exec != NULL"); } while (0)
;
262 g_assert (file_info != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_27
; if (file_info != ((void*)0)) _g_boolean_var_27 = 1; else _g_boolean_var_27
= 0; _g_boolean_var_27; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 262, ((const char
*) (__func__)), "file_info != NULL"); } while (0)
;
263
264 vfs_uri = g_file_new_for_uri (caja_file_info_get_activation_uri (file_info));
265 g_assert (vfs_uri != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_28
; if (vfs_uri != ((void*)0)) _g_boolean_var_28 = 1; else _g_boolean_var_28
= 0; _g_boolean_var_28; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 265, ((const char
*) (__func__)), "vfs_uri != NULL"); } while (0)
;
266
267 g_assert (g_file_has_uri_scheme(vfs_uri, "sftp")==TRUE ||do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_29
; if (g_file_has_uri_scheme(vfs_uri, "sftp")==(!(0)) || g_file_has_uri_scheme
(vfs_uri, "ssh")==(!(0))) _g_boolean_var_29 = 1; else _g_boolean_var_29
= 0; _g_boolean_var_29; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 268, ((const char
*) (__func__)), "g_file_has_uri_scheme(vfs_uri, \"sftp\")==TRUE || g_file_has_uri_scheme(vfs_uri, \"ssh\")==TRUE"
); } while (0)
268 g_file_has_uri_scheme(vfs_uri, "ssh")==TRUE)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_29
; if (g_file_has_uri_scheme(vfs_uri, "sftp")==(!(0)) || g_file_has_uri_scheme
(vfs_uri, "ssh")==(!(0))) _g_boolean_var_29 = 1; else _g_boolean_var_29
= 0; _g_boolean_var_29; }), 1)) ; else g_assertion_message_expr
("Caja-Open-Terminal", "caja-open-terminal.c", 268, ((const char
*) (__func__)), "g_file_has_uri_scheme(vfs_uri, \"sftp\")==TRUE || g_file_has_uri_scheme(vfs_uri, \"ssh\")==TRUE"
); } while (0)
;
269
270 parse_sftp_uri (vfs_uri, &host_name, &host_port, &user_name, &path);
271
272 if (host_port == 0) {
273 host_port_switch = g_strdup ("")g_strdup_inline ("");
274 } else {
275 host_port_switch = g_strdup_printf ("-p %d", host_port);
276 }
277
278 if (user_name != NULL((void*)0)) {
279 user_host = g_strdup_printf ("%s@%s", user_name, host_name);
280 } else {
281 user_host = g_strdup (host_name)g_strdup_inline (host_name);
282 }
283
284 quoted_path = g_shell_quote (path);
285 remote_cmd = g_strdup_printf ("cd %s && $SHELL -l", quoted_path);
286 quoted_remote_cmd = g_shell_quote (remote_cmd);
287
288 cmd = g_strdup_printf ("ssh %s %s -t %s", user_host, host_port_switch, quoted_remote_cmd);
289 quoted_cmd = g_shell_quote (cmd);
290 g_free (cmd);
291
292 *terminal_exec = g_realloc (*terminal_exec, strlen (*terminal_exec) + strlen (quoted_cmd) + 4 + 1);
293 strcpy (*terminal_exec + strlen (*terminal_exec), " -e ");
294 strcpy (*terminal_exec + strlen (*terminal_exec), quoted_cmd);
Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
295
296 g_free (host_name);
297 g_free (user_name);
298 g_free (host_port_switch);
299 g_free (path);
300 g_free (quoted_path);
301
302 g_free (remote_cmd);
303 g_free (quoted_remote_cmd);
304 g_free (quoted_cmd);
305 g_free (user_host);
306 g_object_unref (vfs_uri);
307}
308
309static void
310open_terminal_callback (CajaMenuItem *item,
311 CajaFileInfo *file_info)
312{
313 GdkDisplay *display;
314 const gchar *display_str;
315 const gchar *old_display_str;
316 gchar *uri;
317 gchar **argv, *terminal_exec;
318 gchar *working_directory;
319 gchar *dfile;
320 MateDesktopItem *ditem;
321 GdkScreen *screen;
322
323 terminal_exec = default_terminal_application();
324
325 switch (get_terminal_file_info (file_info)) {
326 case FILE_INFO_LOCAL:
327 uri = caja_file_info_get_activation_uri (file_info);
328 if (uri != NULL((void*)0)) {
329 working_directory = g_filename_from_uri (uri, NULL((void*)0), NULL((void*)0));
330 } else {
331 working_directory = g_strdup (g_get_home_dir ())g_strdup_inline (g_get_home_dir ());
332 }
333 g_free (uri);
334 break;
335
336 case FILE_INFO_DESKTOP:
337 if (desktop_is_home_dir () || desktop_opens_home_dir ()) {
338 working_directory = g_strdup (g_get_home_dir ())g_strdup_inline (g_get_home_dir ());
339 } else {
340 working_directory = g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP))g_strdup_inline (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP
))
;
341 }
342 break;
343
344 case FILE_INFO_SFTP:
345 working_directory = NULL((void*)0);
346 append_sftp_info (&terminal_exec, file_info);
347 break;
348
349 case FILE_INFO_OTHER:
350 default:
351 g_assert_not_reached ()do { g_assertion_message_expr ("Caja-Open-Terminal", "caja-open-terminal.c"
, 351, ((const char*) (__func__)), ((void*)0)); } while (0)
;
352 }
353
354 if (g_str_has_prefix (terminal_exec, "mate-terminal")(__builtin_constant_p ("mate-terminal")? __extension__ ({ const
char * const __str = (terminal_exec); const char * const __prefix
= ("mate-terminal"); gboolean __result = (0); if (__builtin_expect
(__extension__ ({ int _g_boolean_var_30; if (__str == ((void
*)0) || __prefix == ((void*)0)) _g_boolean_var_30 = 1; else _g_boolean_var_30
= 0; _g_boolean_var_30; }), 0)) __result = (g_str_has_prefix
) (__str, __prefix); else { const size_t __str_len = strlen (
((__str) + !(__str))); const size_t __prefix_len = strlen (((
__prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (terminal_exec, "mate-terminal"
) )
) {
355 dfile = lookup_in_data_dirs ("applications/mate-terminal.desktop");
356 } else {
357 dfile = NULL((void*)0);
358 }
359
360 g_shell_parse_argv (terminal_exec, NULL((void*)0), &argv, NULL((void*)0));
361
362 display_str = NULL((void*)0);
363 old_display_str = g_getenv ("DISPLAY");
364
365 screen = g_object_get_data (G_OBJECT (item)((((GObject*) (void *) ((item))))), "CajaOpenTerminal::screen");
366 display = gdk_screen_get_display (screen);
367 if (screen != NULL((void*)0)) {
368 display_str = gdk_display_get_name (display);
369 g_setenv ("DISPLAY", display_str, TRUE(!(0)));
370 }
371
372 if (dfile != NULL((void*)0)) {
373 int orig_cwd = -1;
374
375 do {
376 orig_cwd = open (".", O_RDONLY00);
377 } while (orig_cwd == -1 && errno(*__errno_location ()) == EINTR4);
378
379 if (orig_cwd == -1) {
380 g_message ("CajaOpenTerminal: Failed to open current Caja working directory.");
381 } else if (working_directory != NULL((void*)0)) {
382
383 if (chdir (working_directory) == -1) {
384 int ret;
385
386 g_message ("CajaOpenTerminal: Failed to change Caja working directory to \"%s\".",
387 working_directory);
388
389 do {
390 ret = close (orig_cwd);
391 } while (ret == -1 && errno(*__errno_location ()) == EINTR4);
392
393 if (ret == -1) {
394 g_message ("CajaOpenTerminal: Failed to close() current Caja working directory.");
395 }
396
397 orig_cwd = -1;
398 }
399 }
400
401 ditem = mate_desktop_item_new_from_file (dfile, 0, NULL((void*)0));
402
403 mate_desktop_item_set_string (ditem, "Exec", terminal_exec);
404 if (gtk_get_current_event_time () > 0) {
405 mate_desktop_item_set_launch_time (ditem, gtk_get_current_event_time ());
406 }
407 mate_desktop_item_launch (ditem, NULL((void*)0), MATE_DESKTOP_ITEM_LAUNCH_USE_CURRENT_DIR, NULL((void*)0));
408 mate_desktop_item_unref (ditem);
409 g_free (dfile);
410
411 if (orig_cwd != -1) {
412 int ret;
413
414 ret = fchdir (orig_cwd);
415 if (ret == -1) {
416 g_message ("CajaOpenTerminal: Failed to change back Caja working directory to original location after changing it to \"%s\".",
417 working_directory);
418 }
419
420 do {
421 ret = close (orig_cwd);
422 } while (ret == -1 && errno(*__errno_location ()) == EINTR4);
423
424 if (ret == -1) {
425 g_message ("CajaOpenTerminal: Failed to close Caja working directory.");
426 }
427 }
428 } else {
429 g_spawn_async (working_directory,
430 argv,
431 NULL((void*)0),
432 G_SPAWN_SEARCH_PATH,
433 NULL((void*)0),
434 NULL((void*)0),
435 NULL((void*)0),
436 NULL((void*)0));
437 }
438
439 g_setenv ("DISPLAY", old_display_str, TRUE(!(0)));
440
441 g_strfreev (argv);
442 g_free (terminal_exec);
443 g_free (working_directory);
444}
445
446static CajaMenuItem *
447open_terminal_menu_item_new (CajaFileInfo *file_info,
448 TerminalFileInfo terminal_file_info,
449 GdkScreen *screen,
450 gboolean is_file_item)
451{
452 CajaMenuItem *ret;
453 const char *name;
454 const char *tooltip;
455
456 switch (terminal_file_info) {
457 case FILE_INFO_LOCAL:
458 case FILE_INFO_SFTP:
459 name = _("Open in _Terminal")((char *) g_dgettext ("caja-extensions", "Open in _Terminal")
)
;
460 if (is_file_item) {
461 tooltip = _("Open the currently selected folder in a terminal")((char *) g_dgettext ("caja-extensions", "Open the currently selected folder in a terminal"
))
;
462 } else {
463 tooltip = _("Open the currently open folder in a terminal")((char *) g_dgettext ("caja-extensions", "Open the currently open folder in a terminal"
))
;
464 }
465 break;
466
467 case FILE_INFO_DESKTOP:
468 if (desktop_opens_home_dir ()) {
469 name = _("Open _Terminal")((char *) g_dgettext ("caja-extensions", "Open _Terminal"));
470 tooltip = _("Open a terminal")((char *) g_dgettext ("caja-extensions", "Open a terminal"));
471 } else {
472 name = _("Open in _Terminal")((char *) g_dgettext ("caja-extensions", "Open in _Terminal")
)
;
473 tooltip = _("Open the currently open folder in a terminal")((char *) g_dgettext ("caja-extensions", "Open the currently open folder in a terminal"
))
;
474 }
475 break;
476
477 case FILE_INFO_OTHER:
478 default:
479 g_assert_not_reached ()do { g_assertion_message_expr ("Caja-Open-Terminal", "caja-open-terminal.c"
, 479, ((const char*) (__func__)), ((void*)0)); } while (0)
;
480 }
481
482 ret = caja_menu_item_new ("CajaOpenTerminal::open_terminal",
483 name, tooltip, "terminal");
484
485 g_object_set_data (G_OBJECT (ret)((((GObject*) (void *) ((ret))))),
486 "CajaOpenTerminal::screen",
487 screen);
488
489 g_object_set_data_full (G_OBJECT (ret)((((GObject*) (void *) ((ret))))), "file-info",
490 g_object_ref (file_info)((__typeof__ (file_info)) (g_object_ref) (file_info)),
491 (GDestroyNotify) g_object_unref);
492 g_signal_connect (ret, "activate",g_signal_connect_data ((ret), ("activate"), (((GCallback) (open_terminal_callback
))), (file_info), ((void*)0), (GConnectFlags) 0)
493 G_CALLBACK (open_terminal_callback),g_signal_connect_data ((ret), ("activate"), (((GCallback) (open_terminal_callback
))), (file_info), ((void*)0), (GConnectFlags) 0)
494 file_info)g_signal_connect_data ((ret), ("activate"), (((GCallback) (open_terminal_callback
))), (file_info), ((void*)0), (GConnectFlags) 0)
;
495
496 return ret;
497}
498
499static GList *
500caja_open_terminal_get_background_items (CajaMenuProvider *provider,
501 GtkWidget *window,
502 CajaFileInfo *file_info)
503{
504 CajaMenuItem *item;
505 TerminalFileInfo terminal_file_info;
506
507 terminal_file_info = get_terminal_file_info (file_info);
508 switch (terminal_file_info) {
509 case FILE_INFO_LOCAL:
510 case FILE_INFO_DESKTOP:
511 case FILE_INFO_SFTP:
512 item = open_terminal_menu_item_new (file_info, terminal_file_info, gtk_widget_get_screen (window), FALSE(0));
513 return g_list_append (NULL((void*)0), item);
514
515 case FILE_INFO_OTHER:
516 return NULL((void*)0);
517
518 default:
519 g_assert_not_reached ()do { g_assertion_message_expr ("Caja-Open-Terminal", "caja-open-terminal.c"
, 519, ((const char*) (__func__)), ((void*)0)); } while (0)
;
520 }
521}
522
523static GList *
524caja_open_terminal_get_file_items (CajaMenuProvider *provider,
525 GtkWidget *window,
526 GList *files)
527{
528 CajaMenuItem *item;
529 TerminalFileInfo terminal_file_info;
530
531 if (g_list_length (files) != 1 ||
532 (!caja_file_info_is_directory (files->data) &&
533 caja_file_info_get_file_type (files->data) != G_FILE_TYPE_SHORTCUT &&
534 caja_file_info_get_file_type (files->data) != G_FILE_TYPE_MOUNTABLE)) {
535 return NULL((void*)0);
536 }
537
538 terminal_file_info = get_terminal_file_info (files->data);
539 switch (terminal_file_info) {
540 case FILE_INFO_LOCAL:
541 case FILE_INFO_SFTP:
542 item = open_terminal_menu_item_new (files->data, terminal_file_info, gtk_widget_get_screen (window), TRUE(!(0)));
543 return g_list_append (NULL((void*)0), item);
544
545 case FILE_INFO_DESKTOP:
546 case FILE_INFO_OTHER:
547 return NULL((void*)0);
548
549 default:
550 g_assert_not_reached ()do { g_assertion_message_expr ("Caja-Open-Terminal", "caja-open-terminal.c"
, 550, ((const char*) (__func__)), ((void*)0)); } while (0)
;
551 }
552}
553
554static void
555caja_open_terminal_run_config (CajaConfigurable *provider)
556{
557 GtkWidget *extconf_dialog, *extconf_content, *extconf_desktophomedir, *extconf_inform1, *extconf_inform2, *extconf_exec;
558 gchar * terminal;
559
560 extconf_dialog = gtk_dialog_new ();
561 extconf_content = gtk_dialog_get_content_area (GTK_DIALOG (extconf_dialog)((((GtkDialog*) (void *) ((extconf_dialog))))));
562
563 extconf_desktophomedir = gtk_check_button_new_with_label (_("Open at Home if trying to open on desktop")((char *) g_dgettext ("caja-extensions", "Open at Home if trying to open on desktop"
))
);
564 extconf_exec = gtk_entry_new ();
565 extconf_inform1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
566 extconf_inform2 = gtk_label_new (_("Terminal application:")((char *) g_dgettext ("caja-extensions", "Terminal application:"
))
);
567
568 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (extconf_desktophomedir)((((GtkToggleButton*) (void *) ((extconf_desktophomedir))))), desktop_opens_home_dir ());
569
570 terminal = default_terminal_application();
571 gtk_entry_set_text (GTK_ENTRY (extconf_exec)((((GtkEntry*) (void *) ((extconf_exec))))), terminal);
572 g_free (terminal);
573
574 gtk_container_add (GTK_CONTAINER (extconf_inform1)((((GtkContainer*) (void *) ((extconf_inform1))))), extconf_inform2);
575 gtk_widget_show (extconf_inform2);
576 gtk_container_add (GTK_CONTAINER (extconf_inform1)((((GtkContainer*) (void *) ((extconf_inform1))))), extconf_exec);
577 gtk_widget_show (extconf_exec);
578 gtk_box_set_child_packing (GTK_BOX (extconf_inform1)((((GtkBox*) (void *) ((extconf_inform1))))), extconf_exec, FALSE(0), FALSE(0), 0, GTK_PACK_END);
579
580 gtk_container_add (GTK_CONTAINER (extconf_content)((((GtkContainer*) (void *) ((extconf_content))))), extconf_desktophomedir);
581 gtk_widget_show (extconf_desktophomedir);
582 gtk_container_add (GTK_CONTAINER (extconf_content)((((GtkContainer*) (void *) ((extconf_content))))), extconf_inform1);
583 gtk_widget_show (extconf_inform1);
584 gtk_container_add (GTK_CONTAINER (extconf_content)((((GtkContainer*) (void *) ((extconf_content))))), extconf_exec);
585 gtk_widget_show (extconf_exec);
586 gtk_dialog_add_buttons (GTK_DIALOG (extconf_dialog)((((GtkDialog*) (void *) ((extconf_dialog))))), _("Close")((char *) g_dgettext ("caja-extensions", "Close")), GTK_RESPONSE_OK, NULL((void*)0));
587
588 gtk_container_set_border_width (GTK_CONTAINER (extconf_inform1)((((GtkContainer*) (void *) ((extconf_inform1))))), 6);
589 gtk_container_set_border_width (GTK_CONTAINER (extconf_dialog)((((GtkContainer*) (void *) ((extconf_dialog))))), 6);
590 gtk_container_set_border_width (GTK_CONTAINER (extconf_content)((((GtkContainer*) (void *) ((extconf_content))))), 6);
591
592 gtk_window_set_title (GTK_WINDOW (extconf_dialog)((((GtkWindow*) (void *) ((extconf_dialog))))), _("open-terminal Configuration")((char *) g_dgettext ("caja-extensions", "open-terminal Configuration"
))
);
593 gtk_dialog_run (GTK_DIALOG (extconf_dialog)((((GtkDialog*) (void *) ((extconf_dialog))))));
594
595 set_default_terminal_application (gtk_entry_get_text (GTK_ENTRY (extconf_exec)((((GtkEntry*) (void *) ((extconf_exec)))))));
596 set_desktop_opens_home_dir (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (extconf_desktophomedir)((((GtkToggleButton*) (void *) ((extconf_desktophomedir)))))));
597
598 gtk_widget_destroy (GTK_WIDGET (extconf_dialog)((((GtkWidget*) (void *) ((extconf_dialog))))));
599}
600
601static void
602caja_open_terminal_menu_provider_iface_init (CajaMenuProviderIface *iface)
603{
604 iface->get_background_items = caja_open_terminal_get_background_items;
605 iface->get_file_items = caja_open_terminal_get_file_items;
606}
607
608static void
609caja_open_terminal_configurable_iface_init (CajaConfigurableIface *iface)
610{
611 iface->run_config = caja_open_terminal_run_config;
612}
613
614static void
615caja_open_terminal_instance_init (CajaOpenTerminal *cvs)
616{
617}
618
619static void
620caja_open_terminal_class_init (CajaOpenTerminalClass *class)
621{
622}
623
624GType
625caja_open_terminal_get_type (void)
626{
627 return terminal_type;
628}
629
630void
631caja_open_terminal_register_type (GTypeModule *module)
632{
633 static const GTypeInfo info = {
634 sizeof (CajaOpenTerminalClass),
635 (GBaseInitFunc) NULL((void*)0),
636 (GBaseFinalizeFunc) NULL((void*)0),
637 (GClassInitFunc) caja_open_terminal_class_init,
638 NULL((void*)0),
639 NULL((void*)0),
640 sizeof (CajaOpenTerminal),
641 0,
642 (GInstanceInitFunc) caja_open_terminal_instance_init,
643 NULL((void*)0)
644 };
645
646 static const GInterfaceInfo menu_provider_iface_info = {
647 (GInterfaceInitFunc) caja_open_terminal_menu_provider_iface_init,
648 NULL((void*)0),
649 NULL((void*)0)
650 };
651
652 static const GInterfaceInfo configurable_iface_info = {
653 (GInterfaceInitFunc) caja_open_terminal_configurable_iface_init,
654 NULL((void*)0),
655 NULL((void*)0)
656 };
657
658 terminal_type = g_type_module_register_type (module,
659 G_TYPE_OBJECT((GType) ((20) << (2))),
660 "CajaOpenTerminal",
661 &info, 0);
662
663 g_type_module_add_interface (module,
664 terminal_type,
665 CAJA_TYPE_MENU_PROVIDER(caja_menu_provider_get_type ()),
666 &menu_provider_iface_info);
667
668 g_type_module_add_interface (module,
669 terminal_type,
670 CAJA_TYPE_CONFIGURABLE(caja_configurable_get_type ()),
671 &configurable_iface_info);
672}
diff --git a/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-b7a538.html b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-b7a538.html new file mode 100644 index 0000000..bff0622 --- /dev/null +++ b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/report-b7a538.html @@ -0,0 +1,1034 @@ + + + +caja-xattr-tags-extension.c + + + + + + + + + + + + + + + + + + + + + + + + + + +

Bug Summary

+ + + + +
File:xattr-tags/caja-xattr-tags-extension.c
Warning:line 123, column 18
Out of bound memory access (access exceeds upper limit of memory block)
+ +

Annotated Source Code

+

Press '?' + to see keyboard shortcuts

+ + +
clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name caja-xattr-tags-extension.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -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 -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/xattr-tags -resource-dir /usr/bin/../lib/clang/17 -D HAVE_CONFIG_H -I . -I .. -D G_DISABLE_DEPRECATED -D GDK_PIXBUF_DISABLE_DEPRECATED -D MATELOCALEDIR="/usr/local/share/locale" -I .. -I .. -I /usr/include/caja -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/cairo -I /usr/include/dbus-1.0 -I /usr/lib64/dbus-1.0/include -I /usr/include/atk-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -I /usr/include/at-spi2-atk/2.0 -I /usr/include/cloudproviders -I /usr/include/at-spi-2.0 -I /usr/include/blkid -I /usr/include/gio-unix-2.0 -I /usr/include/libmount -I /usr/include/pixman-1 -I /usr/include/libxml2 -I /usr/include/fribidi -I /usr/include/sysprof-6 -I /usr/include/libpng16 -D PIC -internal-isystem /usr/bin/../lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -fdebug-compilation-dir=/rootdir/xattr-tags -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-checker security.insecureAPI.strcpy -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-03-190745-6463-1 -x c caja-xattr-tags-extension.c +
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1/*
2 * Caja xattr tags extension
3 *
4 * Copyright (C) 2016 Felipe Barriga Richards
5 * Copyright (C) 2016-2021 MATE developers.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 * Authors: Felipe Barriga Richards <spam@felipebarriga.cl>
22 */
23
24#ifdef HAVE_CONFIG_H1
25#include <config.h>
26#endif
27
28#include <glib/gi18n-lib.h>
29
30#include <string.h>
31#include <gio/gio.h>
32
33#include <libcaja-extension/caja-file-info.h>
34#include <libcaja-extension/caja-info-provider.h>
35#include <libcaja-extension/caja-column-provider.h>
36
37#include "caja-xattr-tags-extension.h"
38
39#define XATTR_TAGS_NAME"Xattr::Tags" "Xattr::Tags"
40#define XATTR_TAGS_ATTRIBUTE"xattr_tags" "xattr_tags"
41
42#define G_FILE_ATTRIBUTE_XATTR_XDG_TAGS"xattr::xdg.tags" "xattr::xdg.tags"
43
44static GObjectClass *parent_class;
45
46typedef struct {
47 gboolean cancelled;
48 CajaInfoProvider *provider;
49 CajaFileInfo *file;
50 GClosure *update_complete;
51} CajaXattrTagsHandle;
52
53/* List of protocols that don't support xattr retriving,
54 * so we can skip it safetely
55 */
56static gchar *protocols_blacklist[] = {
57 "mtp://",
58 "gphoto2://",
59
60 NULL((void*)0)
61};
62
63/* Stolen code: why they didn't expose it!?
64 * file: glocalfileinfo.c
65 * function: hex_unescape_string
66 * GIO - GLib Input, Output and Streaming Library
67 */
68static char *
69hex_unescape_string (const char *str,
70 int *out_len,
71 gboolean *free_return)
72{
73 int i;
74 char *unescaped_str, *p;
75 unsigned char c;
76 int len;
77
78 len = strlen (str);
79
80 if (strchr (str, '\\') == NULL((void*)0))
81 {
82 if (out_len)
83 *out_len = len;
84 *free_return = FALSE(0);
85 return (char *)str;
86 }
87
88 unescaped_str = g_malloc (len + 1);
89
90 p = unescaped_str;
91 for (i = 0; i < len; i++)
92 {
93 if (str[i] == '\\' &&
94 str[i+1] == 'x' &&
95 len - i >= 4)
96 {
97 c =
98 (g_ascii_xdigit_value (str[i+2]) << 4) |
99 g_ascii_xdigit_value (str[i+3]);
100 *p++ = c;
101 i += 3;
102 }
103 else
104 *p++ = str[i];
105 }
106 *p++ = 0;
107
108 if (out_len)
109 *out_len = p - unescaped_str;
110 *free_return = TRUE(!(0));
111 return unescaped_str;
112}
113/* End of stolen code */
114
115static gchar *caja_xattr_tags_get_xdg_tags(CajaFileInfo *file)
116{
117 gchar *tags = NULL((void*)0), *uri;
118 GFile *location;
119 GFileInfo *info;
120 int i;
121
122 uri = caja_file_info_get_activation_uri (file);
123 for (i = 0 ; protocols_blacklist[i] ; i++) {
2
Loop condition is true. Entering loop body
6
Loop condition is true. Entering loop body
10
Loop condition is true. Entering loop body
14
Out of bound memory access (access exceeds upper limit of memory block)
124 int l = strlen(protocols_blacklist[i]);
125
126 if (strlen(uri) < l)
3
Assuming the condition is true
4
Taking true branch
7
Assuming the condition is true
8
Taking true branch
11
Assuming the condition is true
12
Taking true branch
127 continue;
5
Execution continues on line 123
9
Execution continues on line 123
13
Execution continues on line 123
128 if (strncasecmp(uri, protocols_blacklist[i], l))
129 continue;
130
131 g_free (uri);
132 return NULL((void*)0);
133 }
134
135 location = g_file_new_for_uri (uri);
136 info = g_file_query_info (location,
137 G_FILE_ATTRIBUTE_XATTR_XDG_TAGS"xattr::xdg.tags",
138 0,
139 NULL((void*)0),
140 NULL((void*)0));
141
142 if (info) {
143 if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_XATTR_XDG_TAGS"xattr::xdg.tags")) {
144 const gchar *escaped_tags =
145 g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_XATTR_XDG_TAGS"xattr::xdg.tags");
146
147 gboolean new_created = FALSE(0);
148 gchar *un_escaped_tags = hex_unescape_string (escaped_tags, NULL((void*)0), &new_created);
149 if (new_created) {
150 tags = un_escaped_tags;
151 } else {
152 /* the string didn't contain any escaped character */
153 tags = g_strdup(escaped_tags)g_strdup_inline (escaped_tags);
154 }
155 }
156 g_object_unref (info);
157 }
158 g_object_unref (location);
159 g_free (uri);
160
161 return tags;
162}
163
164static CajaOperationResult
165caja_xattr_tags_update_file_info(CajaInfoProvider *provider,
166 CajaFileInfo *file,
167 GClosure *update_complete,
168 CajaOperationHandle **handle)
169{
170 gchar *value = caja_xattr_tags_get_xdg_tags(file);
1
Calling 'caja_xattr_tags_get_xdg_tags'
171 if (value != NULL((void*)0)) {
172 caja_file_info_add_string_attribute(file, XATTR_TAGS_ATTRIBUTE"xattr_tags", value);
173 g_free(value);
174 } else {
175 caja_file_info_add_string_attribute(file, XATTR_TAGS_ATTRIBUTE"xattr_tags", "");
176 }
177 return CAJA_OPERATION_COMPLETE;
178}
179
180static void
181caja_xattr_tags_cancel_update(CajaInfoProvider *provider,
182 CajaOperationHandle *handle)
183{
184 CajaXattrTagsHandle *xattr_handle;
185
186 xattr_handle = (CajaXattrTagsHandle*)handle;
187 xattr_handle->cancelled = TRUE(!(0));
188}
189
190static void
191caja_xattr_tags_info_provider_iface_init(CajaInfoProviderIface *iface)
192{
193 iface->update_file_info = caja_xattr_tags_update_file_info;
194 iface->cancel_update = caja_xattr_tags_cancel_update;
195}
196
197static GList *
198caja_xattr_tags_get_columns(CajaColumnProvider *provider)
199{
200 GList *ret = NULL((void*)0);
201 CajaColumn *column = NULL((void*)0);
202
203 column = caja_column_new(XATTR_TAGS_NAME"Xattr::Tags",
204 XATTR_TAGS_ATTRIBUTE"xattr_tags",
205 _("Tags")((char *) g_dgettext ("caja-extensions", "Tags")),
206 _("Tags stored in extended attributes")((char *) g_dgettext ("caja-extensions", "Tags stored in extended attributes"
))
);
207 ret = g_list_append(NULL((void*)0), column);
208
209 return ret;
210}
211
212static void
213caja_xattr_tags_column_provider_iface_init(CajaColumnProviderIface *iface)
214{
215 iface->get_columns = caja_xattr_tags_get_columns;
216}
217
218static void
219caja_xattr_tags_instance_init(CajaXattrTags *cajaXattrTags)
220{
221}
222
223static void
224caja_xattr_tags_class_init(CajaXattrTagsClass *class)
225{
226 parent_class = g_type_class_peek_parent (class);
227}
228
229static GType caja_xattr_tags_type = 0;
230
231GType
232caja_xattr_tags_get_type(void)
233{
234 return caja_xattr_tags_type;
235}
236
237void
238caja_xattr_tags_register_type(GTypeModule *module)
239{
240 static const GTypeInfo info = {
241 sizeof (CajaXattrTagsClass),
242 (GBaseInitFunc) NULL((void*)0),
243 (GBaseFinalizeFunc) NULL((void*)0),
244 (GClassInitFunc) caja_xattr_tags_class_init,
245 NULL((void*)0),
246 NULL((void*)0),
247 sizeof (CajaXattrTags),
248 0,
249 (GInstanceInitFunc) caja_xattr_tags_instance_init,
250 NULL((void*)0)
251 };
252
253 caja_xattr_tags_type = g_type_module_register_type (module,
254 G_TYPE_OBJECT((GType) ((20) << (2))),
255 "CajaXattrTags",
256 &info, 0);
257
258 static const GInterfaceInfo info_provider_iface_info = {
259 (GInterfaceInitFunc) caja_xattr_tags_info_provider_iface_init,
260 NULL((void*)0),
261 NULL((void*)0)
262 };
263
264 g_type_module_add_interface (module,
265 CAJA_TYPE_XATTR_TAGS(caja_xattr_tags_get_type ()),
266 CAJA_TYPE_INFO_PROVIDER(caja_info_provider_get_type ()),
267 &info_provider_iface_info);
268
269 static const GInterfaceInfo column_provider_iface_info = {
270 (GInterfaceInitFunc) caja_xattr_tags_column_provider_iface_init,
271 NULL((void*)0),
272 NULL((void*)0)
273 };
274
275 g_type_module_add_interface (module,
276 CAJA_TYPE_XATTR_TAGS(caja_xattr_tags_get_type ()),
277 CAJA_TYPE_COLUMN_PROVIDER(caja_column_provider_get_type ()),
278 &column_provider_iface_info);
279
280}
281
282void
283caja_module_initialize (GTypeModule *module)
284{
285 g_print ("Initializing caja-xattr-tags extension\n");
286 caja_xattr_tags_register_type (module);
287#ifdef ENABLE_NLS1
288 bindtextdomain (GETTEXT_PACKAGE"caja-extensions", MATELOCALEDIR"/usr/local/share/locale");
289 bind_textdomain_codeset (GETTEXT_PACKAGE"caja-extensions", "UTF-8");
290#endif /* ENABLE_NLS */
291}
292
293void
294caja_module_shutdown (void)
295{
296 g_print ("Shutting down caja-xattr-tags extension\n");
297}
298
299/* List all the extension types. */
300void
301caja_module_list_types (const GType **types,
302 int *num_types)
303{
304 static GType type_list[1];
305
306 type_list[0] = CAJA_TYPE_XATTR_TAGS(caja_xattr_tags_get_type ());
307
308 *types = type_list;
309 *num_types = 1;
310}
diff --git a/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/scanview.css b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/scanview.css new file mode 100644 index 0000000..cf8a5a6 --- /dev/null +++ b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/scanview.css @@ -0,0 +1,62 @@ +body { color:#000000; background-color:#ffffff } +body { font-family: Helvetica, sans-serif; font-size:9pt } +h1 { font-size: 14pt; } +h2 { font-size: 12pt; } +table { font-size:9pt } +table { border-spacing: 0px; border: 1px solid black } +th, table thead { + background-color:#eee; color:#666666; + font-weight: bold; cursor: default; + text-align:center; + font-weight: bold; font-family: Verdana; + white-space:nowrap; +} +.W { font-size:0px } +th, td { padding:5px; padding-left:8px; text-align:left } +td.SUMM_DESC { padding-left:12px } +td.DESC { white-space:pre } +td.Q { text-align:right } +td { text-align:left } +tbody.scrollContent { overflow:auto } + +table.form_group { + background-color: #ccc; + border: 1px solid #333; + padding: 2px; +} + +table.form_inner_group { + background-color: #ccc; + border: 1px solid #333; + padding: 0px; +} + +table.form { + background-color: #999; + border: 1px solid #333; + padding: 2px; +} + +td.form_label { + text-align: right; + vertical-align: top; +} +/* For one line entires */ +td.form_clabel { + text-align: right; + vertical-align: center; +} +td.form_value { + text-align: left; + vertical-align: top; +} +td.form_submit { + text-align: right; + vertical-align: top; +} + +h1.SubmitFail { + color: #f00; +} +h1.SubmitOk { +} diff --git a/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/sorttable.js b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/sorttable.js new file mode 100644 index 0000000..32faa07 --- /dev/null +++ b/2024-02-03-190745-6463-1@b9ac84d9f4fd_v1.27.1/sorttable.js @@ -0,0 +1,492 @@ +/* + SortTable + version 2 + 7th April 2007 + Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ + + Instructions: + Download this file + Add to your HTML + Add class="sortable" to any table you'd like to make sortable + Click on the headers to sort + + Thanks to many, many people for contributions and suggestions. + Licenced as X11: http://www.kryogenix.org/code/browser/licence.html + This basically means: do what you want with it. +*/ + + +var stIsIE = /*@cc_on!@*/false; + +sorttable = { + init: function() { + // quit if this function has already been called + if (arguments.callee.done) return; + // flag this function so we don't do the same thing twice + arguments.callee.done = true; + // kill the timer + if (_timer) clearInterval(_timer); + + if (!document.createElement || !document.getElementsByTagName) return; + + sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; + + forEach(document.getElementsByTagName('table'), function(table) { + if (table.className.search(/\bsortable\b/) != -1) { + sorttable.makeSortable(table); + } + }); + + }, + + makeSortable: function(table) { + if (table.getElementsByTagName('thead').length == 0) { + // table doesn't have a tHead. Since it should have, create one and + // put the first table row in it. + the = document.createElement('thead'); + the.appendChild(table.rows[0]); + table.insertBefore(the,table.firstChild); + } + // Safari doesn't support table.tHead, sigh + if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0]; + + if (table.tHead.rows.length != 1) return; // can't cope with two header rows + + // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as + // "total" rows, for example). This is B&R, since what you're supposed + // to do is put them in a tfoot. So, if there are sortbottom rows, + // for backward compatibility, move them to tfoot (creating it if needed). + sortbottomrows = []; + for (var i=0; i5' : ' ▴'; + this.appendChild(sortrevind); + return; + } + if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) { + // if we're already sorted by this column in reverse, just + // re-reverse the table, which is quicker + sorttable.reverse(this.sorttable_tbody); + this.className = this.className.replace('sorttable_sorted_reverse', + 'sorttable_sorted'); + this.removeChild(document.getElementById('sorttable_sortrevind')); + sortfwdind = document.createElement('span'); + sortfwdind.id = "sorttable_sortfwdind"; + sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; + this.appendChild(sortfwdind); + return; + } + + // remove sorttable_sorted classes + theadrow = this.parentNode; + forEach(theadrow.childNodes, function(cell) { + if (cell.nodeType == 1) { // an element + cell.className = cell.className.replace('sorttable_sorted_reverse',''); + cell.className = cell.className.replace('sorttable_sorted',''); + } + }); + sortfwdind = document.getElementById('sorttable_sortfwdind'); + if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); } + sortrevind = document.getElementById('sorttable_sortrevind'); + if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); } + + this.className += ' sorttable_sorted'; + sortfwdind = document.createElement('span'); + sortfwdind.id = "sorttable_sortfwdind"; + sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; + this.appendChild(sortfwdind); + + // build an array to sort. This is a Schwartzian transform thing, + // i.e., we "decorate" each row with the actual sort key, + // sort based on the sort keys, and then put the rows back in order + // which is a lot faster because you only do getInnerText once per row + row_array = []; + col = this.sorttable_columnindex; + rows = this.sorttable_tbody.rows; + for (var j=0; j 12) { + // definitely dd/mm + return sorttable.sort_ddmm; + } else if (second > 12) { + return sorttable.sort_mmdd; + } else { + // looks like a date, but we can't tell which, so assume + // that it's dd/mm (English imperialism!) and keep looking + sortfn = sorttable.sort_ddmm; + } + } + } + } + return sortfn; + }, + + getInnerText: function(node) { + // gets the text we want to use for sorting for a cell. + // strips leading and trailing whitespace. + // this is *not* a generic getInnerText function; it's special to sorttable. + // for example, you can override the cell text with a customkey attribute. + // it also gets .value for fields. + + hasInputs = (typeof node.getElementsByTagName == 'function') && + node.getElementsByTagName('input').length; + + if (node.getAttribute("sorttable_customkey") != null) { + return node.getAttribute("sorttable_customkey"); + } + else if (typeof node.textContent != 'undefined' && !hasInputs) { + return node.textContent.replace(/^\s+|\s+$/g, ''); + } + else if (typeof node.innerText != 'undefined' && !hasInputs) { + return node.innerText.replace(/^\s+|\s+$/g, ''); + } + else if (typeof node.text != 'undefined' && !hasInputs) { + return node.text.replace(/^\s+|\s+$/g, ''); + } + else { + switch (node.nodeType) { + case 3: + if (node.nodeName.toLowerCase() == 'input') { + return node.value.replace(/^\s+|\s+$/g, ''); + } + case 4: + return node.nodeValue.replace(/^\s+|\s+$/g, ''); + break; + case 1: + case 11: + var innerText = ''; + for (var i = 0; i < node.childNodes.length; i++) { + innerText += sorttable.getInnerText(node.childNodes[i]); + } + return innerText.replace(/^\s+|\s+$/g, ''); + break; + default: + return ''; + } + } + }, + + reverse: function(tbody) { + // reverse the rows in a tbody + newrows = []; + for (var i=0; i=0; i--) { + tbody.appendChild(newrows[i]); + } + delete newrows; + }, + + /* sort functions + each sort function takes two parameters, a and b + you are comparing a[0] and b[0] */ + sort_numeric: function(a,b) { + aa = parseFloat(a[0].replace(/[^0-9.-]/g,'')); + if (isNaN(aa)) aa = 0; + bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); + if (isNaN(bb)) bb = 0; + return aa-bb; + }, + sort_alpha: function(a,b) { + if (a[0]==b[0]) return 0; + if (a[0] 0 ) { + var q = list[i]; list[i] = list[i+1]; list[i+1] = q; + swap = true; + } + } // for + t--; + + if (!swap) break; + + for(var i = t; i > b; --i) { + if ( comp_func(list[i], list[i-1]) < 0 ) { + var q = list[i]; list[i] = list[i-1]; list[i-1] = q; + swap = true; + } + } // for + b++; + + } // while(swap) + } +} + +/* ****************************************************************** + Supporting functions: bundled here to avoid depending on a library + ****************************************************************** */ + +// Dean Edwards/Matthias Miller/John Resig + +/* for Mozilla/Opera9 */ +if (document.addEventListener) { + document.addEventListener("DOMContentLoaded", sorttable.init, false); +} + +/* for Internet Explorer */ +/*@cc_on @*/ +/*@if (@_win32) + document.write("