clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name conf.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 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.sbin/sasyncd/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/usr.sbin/sasyncd -I /usr/src/usr.sbin/sasyncd/../../sbin/iked -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/sasyncd/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c conf.c
| 1 | #include <stdlib.h> |
| 2 | #include <string.h> |
| 3 | #define YYBYACC 1 |
| 4 | #define YYMAJOR 1 |
| 5 | #define YYMINOR 9 |
| 6 | #define YYLEX yylex() |
| 7 | #define YYEMPTY -1 |
| 8 | #define yyclearin (yychar=(YYEMPTY)) |
| 9 | #define yyerrok (yyerrflag=0) |
| 10 | #define YYRECOVERING() (yyerrflag!=0) |
| 11 | #define YYPREFIX "yy" |
| 12 | #line 30 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 13 | #include <sys/types.h> |
| 14 | #include <sys/stat.h> |
| 15 | #include <sys/socket.h> |
| 16 | #include <ctype.h> |
| 17 | #include <fcntl.h> |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | #include <unistd.h> |
| 22 | #include <pwd.h> |
| 23 | |
| 24 | #include "sasyncd.h" |
| 25 | #include "net.h" |
| 26 | |
| 27 | |
| 28 | struct cfgstate cfgstate; |
| 29 | |
| 30 | |
| 31 | int conflen = 0; |
| 32 | char *confbuf, *confptr; |
| 33 | |
| 34 | int yyparse(void); |
| 35 | int yylex(void); |
| 36 | void yyerror(const char *); |
| 37 | unsigned char x2i(unsigned char *); |
| 38 | #line 57 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 39 | #ifndef YYSTYPE_DEFINED |
| 40 | #define YYSTYPE_DEFINED |
| 41 | typedef union { |
| 42 | char *string; |
| 43 | int val; |
| 44 | struct { |
| 45 | unsigned char *data; |
| 46 | int len; |
| 47 | } hex; |
| 48 | } YYSTYPE; |
| 49 | #endif /* YYSTYPE_DEFINED */ |
| 50 | #line 51 "conf.c" |
| 51 | #define MODE 257 |
| 52 | #define INTERFACE 258 |
| 53 | #define INTERVAL 259 |
| 54 | #define LISTEN 260 |
| 55 | #define ON 261 |
| 56 | #define PORT 262 |
| 57 | #define PEER 263 |
| 58 | #define SHAREDKEY 264 |
| 59 | #define Y_SLAVE 265 |
| 60 | #define Y_MASTER 266 |
| 61 | #define INET 267 |
| 62 | #define INET6 268 |
| 63 | #define FLUSHMODE 269 |
| 64 | #define STARTUP 270 |
| 65 | #define NEVER 271 |
| 66 | #define SYNC 272 |
| 67 | #define GROUP 273 |
| 68 | #define SKIPSLAVE 274 |
| 69 | #define CONTROL 275 |
| 70 | #define STRING 276 |
| 71 | #define HEX 277 |
| 72 | #define VALUE 278 |
| 73 | #define YYERRCODE 256 |
| 74 | const short yylhs[] = |
| 75 | { -1, |
| 76 | 0, 0, 1, 1, 1, 2, 2, 3, 3, 7, |
| 77 | 7, 4, 4, 4, 8, 8, 5, 6, 6, 6, |
| 78 | 6, 6, 6, 6, 6, |
| 79 | }; |
| 80 | const short yylen[] = |
| 81 | { 2, |
| 82 | 0, 2, 0, 1, 1, 0, 2, 1, 1, 1, |
| 83 | 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, |
| 84 | 2, 5, 2, 2, 2, |
| 85 | }; |
| 86 | const short yydefred[] = |
| 87 | { 1, |
| 88 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, |
| 89 | 9, 8, 10, 11, 23, 18, 0, 21, 15, 16, |
| 90 | 24, 12, 13, 14, 20, 19, 17, 25, 0, 4, |
| 91 | 5, 0, 0, 22, 7, |
| 92 | }; |
| 93 | const short yydgoto[] = |
| 94 | { 1, |
| 95 | 32, 34, 14, 25, 28, 10, 15, 21, |
| 96 | }; |
| 97 | const short yysindex[] = |
| 98 | { 0, |
| 99 | -253, -251, -276, -244, -270, -274, -246, -268, -258, 0, |
| 100 | 0, 0, 0, 0, 0, 0, -257, 0, 0, 0, |
| 101 | 0, 0, 0, 0, 0, 0, 0, 0, -255, 0, |
| 102 | 0, -241, -250, 0, 0,}; |
| 103 | const short yyrindex[] = |
| 104 | { 0, |
| 105 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 106 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 107 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, |
| 108 | 0, 9, 0, 0, 0,}; |
| 109 | const short yygindex[] = |
| 110 | { 0, |
| 111 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 112 | }; |
| 113 | #define YYTABLESIZE 284 |
| 114 | const short yytable[] = |
| 115 | { 16, |
| 116 | 3, 19, 20, 2, 3, 18, 4, 26, 6, 5, |
| 117 | 6, 30, 31, 11, 12, 7, 17, 27, 29, 8, |
| 118 | 33, 9, 13, 22, 23, 24, 0, 35, 0, 0, |
| 119 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 120 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 121 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 122 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 123 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 124 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 125 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 126 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 127 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 128 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 129 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 130 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 131 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 132 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 133 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 134 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 135 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 136 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 137 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 138 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 139 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 140 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 141 | 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, |
| 142 | 3, 0, 3, 3, 3, 6, 6, 0, 6, 3, |
| 143 | 0, 6, 6, 3, 0, 3, 0, 6, 0, 0, |
| 144 | 0, 6, 0, 6, |
| 145 | }; |
| 146 | const short yycheck[] = |
| 147 | { 276, |
| 148 | 0, 276, 277, 257, 258, 276, 260, 276, 0, 263, |
| 149 | 264, 267, 268, 265, 266, 269, 261, 276, 276, 273, |
| 150 | 262, 275, 274, 270, 271, 272, -1, 278, -1, -1, |
| 151 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 152 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 153 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 154 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 155 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 156 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 157 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 158 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 159 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 160 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 161 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 162 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 163 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 164 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 165 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 166 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 167 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 168 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 169 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 170 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 171 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 172 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 173 | -1, -1, -1, -1, -1, -1, -1, 257, 258, -1, |
| 174 | 260, -1, 262, 263, 264, 257, 258, -1, 260, 269, |
| 175 | -1, 263, 264, 273, -1, 275, -1, 269, -1, -1, |
| 176 | -1, 273, -1, 275, |
| 177 | }; |
| 178 | #define YYFINAL 1 |
| 179 | #ifndef YYDEBUG |
| 180 | #define YYDEBUG 0 |
| 181 | #endif |
| 182 | #define YYMAXTOKEN 278 |
| 183 | #if YYDEBUG |
| 184 | const char * const yyname[] = |
| 185 | { |
| 186 | "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 187 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 188 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 189 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 190 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 191 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 192 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"MODE","INTERFACE","INTERVAL", |
| 193 | "LISTEN","ON","PORT","PEER","SHAREDKEY","Y_SLAVE","Y_MASTER","INET","INET6", |
| 194 | "FLUSHMODE","STARTUP","NEVER","SYNC","GROUP","SKIPSLAVE","CONTROL","STRING", |
| 195 | "HEX","VALUE", |
| 196 | }; |
| 197 | const char * const yyrule[] = |
| 198 | {"$accept : settings", |
| 199 | "settings :", |
| 200 | "settings : settings setting", |
| 201 | "af :", |
| 202 | "af : INET", |
| 203 | "af : INET6", |
| 204 | "port :", |
| 205 | "port : PORT VALUE", |
| 206 | "mode : Y_MASTER", |
| 207 | "mode : Y_SLAVE", |
| 208 | "modes : SKIPSLAVE", |
| 209 | "modes : mode", |
| 210 | "flushmode : STARTUP", |
| 211 | "flushmode : NEVER", |
| 212 | "flushmode : SYNC", |
| 213 | "key : STRING", |
| 214 | "key : HEX", |
| 215 | "ctlmode : STRING", |
| 216 | "setting : INTERFACE STRING", |
| 217 | "setting : GROUP STRING", |
| 218 | "setting : FLUSHMODE flushmode", |
| 219 | "setting : PEER STRING", |
| 220 | "setting : LISTEN ON STRING af port", |
| 221 | "setting : MODE modes", |
| 222 | "setting : SHAREDKEY key", |
| 223 | "setting : CONTROL ctlmode", |
| 224 | }; |
| 225 | #endif |
| 226 | #ifdef YYSTACKSIZE |
| 227 | #undef YYMAXDEPTH |
| 228 | #define YYMAXDEPTH YYSTACKSIZE |
| 229 | #else |
| 230 | #ifdef YYMAXDEPTH |
| 231 | #define YYSTACKSIZE YYMAXDEPTH |
| 232 | #else |
| 233 | #define YYSTACKSIZE 10000 |
| 234 | #define YYMAXDEPTH 10000 |
| 235 | #endif |
| 236 | #endif |
| 237 | #define YYINITSTACKSIZE 200 |
| 238 | |
| 239 | int yydebug; |
| 240 | int yynerrs; |
| 241 | int yyerrflag; |
| 242 | int yychar; |
| 243 | short *yyssp; |
| 244 | YYSTYPE *yyvsp; |
| 245 | YYSTYPE yyval; |
| 246 | YYSTYPE yylval; |
| 247 | short *yyss; |
| 248 | short *yysslim; |
| 249 | YYSTYPE *yyvs; |
| 250 | unsigned int yystacksize; |
| 251 | int yyparse(void); |
| 252 | #line 241 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 253 | |
| 254 | |
| 255 | struct keyword { |
| 256 | char *name; |
| 257 | int value; |
| 258 | }; |
| 259 | |
| 260 | static int |
| 261 | match_cmp(const void *a, const void *b) |
| 262 | { |
| 263 | return strcmp(a, ((const struct keyword *)b)->name); |
| 264 | } |
| 265 | |
| 266 | static int |
| 267 | match(char *token) |
| 268 | { |
| 269 | |
| 270 | static const struct keyword keywords[] = { |
| 271 | { "control", CONTROL }, |
| 272 | { "flushmode", FLUSHMODE }, |
| 273 | { "group", GROUP }, |
| 274 | { "inet", INET }, |
| 275 | { "inet6", INET6 }, |
| 276 | { "interface", INTERFACE }, |
| 277 | { "listen", LISTEN }, |
| 278 | { "master", Y_MASTER }, |
| 279 | { "mode", MODE }, |
| 280 | { "never", NEVER }, |
| 281 | { "on", ON }, |
| 282 | { "peer", PEER }, |
| 283 | { "port", PORT }, |
| 284 | { "sharedkey", SHAREDKEY }, |
| 285 | { "skipslave", SKIPSLAVE }, |
| 286 | { "slave", Y_SLAVE }, |
| 287 | { "startup", STARTUP }, |
| 288 | { "sync", SYNC }, |
| 289 | }; |
| 290 | const struct keyword *k; |
| 291 | |
| 292 | k = bsearch(token, keywords, sizeof keywords / sizeof keywords[0], |
| 293 | sizeof keywords[0], match_cmp); |
| 294 | |
| 295 | return k ? k->value : STRING; |
| 296 | } |
| 297 | |
| 298 | int |
| 299 | yylex(void) |
| 300 | { |
| 301 | char *p; |
| 302 | int v, i, len; |
| 303 | |
| 304 | |
| 305 | if (!confptr) |
| 306 | confptr = confbuf; |
| 307 | else { |
| 308 | for (p = confptr; p < confbuf + conflen && *p; p++) |
| 309 | ; |
| 310 | if (p == confbuf + conflen) |
| 311 | return 0; |
| 312 | p++; |
| 313 | if (!*p) |
| 314 | return 0; |
| 315 | confptr = p; |
| 316 | } |
| 317 | |
| 318 | |
| 319 | p = confptr; |
| 320 | if (!strncmp(p, "0x", 2)) { |
| 321 | for (p = confptr + 2; *p; p++) |
| 322 | if (!isxdigit(*p)) |
| 323 | goto is_string; |
| 324 | p = confptr + 2; |
| 325 | len = strlen(p) / 2; |
| 326 | if ((yylval.hex.data = calloc(len, sizeof(unsigned char))) |
| 327 | == NULL) { |
| 328 | log_err("yylex: calloc()"); |
| 329 | exit(1); |
| 330 | } |
| 331 | for (i = 0; i < len; i++) |
| 332 | yylval.hex.data[i] = x2i(p + 2 * i); |
| 333 | yylval.hex.len = len; |
| 334 | return HEX; |
| 335 | } |
| 336 | |
| 337 | |
| 338 | if (isdigit(*confptr)) { |
| 339 | for (p = confptr; *p; p++) |
| 340 | if (*p == '.' || *p == ':') |
| 341 | goto is_string; |
| 342 | v = (int)strtol(confptr, (char **)NULL, 10); |
| 343 | yylval.val = v; |
| 344 | return VALUE; |
| 345 | } |
| 346 | |
| 347 | is_string: |
| 348 | v = match(confptr); |
| 349 | if (v == STRING) { |
| 350 | yylval.string = strdup(confptr); |
| 351 | if (!yylval.string) { |
| 352 | log_err("yylex: strdup()"); |
| 353 | exit(1); |
| 354 | } |
| 355 | } |
| 356 | return v; |
| 357 | } |
| 358 | |
| 359 | int |
| 360 | conf_parse_file(char *cfgfile) |
| 361 | { |
| 362 | struct stat st; |
| 363 | int fd, r; |
| 364 | char *buf, *s, *d; |
| 365 | struct passwd *pw; |
| 366 | |
| 367 | if (stat(cfgfile, &st) != 0) |
| 368 | goto bad; |
| 369 | |
| 370 | pw = getpwnam(SASYNCD_USER); |
| 371 | if (pw == NULL) { |
| 372 | log_err("getpwnam(%s) failed", SASYNCD_USER); |
| 373 | return 1; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | if ((st.st_uid && st.st_uid != pw->pw_uid) || |
| 378 | ((st.st_mode & S_IFMT) != S_IFREG) || |
| 379 | ((st.st_mode & (S_IRWXG | S_IRWXO)) != 0)) { |
| 380 | log_msg(0, "configuration file has bad owner, type or mode"); |
| 381 | goto bad; |
| 382 | } |
| 383 | |
| 384 | fd = open(cfgfile, O_RDONLY); |
| 385 | if (fd == -1) |
| 386 | goto bad; |
| 387 | |
| 388 | conflen = st.st_size; |
| 389 | buf = malloc(conflen + 1); |
| 390 | if (!buf) { |
| 391 | log_err("malloc(%d) failed", conflen + 1); |
| 392 | close(fd); |
| 393 | return 1; |
| 394 | } |
| 395 | |
| 396 | if (read(fd, buf, conflen) != conflen) { |
| 397 | log_err("read() failed"); |
| 398 | free(buf); |
| 399 | close(fd); |
| 400 | return 1; |
| 401 | } |
| 402 | close(fd); |
| 403 | |
| 404 | |
| 405 | buf[conflen] = (char)0; |
| 406 | for (s = buf, d = s; s < buf + conflen && *s; s++) { |
| 407 | if (isspace(*s) && isspace(*(s+1))) |
| 408 | continue; |
| 409 | if (*s == '#') { |
| 410 | while (*s != '\n' && s < buf + conflen) |
| 411 | s++; |
| 412 | while (*s == '\n' && s < buf + conflen) |
| 413 | s++; |
| 414 | s--; |
| 415 | continue; |
| 416 | } |
| 417 | if (d == buf && isspace(*s)) |
| 418 | continue; |
| 419 | *d++ = *s; |
| 420 | } |
| 421 | *d = (char)0; |
| 422 | for (s = buf; s <= d; s++) |
| 423 | if (isspace(*s)) |
| 424 | *s = (char)0; |
| 425 | |
| 426 | confbuf = buf; |
| 427 | confptr = NULL; |
| 428 | r = yyparse(); |
| 429 | free(buf); |
| 430 | |
| 431 | if (!cfgstate.carp_ifgroup) |
| 432 | cfgstate.carp_ifgroup = strdup("carp"); |
| 433 | |
| 434 | return r; |
| 435 | |
| 436 | bad: |
| 437 | log_msg(0, "failed to open \"%s\"", cfgfile); |
| 438 | return 1; |
| 439 | } |
| 440 | |
| 441 | unsigned char |
| 442 | x2i(unsigned char *s) |
| 443 | { |
| 444 | char ss[3]; |
| 445 | |
| 446 | ss[0] = s[0]; |
| 447 | ss[1] = s[1]; |
| 448 | ss[2] = 0; |
| 449 | |
| 450 | return ((unsigned char)strtoul(ss, NULL, 16)); |
| 451 | } |
| 452 | |
| 453 | void |
| 454 | yyerror(const char *s) |
| 455 | { |
| 456 | fprintf(stderr, "config: %s\n", s); |
| 457 | } |
| 458 | #line 451 "conf.c" |
| 459 | |
| 460 | static int yygrowstack(void) |
| 461 | { |
| 462 | unsigned int newsize; |
| 463 | long sslen; |
| 464 | short *newss; |
| 465 | YYSTYPE *newvs; |
| 466 | |
| 467 | if ((newsize = yystacksize) == 0) |
| 43 | | Assuming the condition is false | |
|
| |
| 468 | newsize = YYINITSTACKSIZE; |
| 469 | else if (newsize >= YYMAXDEPTH) |
| 45 | | Assuming 'newsize' is < YYMAXDEPTH | |
|
| |
| 470 | return -1; |
| 471 | else if ((newsize *= 2) > YYMAXDEPTH) |
| 47 | | Assuming the condition is false | |
|
| |
| 472 | newsize = YYMAXDEPTH; |
| 473 | sslen = yyssp - yyss; |
| 474 | #ifdef SIZE_MAX |
| 475 | #define YY_SIZE_MAX SIZE_MAX |
| 476 | #else |
| 477 | #define YY_SIZE_MAX 0xffffffffU |
| 478 | #endif |
| 479 | if (newsize && YY_SIZE_MAX / newsize < sizeof *newss) |
| 49 | | Assuming 'newsize' is 0 | |
|
| 480 | goto bail; |
| 481 | newss = (short *)realloc(yyss, newsize * sizeof *newss); |
| 482 | if (newss == NULL) |
| 50 | | Assuming 'newss' is not equal to NULL | |
|
| |
| 483 | goto bail; |
| 484 | yyss = newss; |
| 485 | yyssp = newss + sslen; |
| 486 | if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs) |
| 487 | goto bail; |
| 488 | newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs); |
| 489 | if (newvs == NULL) |
| 52 | | Assuming 'newvs' is not equal to NULL | |
|
| |
| 490 | goto bail; |
| 491 | yyvs = newvs; |
| 492 | yyvsp = newvs + sslen; |
| 493 | yystacksize = newsize; |
| 494 | yysslim = yyss + newsize - 1; |
| 495 | return 0; |
| 496 | bail: |
| 497 | if (yyss) |
| 498 | free(yyss); |
| 499 | if (yyvs) |
| 500 | free(yyvs); |
| 501 | yyss = yyssp = NULL; |
| 502 | yyvs = yyvsp = NULL; |
| 503 | yystacksize = 0; |
| 504 | return -1; |
| 505 | } |
| 506 | |
| 507 | #define YYABORT goto yyabort |
| 508 | #define YYREJECT goto yyabort |
| 509 | #define YYACCEPT goto yyaccept |
| 510 | #define YYERROR goto yyerrlab |
| 511 | int |
| 512 | yyparse(void) |
| 513 | { |
| 514 | int yym, yyn, yystate; |
| 515 | #if YYDEBUG |
| 516 | const char *yys; |
| 517 | |
| 518 | if ((yys = getenv("YYDEBUG"))) |
| 519 | { |
| 520 | yyn = *yys; |
| 521 | if (yyn >= '0' && yyn <= '9') |
| 522 | yydebug = yyn - '0'; |
| 523 | } |
| 524 | #endif /* YYDEBUG */ |
| 525 | |
| 526 | yynerrs = 0; |
| 527 | yyerrflag = 0; |
| 528 | yychar = (-1); |
| 529 | |
| 530 | if (yyss == NULL && yygrowstack()) goto yyoverflow; |
| 1 | Assuming 'yyss' is not equal to NULL | |
|
| 531 | yyssp = yyss; |
| 532 | yyvsp = yyvs; |
| 533 | *yyssp = yystate = 0; |
| 534 | |
| 535 | yyloop: |
| 536 | if ((yyn = yydefred[yystate]) != 0) goto yyreduce; |
| |
| 3 | | Control jumps to line 643 | |
|
| |
| 23 | | Assuming the condition is false | |
|
| |
| 537 | if (yychar < 0) |
| |
| |
| 538 | { |
| 539 | if ((yychar = yylex()) < 0) yychar = 0; |
| 26 | | Assuming the condition is false | |
|
| |
| 540 | #if YYDEBUG |
| 541 | if (yydebug) |
| 542 | { |
| 543 | yys = 0; |
| 544 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
| 545 | if (!yys) yys = "illegal-symbol"; |
| 546 | printf("%sdebug: state %d, reading %d (%s)\n", |
| 547 | YYPREFIX, yystate, yychar, yys); |
| 548 | } |
| 549 | #endif |
| 550 | } |
| 551 | if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && |
| 15 | | Assuming 'yyn' is not equal to 0 | |
|
| 16 | | Assuming the condition is true | |
|
| |
| |
| 552 | yyn <= YYTABLESIZE && yycheck[yyn] == yychar) |
| 17 | | Assuming 'yyn' is <= YYTABLESIZE | |
|
| 18 | | Assuming the condition is true | |
|
| 553 | { |
| 554 | #if YYDEBUG |
| 555 | if (yydebug) |
| 556 | printf("%sdebug: state %d, shifting to state %d\n", |
| 557 | YYPREFIX, yystate, yytable[yyn]); |
| 558 | #endif |
| 559 | if (yyssp >= yysslim && yygrowstack()) |
| 20 | | Assuming 'yyssp' is < 'yysslim' | |
|
| 560 | { |
| 561 | goto yyoverflow; |
| 562 | } |
| 563 | *++yyssp = yystate = yytable[yyn]; |
| 564 | *++yyvsp = yylval; |
| 565 | yychar = (-1); |
| 566 | if (yyerrflag > 0) --yyerrflag; |
| |
| 567 | goto yyloop; |
| 22 | | Control jumps to line 536 | |
|
| 568 | } |
| 569 | if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && |
| |
| 570 | yyn <= YYTABLESIZE && yycheck[yyn] == yychar) |
| 571 | { |
| 572 | yyn = yytable[yyn]; |
| 573 | goto yyreduce; |
| 574 | } |
| 575 | if (yyerrflag) goto yyinrecovery; |
| 30 | | Assuming 'yyerrflag' is not equal to 0 | |
|
| |
| 32 | | Control jumps to line 587 | |
|
| 576 | #if defined(__GNUC__) |
| 577 | goto yynewerror; |
| 578 | #endif |
| 579 | yynewerror: |
| 580 | yyerror("syntax error"); |
| 581 | #if defined(__GNUC__) |
| 582 | goto yyerrlab; |
| 583 | #endif |
| 584 | yyerrlab: |
| 585 | ++yynerrs; |
| 586 | yyinrecovery: |
| 587 | if (yyerrflag < 3) |
| 33 | | Assuming 'yyerrflag' is < 3 | |
|
| |
| 588 | { |
| 589 | yyerrflag = 3; |
| 590 | for (;;) |
| 35 | | Loop condition is true. Entering loop body | |
|
| 591 | { |
| 592 | if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && |
| 36 | | Assuming 'yyn' is not equal to 0 | |
|
| 37 | | Assuming the condition is true | |
|
| |
| 593 | yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) |
| 38 | | Assuming 'yyn' is <= YYTABLESIZE | |
|
| 39 | | Assuming the condition is true | |
|
| 594 | { |
| 595 | #if YYDEBUG |
| 596 | if (yydebug) |
| 597 | printf("%sdebug: state %d, error recovery shifting\ |
| 598 | to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); |
| 599 | #endif |
| 600 | if (yyssp >= yysslim && yygrowstack()) |
| 41 | | Assuming 'yyssp' is >= 'yysslim' | |
|
| |
| 54 | | Returning from 'yygrowstack' | |
|
| |
| 601 | { |
| 602 | goto yyoverflow; |
| 603 | } |
| 604 | *++yyssp = yystate = yytable[yyn]; |
| 56 | | Use of zero-allocated memory |
|
| 605 | *++yyvsp = yylval; |
| 606 | goto yyloop; |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | #if YYDEBUG |
| 611 | if (yydebug) |
| 612 | printf("%sdebug: error recovery discarding state %d\n", |
| 613 | YYPREFIX, *yyssp); |
| 614 | #endif |
| 615 | if (yyssp <= yyss) goto yyabort; |
| 616 | --yyssp; |
| 617 | --yyvsp; |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | else |
| 622 | { |
| 623 | if (yychar == 0) goto yyabort; |
| 624 | #if YYDEBUG |
| 625 | if (yydebug) |
| 626 | { |
| 627 | yys = 0; |
| 628 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
| 629 | if (!yys) yys = "illegal-symbol"; |
| 630 | printf("%sdebug: state %d, error recovery discards token %d (%s)\n", |
| 631 | YYPREFIX, yystate, yychar, yys); |
| 632 | } |
| 633 | #endif |
| 634 | yychar = (-1); |
| 635 | goto yyloop; |
| 636 | } |
| 637 | yyreduce: |
| 638 | #if YYDEBUG |
| 639 | if (yydebug) |
| 640 | printf("%sdebug: state %d, reducing by rule %d (%s)\n", |
| 641 | YYPREFIX, yystate, yyn, yyrule[yyn]); |
| 642 | #endif |
| 643 | yym = yylen[yyn]; |
| 644 | if (yym) |
| |
| 645 | yyval = yyvsp[1-yym]; |
| 646 | else |
| 647 | memset(&yyval, 0, sizeof yyval); |
| 648 | switch (yyn) |
| 5 | | 'Default' branch taken. Execution continues on line 849 | |
|
| 649 | { |
| 650 | case 3: |
| 651 | #line 81 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 652 | { yyval.val = AF_UNSPEC; } |
| 653 | break; |
| 654 | case 4: |
| 655 | #line 82 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 656 | { yyval.val = AF_INET; } |
| 657 | break; |
| 658 | case 5: |
| 659 | #line 83 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 660 | { yyval.val = AF_INET6; } |
| 661 | break; |
| 662 | case 6: |
| 663 | #line 86 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 664 | { yyval.val = SASYNCD_DEFAULT_PORT; } |
| 665 | break; |
| 666 | case 7: |
| 667 | #line 87 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 668 | { yyval.val = yyvsp[0].val; } |
| 669 | break; |
| 670 | case 8: |
| 671 | #line 90 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 672 | { yyval.val = MASTER; } |
| 673 | break; |
| 674 | case 9: |
| 675 | #line 91 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 676 | { yyval.val = SLAVE; } |
| 677 | break; |
| 678 | case 10: |
| 679 | #line 95 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 680 | { |
| 681 | cfgstate.flags |= SKIP_LOCAL_SAS; |
| 682 | log_msg(2, "config: not syncing SA to peers"); |
| 683 | } |
| 684 | break; |
| 685 | case 11: |
| 686 | #line 100 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 687 | { |
| 688 | const char *m[] = CARPSTATES; |
| 689 | cfgstate.lockedstate = yyvsp[0].val; |
| 690 | log_msg(2, "config: mode set to %s", m[yyvsp[0].val]); |
| 691 | } |
| 692 | break; |
| 693 | case 12: |
| 694 | #line 107 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 695 | { yyval.val = FM_STARTUP; } |
| 696 | break; |
| 697 | case 13: |
| 698 | #line 108 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 699 | { yyval.val = FM_NEVER; } |
| 700 | break; |
| 701 | case 14: |
| 702 | #line 109 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 703 | { yyval.val = FM_SYNC; } |
| 704 | break; |
| 705 | case 15: |
| 706 | #line 113 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 707 | { |
| 708 | if (cfgstate.sharedkey) |
| 709 | free(cfgstate.sharedkey); |
| 710 | cfgstate.sharedkey = yyvsp[0].string; |
| 711 | cfgstate.sharedkey_len = strlen(yyvsp[0].string) * 8; |
| 712 | log_msg(2, "config: shared ascii key"); |
| 713 | } |
| 714 | break; |
| 715 | case 16: |
| 716 | #line 121 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 717 | { |
| 718 | if (cfgstate.sharedkey) |
| 719 | free(cfgstate.sharedkey); |
| 720 | cfgstate.sharedkey = yyvsp[0].hex.data; |
| 721 | cfgstate.sharedkey_len = yyvsp[0].hex.len * 8; |
| 722 | log_msg(2, "config: %d byte shared hex key", yyvsp[0].hex.len); |
| 723 | } |
| 724 | break; |
| 725 | case 17: |
| 726 | #line 130 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 727 | { |
| 728 | |
| 729 | if (strcmp("isakmpd", yyvsp[0].string) == 0) |
| 730 | yyval.val = CTL_ISAKMPD; |
| 731 | else if (strcmp("iked", yyvsp[0].string) == 0) |
| 732 | yyval.val = CTL_IKED; |
| 733 | else if (strcmp("all", yyvsp[0].string) == 0) |
| 734 | yyval.val = CTL_MASK; |
| 735 | else if (strcmp("none", yyvsp[0].string) == 0) |
| 736 | yyval.val = CTL_NONE; |
| 737 | else { |
| 738 | log_err("config: invalid control mode"); |
| 739 | free(yyvsp[0].string); |
| 740 | YYERROR; |
| 741 | } |
| 742 | log_msg(2, "config: control mode set to %s", yyvsp[0].string); |
| 743 | free(yyvsp[0].string); |
| 744 | } |
| 745 | break; |
| 746 | case 18: |
| 747 | #line 151 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 748 | { |
| 749 | if (cfgstate.carp_ifname) |
| 750 | free(cfgstate.carp_ifname); |
| 751 | cfgstate.carp_ifname = yyvsp[0].string; |
| 752 | log_msg(2, "config: interface %s", |
| 753 | cfgstate.carp_ifname); |
| 754 | } |
| 755 | break; |
| 756 | case 19: |
| 757 | #line 159 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 758 | { |
| 759 | if (cfgstate.carp_ifgroup) |
| 760 | free(cfgstate.carp_ifgroup); |
| 761 | cfgstate.carp_ifgroup = yyvsp[0].string; |
| 762 | log_msg(2, "config: group %s", |
| 763 | cfgstate.carp_ifgroup); |
| 764 | } |
| 765 | break; |
| 766 | case 20: |
| 767 | #line 167 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 768 | { |
| 769 | const char *fm[] = { "STARTUP", "NEVER", "SYNC" }; |
| 770 | cfgstate.flags |= yyvsp[0].val; |
| 771 | log_msg(2, "config: flush mode set to %s", fm[yyvsp[0].val]); |
| 772 | } |
| 773 | break; |
| 774 | case 21: |
| 775 | #line 173 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 776 | { |
| 777 | struct syncpeer *peer; |
| 778 | int duplicate = 0; |
| 779 | |
| 780 | for (peer = LIST_FIRST(&cfgstate.peerlist); peer; |
| 781 | peer = LIST_NEXT(peer, link)) |
| 782 | if (strcmp(yyvsp[0].string, peer->name) == 0) { |
| 783 | duplicate++; |
| 784 | break; |
| 785 | } |
| 786 | if (duplicate) |
| 787 | free(yyvsp[0].string); |
| 788 | else { |
| 789 | peer = calloc(1, sizeof *peer); |
| 790 | if (!peer) { |
| 791 | log_err("config: calloc(1, %lu) " |
| 792 | "failed", sizeof *peer); |
| 793 | free(yyvsp[0].string); |
| 794 | YYERROR; |
| 795 | } |
| 796 | peer->name = yyvsp[0].string; |
| 797 | } |
| 798 | LIST_INSERT_HEAD(&cfgstate.peerlist, peer, link); |
| 799 | cfgstate.peercnt++; |
| 800 | log_msg(2, "config: add peer %s", peer->name); |
| 801 | } |
| 802 | break; |
| 803 | case 22: |
| 804 | #line 200 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 805 | { |
| 806 | char pstr[20]; |
| 807 | |
| 808 | if (cfgstate.listen_on) |
| 809 | free(cfgstate.listen_on); |
| 810 | cfgstate.listen_on = yyvsp[-2].string; |
| 811 | cfgstate.listen_family = yyvsp[-1].val; |
| 812 | cfgstate.listen_port = yyvsp[0].val; |
| 813 | if (yyvsp[0].val < 1 || yyvsp[0].val > IPPORT_HILASTAUTO) { |
| 814 | cfgstate.listen_port = SASYNCD_DEFAULT_PORT; |
| 815 | log_msg(0, "config: bad port, listen-port " |
| 816 | "reset to %u", SASYNCD_DEFAULT_PORT); |
| 817 | } |
| 818 | if (yyvsp[0].val != SASYNCD_DEFAULT_PORT) |
| 819 | snprintf(pstr, sizeof pstr, "port %d",yyvsp[0].val); |
| 820 | log_msg(2, "config: listen on %s %s%s", |
| 821 | cfgstate.listen_on, yyvsp[-1].val == AF_INET6 ? "(IPv6) " : |
| 822 | (yyvsp[-1].val == AF_INET ? "(IPv4) " : ""), |
| 823 | yyvsp[0].val != SASYNCD_DEFAULT_PORT ? pstr : ""); |
| 824 | } |
| 825 | break; |
| 826 | case 24: |
| 827 | #line 222 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 828 | { |
| 829 | int bits; |
| 830 | |
| 831 | bits = cfgstate.sharedkey_len; |
| 832 | if (bits != 128 && bits != 192 && bits != 256) { |
| 833 | log_err("config: bad shared key length %d, " |
| 834 | "should be 128, 192 or 256 bits\n", bits); |
| 835 | YYERROR; |
| 836 | } |
| 837 | log_msg(2, "config: shared key set"); |
| 838 | } |
| 839 | break; |
| 840 | case 25: |
| 841 | #line 234 "/usr/src/usr.sbin/sasyncd/conf.y" |
| 842 | { |
| 843 | cfgstate.flags &= ~CTL_MASK; |
| 844 | cfgstate.flags |= yyvsp[0].val; |
| 845 | } |
| 846 | break; |
| 847 | #line 840 "conf.c" |
| 848 | } |
| 849 | yyssp -= yym; |
| 850 | yystate = *yyssp; |
| 851 | yyvsp -= yym; |
| 852 | yym = yylhs[yyn]; |
| 853 | if (yystate == 0 && yym == 0) |
| |
| 854 | { |
| 855 | #if YYDEBUG |
| 856 | if (yydebug) |
| 857 | printf("%sdebug: after reduction, shifting from state 0 to\ |
| 858 | state %d\n", YYPREFIX, YYFINAL); |
| 859 | #endif |
| 860 | yystate = YYFINAL; |
| 861 | *++yyssp = YYFINAL; |
| 862 | *++yyvsp = yyval; |
| 863 | if (yychar < 0) |
| |
| 864 | { |
| 865 | if ((yychar = yylex()) < 0) yychar = 0; |
| 8 | | Assuming the condition is false | |
|
| |
| 866 | #if YYDEBUG |
| 867 | if (yydebug) |
| 868 | { |
| 869 | yys = 0; |
| 870 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; |
| 871 | if (!yys) yys = "illegal-symbol"; |
| 872 | printf("%sdebug: state %d, reading %d (%s)\n", |
| 873 | YYPREFIX, YYFINAL, yychar, yys); |
| 874 | } |
| 875 | #endif |
| 876 | } |
| 877 | if (yychar == 0) goto yyaccept; |
| 10 | | Assuming 'yychar' is not equal to 0 | |
|
| |
| 878 | goto yyloop; |
| 12 | | Control jumps to line 536 | |
|
| 879 | } |
| 880 | if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && |
| 881 | yyn <= YYTABLESIZE && yycheck[yyn] == yystate) |
| 882 | yystate = yytable[yyn]; |
| 883 | else |
| 884 | yystate = yydgoto[yym]; |
| 885 | #if YYDEBUG |
| 886 | if (yydebug) |
| 887 | printf("%sdebug: after reduction, shifting from state %d \ |
| 888 | to state %d\n", YYPREFIX, *yyssp, yystate); |
| 889 | #endif |
| 890 | if (yyssp >= yysslim && yygrowstack()) |
| 891 | { |
| 892 | goto yyoverflow; |
| 893 | } |
| 894 | *++yyssp = yystate; |
| 895 | *++yyvsp = yyval; |
| 896 | goto yyloop; |
| 897 | yyoverflow: |
| 898 | yyerror("yacc stack overflow"); |
| 899 | yyabort: |
| 900 | if (yyss) |
| 901 | free(yyss); |
| 902 | if (yyvs) |
| 903 | free(yyvs); |
| 904 | yyss = yyssp = NULL; |
| 905 | yyvs = yyvsp = NULL; |
| 906 | yystacksize = 0; |
| 907 | return (1); |
| 908 | yyaccept: |
| 909 | if (yyss) |
| 910 | free(yyss); |
| 911 | if (yyvs) |
| 912 | free(yyvs); |
| 913 | yyss = yyssp = NULL; |
| 914 | yyvs = yyvsp = NULL; |
| 915 | yystacksize = 0; |
| 916 | return (0); |
| 917 | } |