Bug Summary

File:libbaul-private/baul-extensions.c
Warning:line 234, column 46
Access to field 'filename' results in a dereference of a null pointer (loaded from variable 'ext')

Annotated Source Code

Press '?' to see keyboard shortcuts

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 baul-extensions.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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=all -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/libbaul-private -resource-dir /usr/lib/llvm-14/lib/clang/14.0.6 -D HAVE_CONFIG_H -I . -I .. -I .. -I .. -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/cafe-desktop-2.0 -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -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/gio-unix-2.0 -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/startup-notification-1.0 -I /usr/include/dconf -I /usr/include/cail-3.0 -I /usr/include/libxml2 -D G_DISABLE_DEPRECATED -D GDK_PIXBUF_DISABLE_DEPRECATED -D DATADIR="/usr/local/share" -D SYSCONFDIR="/usr/local/etc" -D BAUL_DATADIR="/usr/local/share/baul" -D BAUL_EXTENSIONDIR="/usr/local/lib/baul/extensions-2.0" -D PIC -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/libbaul-private -ferror-limit 19 -fgnuc-version=4.2.1 -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-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2023-07-15-190635-27806-1 -x c baul-extensions.c
1/*
2 * baul-extension.c - extension management functions
3 *
4 * Copyright (C) 2014 CAFE Desktop.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library 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 Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 * Author: Alexander van der Meij <alexandervdm@gliese.me>
22 */
23
24#include "baul-extensions.h"
25
26#include "baul-global-preferences.h"
27#include "baul-module.h"
28#include "baul-debug-log.h"
29
30#include <string.h>
31
32#define BAUL_EXTENSION_GROUP"Baul Extension" "Baul Extension"
33
34static GList *baul_extensions = NULL((void*)0);
35
36
37static Extension *
38extension_new (gchar *filename, gboolean state, gboolean python, GObject *module)
39{
40 GError *error = NULL((void*)0);
41 Extension *ext;
42 GKeyFile *extension_file;
43 gchar *extension_filename;
44
45 ext = g_new0 (Extension, 1)((Extension *) g_malloc0_n ((1), sizeof (Extension)));
46 ext->filename = filename;
47 ext->name = NULL((void*)0);
48 ext->description = NULL((void*)0);
49 ext->author = NULL((void*)0);
50 ext->copyright = NULL((void*)0);
51 ext->version = NULL((void*)0);
52 ext->website = NULL((void*)0);
53 ext->state = state;
54 ext->module = module;
55
56 extension_file = g_key_file_new ();
57 extension_filename = g_strdup_printf(BAUL_DATADIR"/usr/local/share/baul" "/extensions/%s.baul-extension", filename);
58 if (g_key_file_load_from_file (extension_file, extension_filename, G_KEY_FILE_NONE, &error))
59 {
60 ext->name = g_key_file_get_locale_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Name", NULL((void*)0), NULL((void*)0));
61 ext->description = g_key_file_get_locale_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Description", NULL((void*)0), NULL((void*)0));
62 ext->icon = g_key_file_get_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Icon", NULL((void*)0));
63 ext->author = g_key_file_get_string_list (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Author", NULL((void*)0), NULL((void*)0));
64 ext->copyright = g_key_file_get_locale_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Copyright", NULL((void*)0), NULL((void*)0));
65 ext->version = g_key_file_get_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Version", NULL((void*)0));
66 ext->website = g_key_file_get_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Website", NULL((void*)0));
67 g_key_file_free (extension_file);
68 }
69 else
70 {
71 baul_debug_log (FALSE(0), BAUL_DEBUG_LOG_DOMAIN_USER"USER", "Error loading keys from file: %s\n", error->message);
72 g_error_free (error);
73 }
74 g_free (extension_filename);
75
76 if (python)
77 {
78 ext->name = g_strconcat("Python: ", filename, NULL((void*)0));
79 ext->description = "Python-baul extension";
80 }
81
82 return ext;
83}
84
85/* functions related to persistent configuration through gsettings: */
86
87static gboolean
88gsettings_key_has_value (const gchar *value)
89{
90 gchar **list;
91 gint i;
92
93 list = g_settings_get_strv (baul_extension_preferences,
94 BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions");
95
96 if (list != NULL((void*)0))
97 {
98 for (i = 0; list[i]; i++)
99 {
100 if (g_ascii_strcasecmp (value, list[i]) == 0)
101 {
102 g_strfreev (list);
103 return TRUE(!(0));
104 }
105 }
106 }
107 g_strfreev (list);
108 return FALSE(0);
109}
110
111static gboolean
112gsettings_append_to_list (const char *value)
113{
114 gchar **current;
115 gchar **new;
116 gint size;
117 gboolean retval;
118
119 current = g_settings_get_strv (baul_extension_preferences,
120 BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions");
121
122 for (size = 0; current[size] != NULL((void*)0); size++);
123
124 size += 1;
125 size += 1;
126
127 new = g_realloc_n (current, size, sizeof (gchar *));
128
129 new[size - 2] = g_strdup (value);
130 new[size - 1] = NULL((void*)0);
131
132 retval = g_settings_set_strv (baul_extension_preferences,
133 BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions",
134 (const gchar **) new);
135
136 g_strfreev (new);
137 return retval;
138}
139
140static gboolean
141gsettings_remove_from_list (const char *value)
142{
143 gchar **current;
144 GArray *array;
145 gint i;
146 gboolean retval;
147
148 current = g_settings_get_strv (baul_extension_preferences,
149 BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions");
150
151 array = g_array_new (TRUE(!(0)), TRUE(!(0)), sizeof (gchar *));
152
153 for (i = 0; current[i] != NULL((void*)0); i++)
154 {
155 if (g_strcmp0 (current[i], value) != 0)
156 array = g_array_append_val (array, current[i])g_array_append_vals (array, &(current[i]), 1);
157 }
158
159 retval = g_settings_set_strv (baul_extension_preferences,
160 BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions",
161 (const gchar **) array->data);
162
163 g_strfreev (current);
164 g_array_free (array, TRUE(!(0)));
165 return retval;
166}
167
168/* functions related to the extension management */
169
170static gboolean
171baul_extension_get_state (const gchar *extname)
172{
173 return !gsettings_key_has_value (extname);
174}
175
176GList *
177baul_extensions_get_for_type (GType type)
178{
179 GList *l;
180 GList *ret = NULL((void*)0);
181
182 for (l = baul_extensions; l != NULL((void*)0); l = l->next)
183 {
184 Extension *ext = l->data;
185 ext->state = baul_extension_get_state (ext->filename);
186 if (ext->state) // only load enabled extensions
187 {
188 if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (ext->module), type)((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((ext->module)), (((GType) ((20) << (2))))))))); GType
__t = (type); gboolean __r; if (!__inst) __r = (0); else if (
__inst->g_class && __inst->g_class->g_type ==
__t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst
, __t); __r; })))
)
189 {
190 g_object_ref (ext->module)((__typeof__ (ext->module)) (g_object_ref) (ext->module
))
;
191 ret = g_list_prepend (ret, ext->module);
192 }
193 }
194 }
195
196 return ret;
197}
198
199GList *
200baul_extensions_get_list (void)
201{
202 return baul_extensions;
203}
204
205void
206baul_extension_register (gchar *filename, GObject *module)
207{
208 gboolean ext_state = TRUE(!(0)); // new extensions are enabled by default.
209 gboolean ext_python = FALSE(0);
210 gchar *ext_filename;
211
212 ext_filename = g_strndup (filename, strlen(filename) - 3);
213 ext_state = baul_extension_get_state (ext_filename);
214
215 if (g_str_has_suffix (filename, ".py")) {
216 ext_python = TRUE(!(0));
217 }
218
219 Extension *ext = extension_new (ext_filename, ext_state, ext_python, module);
220 baul_extensions = g_list_append (baul_extensions, ext);
221}
222
223gboolean
224baul_extension_set_state (Extension *ext, gboolean new_state)
225{
226 if (ext)
1
Assuming 'ext' is null
2
Taking false branch
227 {
228 g_return_val_if_fail (ext->state != new_state, FALSE)do { if ((ext->state != new_state)) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "ext->state != new_state"
); return ((0)); } } while (0)
;
229 ext->state = new_state;
230 }
231
232 gboolean retval;
233 if (new_state) {
3
Assuming 'new_state' is not equal to 0
4
Taking true branch
234 retval = gsettings_remove_from_list (ext->filename);
5
Access to field 'filename' results in a dereference of a null pointer (loaded from variable 'ext')
235 }
236 else {
237 retval = gsettings_append_to_list (ext->filename);
238 }
239
240 g_return_val_if_fail (retval == TRUE, FALSE)do { if ((retval == (!(0)))) { } else { g_return_if_fail_warning
(((gchar*) 0), ((const char*) (__func__)), "retval == TRUE")
; return ((0)); } } while (0)
;
241 return TRUE(!(0));
242}
243