Bug Summary

File:eel/eel-vfs-extensions.c
Warning:line 136, column 14
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-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name eel-vfs-extensions.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=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/eel -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I .. -D G_LOG_DOMAIN="Eel" -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/webp -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 SOURCE_DATADIR="../data" -D CAFELOCALEDIR="/usr/local//locale" -D PIC -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../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/eel -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/2024-01-10-165140-28395-1 -x c eel-vfs-extensions.c
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3/* eel-vfs-extensions.c - cafe-vfs extensions. Its likely some of these will
4 be part of cafe-vfs in the future.
5
6 Copyright (C) 1999, 2000 Eazel, Inc.
7
8 The Cafe Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
12
13 The Cafe Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public
19 License along with the Cafe Library; see the file COPYING.LIB. If not,
20 write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22
23 Authors: Darin Adler <darin@eazel.com>
24 Pavel Cisler <pavel@eazel.com>
25 Mike Fleming <mfleming@eazel.com>
26 John Sullivan <sullivan@eazel.com>
27*/
28
29#include <config.h>
30#include "eel-vfs-extensions.h"
31#include "eel-glib-extensions.h"
32#include "eel-lib-self-check-functions.h"
33#include <glib.h>
34#include <glib/gi18n-lib.h>
35#include <gio/gio.h>
36
37#include "eel-string.h"
38
39#include <string.h>
40#include <stdlib.h>
41
42gboolean
43eel_uri_is_trash (const char *uri)
44{
45 return eel_istr_has_prefix (uri, "trash:");
46}
47
48gboolean
49eel_uri_is_search (const char *uri)
50{
51 return eel_istr_has_prefix (uri, EEL_SEARCH_URI"x-baul-search:");
52}
53
54gboolean
55eel_uri_is_desktop (const char *uri)
56{
57 return eel_istr_has_prefix (uri, EEL_DESKTOP_URI"x-baul-desktop:");
58}
59
60char *
61eel_make_valid_utf8 (const char *name)
62{
63 GString *string;
64 const char *remainder, *invalid;
65 int remaining_bytes;
66
67 string = NULL((void*)0);
68 remainder = name;
69 remaining_bytes = strlen (name);
70
71 while (remaining_bytes != 0)
72 {
73 int valid_bytes;
74
75 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
76 {
77 break;
78 }
79 valid_bytes = invalid - remainder;
80
81 if (string == NULL((void*)0))
82 {
83 string = g_string_sized_new (remaining_bytes);
84 }
85 g_string_append_len (string, remainder, valid_bytes)g_string_append_len_inline (string, remainder, valid_bytes);
86 g_string_append_c (string, '?')g_string_append_c_inline (string, '?');
87
88 remaining_bytes -= valid_bytes + 1;
89 remainder = invalid + 1;
90 }
91
92 if (string == NULL((void*)0))
93 {
94 return g_strdup (name)g_strdup_inline (name);
95 }
96
97 g_string_append (string, remainder)(__builtin_constant_p (remainder) ? __extension__ ({ const char
* const __val = (remainder); g_string_append_len_inline (string
, __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + !
(__val))) : (gssize) -1); }) : g_string_append_len_inline (string
, remainder, (gssize) -1))
;
98 g_string_append (string, _(" (invalid Unicode)"))(__builtin_constant_p (((char *) g_dgettext ("baul", " (invalid Unicode)"
))) ? __extension__ ({ const char * const __val = (((char *) g_dgettext
("baul", " (invalid Unicode)"))); g_string_append_len_inline
(string, __val, (__val != ((void*)0)) ? (gssize) strlen (((__val
) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline
(string, ((char *) g_dgettext ("baul", " (invalid Unicode)")
), (gssize) -1))
;
99 g_assert (g_utf8_validate (string->str, -1, NULL))do { if (g_utf8_validate (string->str, -1, ((void*)0))) ; else
g_assertion_message_expr ("Eel", "eel-vfs-extensions.c", 99,
((const char*) (__func__)), "g_utf8_validate (string->str, -1, NULL)"
); } while (0)
;
100
101 return g_string_free (string, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((string
), ((0))) : g_string_free_and_steal (string)) : (g_string_free
) ((string), ((0))))
;
102}
103
104char *
105eel_filename_strip_extension (const char * filename_with_extension)
106{
107 char *filename, *end, *end2;
108
109 if (filename_with_extension
10.1
'filename_with_extension' is not equal to NULL
== NULL((void*)0))
11
Taking false branch
110 {
111 return NULL((void*)0);
112 }
113
114 filename = g_strdup (filename_with_extension)g_strdup_inline (filename_with_extension);
115
116 end = strrchr (filename, '.');
117
118 if (end && end != filename)
12
Assuming 'end' is non-null
13
Assuming 'end' is not equal to 'filename'
119 {
120 if (strcmp (end, ".gz") == 0 ||
121 strcmp (end, ".bz2") == 0 ||
122 strcmp (end, ".sit") == 0 ||
123 strcmp (end, ".Z") == 0)
124 {
125 end2 = end - 1;
126 while (end2 > filename &&
14
Assuming 'end2' is <= 'filename'
127 *end2 != '.')
128 {
129 end2--;
130 }
131 if (end2 != filename)
15
Assuming 'end2' is not equal to 'filename'
16
Taking true branch
132 {
133 end = end2;
134 }
135 }
136 *end = '\0';
17
Out of bound memory access (access exceeds upper limit of memory block)
137 }
138
139 return filename;
140}
141
142void
143eel_filename_get_rename_region (const char *filename,
144 int *start_offset,
145 int *end_offset)
146{
147 char *filename_without_extension;
148
149 g_return_if_fail (start_offset != NULL)do { if ((start_offset != ((void*)0))) { } else { g_return_if_fail_warning
("Eel", ((const char*) (__func__)), "start_offset != NULL");
return; } } while (0)
;
1
Assuming 'start_offset' is not equal to null
2
Taking true branch
3
Loop condition is false. Exiting loop
150 g_return_if_fail (end_offset != NULL)do { if ((end_offset != ((void*)0))) { } else { g_return_if_fail_warning
("Eel", ((const char*) (__func__)), "end_offset != NULL"); return
; } } while (0)
;
4
Assuming 'end_offset' is not equal to null
5
Taking true branch
6
Loop condition is false. Exiting loop
151
152 *start_offset = 0;
153 *end_offset = 0;
154
155 g_return_if_fail (filename != NULL)do { if ((filename != ((void*)0))) { } else { g_return_if_fail_warning
("Eel", ((const char*) (__func__)), "filename != NULL"); return
; } } while (0)
;
7
Assuming 'filename' is not equal to null
8
Taking true branch
9
Loop condition is false. Exiting loop
156
157 filename_without_extension = eel_filename_strip_extension (filename);
10
Calling 'eel_filename_strip_extension'
158 *end_offset = g_utf8_strlen (filename_without_extension, -1);
159
160 g_free (filename_without_extension);
161}