Bug Summary

File:rootdir/src/utils/cas/html.c
Warning:line 90, column 14
Null pointer passed to 1st parameter expecting 'nonnull'

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 html.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 -pic-is-pie -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 -fdebug-compilation-dir=/rootdir/src/utils/cas -fcoverage-compilation-dir=/rootdir/src/utils/cas -resource-dir /usr/lib/llvm-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I ../../.. -D USE_WX_EXTENSIONS -D __GD__ -I /usr/include/libpng16 -I /usr/include/freetype2 -I /usr/include/harfbuzz -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/fribidi -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -D AVIF_DLL -I /usr/include/rav1e -I /usr/include/svt-av1 -D EB_DLL -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-register -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -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.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-12-16-222823-17165-1 -x c html.c
1/*
2 * Name: HTML creation functions
3 *
4 * Purpose: Create a nice HTML page with all the statistics
5 *
6 * Author: Pedro de Oliveira <falso@rdk.homeip.net>
7 *
8 * Copyright (c) 2004-2011 Pedro de Oliveira ( falso@rdk.homeip-net )
9 *
10 * This file is part of aMule.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the
24 * Free Software Foundation, Inc.,
25 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <unistd.h>
32#include <sys/stat.h>
33#include <sys/types.h>
34#include <fcntl.h>
35#include <string.h>
36
37#include "html.h"
38#include "functions.h"
39#include "version.h"
40
41int create_html(char *stats[20], char *lines[6], char template[120], char *path_for_html)
42{
43 /* Strings */
44 char *path = NULL((void*)0);
45 char version[25], upload[25], download[25];
46 char *search[] = {"#VERSION#", "#CLIENT#", "#NICK#", "#UPLOADRATE#" ,
47 "#DOWNLOADRATE#" , "#QUEUE#" , "#NUMSHARE#" , "#SESSIONUP#" ,
48 "#SESSIONDOWN#" , "#TOTALUP#", "#TOTALDOWN#" , "#SERVER#" , "#IP#",
49 "#PORT#" };
50
51 snprintf(version, 25, "cas %s", CAS_VERSION"0.8");
52 snprintf(upload, 25, "%s kB/s", stats[7]);
53 snprintf(download, 25, "%s kB/s", stats[6]);
54
55 char *repl[] = { version , lines[0] , stats[10] , upload , download ,
56 stats[8] , stats[9] , stats[15] , stats[14] , stats[12] , stats[11] ,
57 stats[1] , stats[2] , stats[3] };
58
59 /* get some memory to read the template into */
60 int fdTmpl;
61 if ((fdTmpl = open(template, O_RDONLY00)) < 0)
1
Taking false branch
62 {
63 printf("\n\n%s\n",template);
64 perror("Could not open file");
65 exit (43);
66 }
67
68 struct stat sb;
69 if (fstat(fdTmpl, &sb) < 0)
2
Taking false branch
70 {
71 perror("Could not stat file");
72 exit(43);
73 }
74 close(fdTmpl);
75
76 /* 2 times the size of the template should be enough */
77 /* st_size is defined as off_t, but size_t seems more reasonable */
78 size_t size = sb.st_size*2;
79 char *mem = calloc(size, 1);
80 if (NULL((void*)0) == mem)
3
Assuming 'mem' is not equal to NULL
4
Taking false branch
81 {
82 perror("Could not calloc\n");
83 exit(44);
84 }
85
86 /* read the template into the memory */
87 size_t len = 0;
88 int ler;
89 FILE *fTmpl = fopen(template,"r");
5
Assuming pointer value is null
6
Assuming that 'fopen' fails
7
'fTmpl' initialized here
90 while ((ler=fgetc(fTmpl)) != EOF(-1) && len+1 < size)
8
Null pointer passed to 1st parameter expecting 'nonnull'
91 {
92 mem[len++] = ler;
93 }
94 fclose(fTmpl);
95
96 /* printf ("HTML: %s\n", mem); */
97
98 int t;
99 for (t=0; t<=13; t++)
100 {
101 /* replace the special tags */
102 replace(mem, search[t], repl[t]);
103 }
104
105 /* printf("FINAL: %s\n",mem); */
106
107 path = get_amule_path("aMule-online-sign.html", 0, path_for_html);
108
109 if (NULL((void*)0) == path)
110 {
111 perror("could not get the HTML path\n");
112 free(mem);
113 return 0;
114 }
115
116 FILE *fHTML = NULL((void*)0);
117 if ((fHTML = fopen(path, "w")) == NULL((void*)0))
118 {
119 perror("Unable to create file\n");
120 free(path);
121 free(mem);
122 exit(44);
123 }
124 free(path);
125
126 fprintf(fHTML, "%s", mem);
127 fclose(fHTML);
128 free(mem);
129
130 printf("HTML file created.\n");
131
132 return 1;
133}