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 configfile.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 configfile.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
| 31 | |
| 32 | #include "configfile.h" |
| 33 | #include "functions.h" |
| 34 | |
| 35 | #define STRINGIFY(x) #x |
| 36 | #define STRINGIFY_EXPAND(x) STRINGIFY(x) |
| 37 | |
| 38 | #define MAX_CONF_ARG_LEN_STR STRINGIFY_EXPAND(MAX_CONF_ARG_LEN) |
| 39 | |
| 40 | #define MAX_CONF_KEY_LEN 12 |
| 41 | #define MAX_CONF_KEY_LEN_STR STRINGIFY_EXPAND(MAX_CONF_KEY_LEN) |
| 42 | |
| 43 | int writeconfig(void) |
| 44 | { |
| 45 | FILE *config; |
| 46 | char *path; |
| 47 | unsigned int i; |
| 48 | char *def[] = { |
| 49 | "# cas config file\n", |
| 50 | "#\n", |
| 51 | "# font - full path to a ttf font\n", |
| 52 | "# font_size - size the font\n", |
| 53 | "# source_image - image where the text will be written\n", |
| 54 | "# *_line - x,y,[1/0] enabled or disabled\n\n", |
| 55 | "font /usr/share/fonts/corefonts/times.ttf\n", |
| 56 | "font_size 10.5\n", |
| 57 | "source_image /usr/share/cas/stat.png\n", |
| 58 | "first_line 23,17,1\n", |
| 59 | "second_line 23,34,1\n", |
| 60 | "third_line 23,51,1\n", |
| 61 | "fourth_line 23,68,1\n", |
| 62 | "fifth_line 23,85,1\n", |
| 63 | "sixth_line 23,102,1\n", |
| 64 | "seventh_line 23,119,1\n", |
| 65 | "template /usr/share/cas/tmp.html\n" |
| 66 | "img_type 0\n" |
| 67 | }; |
| 68 | |
| 69 | path = get_path("casrc"); |
| 70 | if (path == NULL) |
| 71 | return 0; |
| 72 | |
| 73 | if ( (config = fopen(path, "w")) == NULL) |
| 74 | return 0; |
| 75 | |
| 76 | for (i = 0; i < sizeof(def) / sizeof(char *); i++) |
| 77 | fprintf(config, "%s", def[i]); |
| 78 | |
| 79 | fclose(config); |
| 80 | |
| 81 | printf("%s created, please edit it and then rerun cas\n", path); |
| 82 | free(path); |
| 83 | |
| 84 | return 1; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | int readconfig(CONF *config) |
| 89 | { |
| 90 | char buffer[120], option[15], *path; |
| 91 | FILE *conf; |
| 92 | int i; |
| 93 | char lines[IMG_TEXTLINES][13] = { |
| 94 | "first_line", |
| 95 | "second_line", |
| 96 | "third_line", |
| 97 | "fourth_line", |
| 98 | "fifth_line", |
| 99 | "sixth_line", |
| 100 | "seventh_line" |
| 101 | }; |
| 102 | |
| 103 | path = get_path("casrc"); |
| 104 | if (path == NULL) { |
| 1 | Assuming 'path' is not equal to NULL | |
|
| |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | if ((conf = fopen(path, "r")) == NULL) { |
| |
| 109 | printf("Unable to open %s. Creating it.\n", path); |
| 110 | free(path); |
| 111 | if (!writeconfig()) { |
| 112 | perror("readconfig: unable to create initial config file\n"); |
| 113 | } |
| 114 | return 0; |
| 115 | } |
| 116 | free(path); |
| 117 | |
| 118 | buffer[0] = 0; |
| 119 | while (!feof(conf)) { |
| 4 | | Loop condition is true. Entering loop body | |
|
| 7 | | Loop condition is true. Entering loop body | |
|
| 120 | |
| 121 | if (fgets (buffer,120,conf)) { |
| 5 | | Assuming this stream operation fails | |
|
| |
| 8 | | File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior |
|
| 122 | if (buffer[0] != '#') { |
| 123 | |
| 124 | sscanf(buffer, "%" MAX_CONF_KEY_LEN_STR "s %*" MAX_CONF_ARG_LEN_STR "s", option); |
| 125 | fflush (stdout); |
| 126 | |
| 127 | if (strcmp(option, "font") == 0) { |
| 128 | sscanf(buffer, "%*" MAX_CONF_KEY_LEN_STR "s %" MAX_CONF_ARG_LEN_STR "s", config->font); |
| 129 | } |
| 130 | if (strcmp(option, "font_size") == 0) { |
| 131 | sscanf(buffer, "%*" MAX_CONF_KEY_LEN_STR "s %10f", &config->size); |
| 132 | } |
| 133 | if (strcmp(option, "source_image") == 0) { |
| 134 | sscanf(buffer, "%*" MAX_CONF_KEY_LEN_STR "s %" MAX_CONF_ARG_LEN_STR "s", config->source); |
| 135 | } |
| 136 | if (strcmp(option, "template") == 0) { |
| 137 | sscanf(buffer, "%*" MAX_CONF_KEY_LEN_STR "s %" MAX_CONF_ARG_LEN_STR "s", config->template); |
| 138 | } |
| 139 | if (strcmp(option, "img_type") == 0) { |
| 140 | sscanf(buffer, "%*" MAX_CONF_KEY_LEN_STR "s %1d", &config->img_type); |
| 141 | } |
| 142 | |
| 143 | for (i = 0; i < IMG_TEXTLINES; i++) { |
| 144 | if (strcmp(option, lines[i]) == 0) { |
| 145 | sscanf(buffer, |
| 146 | "%*" MAX_CONF_KEY_LEN_STR "s %4d,%4d,%4d", |
| 147 | &config->x[i], &config->y[i], |
| 148 | &config->enabled[i]); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | fclose(conf); |
| 156 | |
| 157 | return 1; |
| 158 | } |
| 159 | |