Bug Summary

File:src/gss_cmd.c
Warning:line 417, column 24
Dereference of null pointer

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name gss_cmd.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=none -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=/builds/gsasl/gss/src -resource-dir /usr/lib64/clang/14.0.0 -D HAVE_CONFIG_H -I . -I .. -I ../src/gl -I ../src/gl -I ../lib/headers -I ../lib/headers -D LOCALEDIR="/usr/local/share/locale" -D PIC -internal-isystem /usr/lib64/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/builds/gsasl/gss/src -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/gsasl/gss/clang-analyzer/2022-08-16-210225-28585-1 -x c gss_cmd.c
1/*
2 File autogenerated by gengetopt version 2.23
3 generated with the following command:
4 gengetopt --no-handle-help --no-handle-version --input gss.ggo --file-name gss_cmd Makefile.am
5
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
9*/
10
11/* If we use autoconf. */
12#ifdef HAVE_CONFIG_H1
13#include "config.h"
14#endif
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20#ifndef FIX_UNUSED
21#define FIX_UNUSED(X)(void) (X) (void) (X) /* avoid warnings for unused params */
22#endif
23
24#include <getopt.h>
25
26#include "gss_cmd.h"
27
28const char *gengetopt_args_info_purpose = "Command line interface to GSS, used to explain error codes.";
29
30const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE"gss" " [OPTION]...";
31
32const char *gengetopt_args_info_versiontext = "";
33
34const char *gengetopt_args_info_description = "";
35
36const char *gengetopt_args_info_help[] = {
37 " -h, --help Print help and exit",
38 " -V, --version Print version and exit",
39 " -m, --major=LONG See gss.c for doc string",
40 " -l, --list-mechanisms See gss.c for doc string",
41 " -a, --accept-sec-context[=STRING]\n See gss.c for doc string",
42 " -i, --init-sec-context=STRING See gss.c for doc string",
43 " -n, --server-name=STRING See gss.c for doc string",
44 " -q, --quiet Silent operation (default=off)",
45 0
46};
47
48typedef enum {ARG_NO
49 , ARG_FLAG
50 , ARG_STRING
51 , ARG_LONG
52} cmdline_parser_arg_type;
53
54static
55void clear_given (struct gengetopt_args_info *args_info);
56static
57void clear_args (struct gengetopt_args_info *args_info);
58
59static int
60cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
61 struct cmdline_parser_params *params, const char *additional_error);
62
63
64static char *
65gengetopt_strdup (const char *s);
66
67static
68void clear_given (struct gengetopt_args_info *args_info)
69{
70 args_info->help_given = 0 ;
71 args_info->version_given = 0 ;
72 args_info->major_given = 0 ;
73 args_info->list_mechanisms_given = 0 ;
74 args_info->accept_sec_context_given = 0 ;
75 args_info->init_sec_context_given = 0 ;
76 args_info->server_name_given = 0 ;
77 args_info->quiet_given = 0 ;
78}
79
80static
81void clear_args (struct gengetopt_args_info *args_info)
82{
83 FIX_UNUSED (args_info)(void) (args_info);
84 args_info->major_orig = NULL((void*)0);
85 args_info->accept_sec_context_arg = NULL((void*)0);
86 args_info->accept_sec_context_orig = NULL((void*)0);
87 args_info->init_sec_context_arg = NULL((void*)0);
88 args_info->init_sec_context_orig = NULL((void*)0);
89 args_info->server_name_arg = NULL((void*)0);
90 args_info->server_name_orig = NULL((void*)0);
91 args_info->quiet_flag = 0;
92
93}
94
95static
96void init_args_info(struct gengetopt_args_info *args_info)
97{
98
99
100 args_info->help_help = gengetopt_args_info_help[0] ;
101 args_info->version_help = gengetopt_args_info_help[1] ;
102 args_info->major_help = gengetopt_args_info_help[2] ;
103 args_info->list_mechanisms_help = gengetopt_args_info_help[3] ;
104 args_info->accept_sec_context_help = gengetopt_args_info_help[4] ;
105 args_info->init_sec_context_help = gengetopt_args_info_help[5] ;
106 args_info->server_name_help = gengetopt_args_info_help[6] ;
107 args_info->quiet_help = gengetopt_args_info_help[7] ;
108
109}
110
111void
112cmdline_parser_print_version (void)
113{
114 printf ("%s %s\n",
115 (strlen(CMDLINE_PARSER_PACKAGE_NAME"GNU Generic Security Service") ? CMDLINE_PARSER_PACKAGE_NAME"GNU Generic Security Service" : CMDLINE_PARSER_PACKAGE"gss"),
116 CMDLINE_PARSER_VERSION"1.0.4.17-aca9");
117
118 if (strlen(gengetopt_args_info_versiontext) > 0)
119 printf("\n%s\n", gengetopt_args_info_versiontext);
120}
121
122static void print_help_common(void)
123{
124 size_t len_purpose = strlen(gengetopt_args_info_purpose);
125 size_t len_usage = strlen(gengetopt_args_info_usage);
126
127 if (len_usage > 0) {
128 printf("%s\n", gengetopt_args_info_usage);
129 }
130 if (len_purpose > 0) {
131 printf("%s\n", gengetopt_args_info_purpose);
132 }
133
134 if (len_usage || len_purpose) {
135 printf("\n");
136 }
137
138 if (strlen(gengetopt_args_info_description) > 0) {
139 printf("%s\n\n", gengetopt_args_info_description);
140 }
141}
142
143void
144cmdline_parser_print_help (void)
145{
146 int i = 0;
147 print_help_common();
148 while (gengetopt_args_info_help[i])
149 printf("%s\n", gengetopt_args_info_help[i++]);
150}
151
152void
153cmdline_parser_init (struct gengetopt_args_info *args_info)
154{
155 clear_given (args_info);
156 clear_args (args_info);
157 init_args_info (args_info);
158}
159
160void
161cmdline_parser_params_init(struct cmdline_parser_params *params)
162{
163 if (params)
164 {
165 params->override = 0;
166 params->initialize = 1;
167 params->check_required = 1;
168 params->check_ambiguity = 0;
169 params->print_errors = 1;
170 }
171}
172
173struct cmdline_parser_params *
174cmdline_parser_params_create(void)
175{
176 struct cmdline_parser_params *params =
177 (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
178 cmdline_parser_params_init(params);
179 return params;
180}
181
182static void
183free_string_field (char **s)
184{
185 if (*s)
186 {
187 free (*s);
188 *s = 0;
189 }
190}
191
192
193static void
194cmdline_parser_release (struct gengetopt_args_info *args_info)
195{
196
197 free_string_field (&(args_info->major_orig));
198 free_string_field (&(args_info->accept_sec_context_arg));
199 free_string_field (&(args_info->accept_sec_context_orig));
200 free_string_field (&(args_info->init_sec_context_arg));
201 free_string_field (&(args_info->init_sec_context_orig));
202 free_string_field (&(args_info->server_name_arg));
203 free_string_field (&(args_info->server_name_orig));
204
205
206
207 clear_given (args_info);
208}
209
210
211static void
212write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
213{
214 FIX_UNUSED (values)(void) (values);
215 if (arg) {
216 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
217 } else {
218 fprintf(outfile, "%s\n", opt);
219 }
220}
221
222
223int
224cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
225{
226 int i = 0;
227
228 if (!outfile)
229 {
230 fprintf (stderrstderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE"gss");
231 return EXIT_FAILURE1;
232 }
233
234 if (args_info->help_given)
235 write_into_file(outfile, "help", 0, 0 );
236 if (args_info->version_given)
237 write_into_file(outfile, "version", 0, 0 );
238 if (args_info->major_given)
239 write_into_file(outfile, "major", args_info->major_orig, 0);
240 if (args_info->list_mechanisms_given)
241 write_into_file(outfile, "list-mechanisms", 0, 0 );
242 if (args_info->accept_sec_context_given)
243 write_into_file(outfile, "accept-sec-context", args_info->accept_sec_context_orig, 0);
244 if (args_info->init_sec_context_given)
245 write_into_file(outfile, "init-sec-context", args_info->init_sec_context_orig, 0);
246 if (args_info->server_name_given)
247 write_into_file(outfile, "server-name", args_info->server_name_orig, 0);
248 if (args_info->quiet_given)
249 write_into_file(outfile, "quiet", 0, 0 );
250
251
252 i = EXIT_SUCCESS0;
253 return i;
254}
255
256int
257cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
258{
259 FILE *outfile;
260 int i = 0;
261
262 outfile = fopen(filename, "w");
263
264 if (!outfile)
265 {
266 fprintf (stderrstderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE"gss", filename);
267 return EXIT_FAILURE1;
268 }
269
270 i = cmdline_parser_dump(outfile, args_info);
271 fclose (outfile);
272
273 return i;
274}
275
276void
277cmdline_parser_free (struct gengetopt_args_info *args_info)
278{
279 cmdline_parser_release (args_info);
280}
281
282/** @brief replacement of strdup, which is not standard */
283char *
284gengetopt_strdup (const char *s)
285{
286 char *result = 0;
287 if (!s)
288 return result;
289
290 result = (char*)malloc(strlen(s) + 1);
291 if (result == (char*)0)
292 return (char*)0;
293 strcpy(result, s);
294 return result;
295}
296
297int
298cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
299{
300 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
301}
302
303int
304cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
305 struct cmdline_parser_params *params)
306{
307 int result;
308 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
1
Passing value via 3rd parameter 'args_info'
2
Calling 'cmdline_parser_internal'
309
310 if (result == EXIT_FAILURE1)
311 {
312 cmdline_parser_free (args_info);
313 exit (EXIT_FAILURE1);
314 }
315
316 return result;
317}
318
319int
320cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
321{
322 int result;
323 struct cmdline_parser_params params;
324
325 params.override = override;
326 params.initialize = initialize;
327 params.check_required = check_required;
328 params.check_ambiguity = 0;
329 params.print_errors = 1;
330
331 result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
332
333 if (result == EXIT_FAILURE1)
334 {
335 cmdline_parser_free (args_info);
336 exit (EXIT_FAILURE1);
337 }
338
339 return result;
340}
341
342int
343cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
344{
345 FIX_UNUSED (args_info)(void) (args_info);
346 FIX_UNUSED (prog_name)(void) (prog_name);
347 return EXIT_SUCCESS0;
348}
349
350
351static char *package_name = 0;
352
353/**
354 * @brief updates an option
355 * @param field the generic pointer to the field to update
356 * @param orig_field the pointer to the orig field
357 * @param field_given the pointer to the number of occurrence of this option
358 * @param prev_given the pointer to the number of occurrence already seen
359 * @param value the argument for this option (if null no arg was specified)
360 * @param possible_values the possible values for this option (if specified)
361 * @param default_value the default value (in case the option only accepts fixed values)
362 * @param arg_type the type of this option
363 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
364 * @param override @see cmdline_parser_params.override
365 * @param no_free whether to free a possible previous value
366 * @param multiple_option whether this is a multiple option
367 * @param long_opt the corresponding long option
368 * @param short_opt the corresponding short option (or '-' if none)
369 * @param additional_error possible further error specification
370 */
371static
372int update_arg(void *field, char **orig_field,
373 unsigned int *field_given, unsigned int *prev_given,
374 char *value, const char *possible_values[],
375 const char *default_value,
376 cmdline_parser_arg_type arg_type,
377 int check_ambiguity, int override,
378 int no_free, int multiple_option,
379 const char *long_opt, char short_opt,
380 const char *additional_error)
381{
382 char *stop_char = 0;
383 const char *val = value;
384 int found;
385 char **string_field;
386 FIX_UNUSED (field)(void) (field);
387
388 stop_char = 0;
389 found = 0;
390
391 if (!multiple_option
10.1
'multiple_option' is 0
&& prev_given
10.2
'prev_given' is non-null
&& (*prev_given || (check_ambiguity && *field_given)))
11
Assuming 'check_ambiguity' is 0
392 {
393 if (short_opt != '-')
394 fprintf (stderrstderr, "%s: `--%s' (`-%c') option given more than once%s\n",
395 package_name, long_opt, short_opt,
396 (additional_error ? additional_error : ""));
397 else
398 fprintf (stderrstderr, "%s: `--%s' option given more than once%s\n",
399 package_name, long_opt,
400 (additional_error ? additional_error : ""));
401 return 1; /* failure */
402 }
403
404 FIX_UNUSED (default_value)(void) (default_value);
405
406 if (field_given && *field_given && ! override)
12
Assuming 'field_given' is null
407 return 0;
408 if (prev_given
12.1
'prev_given' is non-null
)
13
Taking true branch
409 (*prev_given)++;
410 if (field_given
13.1
'field_given' is null
)
14
Taking false branch
411 (*field_given)++;
412 if (possible_values
14.1
'possible_values' is null
)
15
Taking false branch
413 val = possible_values[found];
414
415 switch(arg_type) {
16
Control jumps to 'case ARG_FLAG:' at line 416
416 case ARG_FLAG:
417 *((int *)field) = !*((int *)field);
17
Dereference of null pointer
418 break;
419 case ARG_LONG:
420 if (val) *((long *)field) = (long)strtol (val, &stop_char, 0);
421 break;
422 case ARG_STRING:
423 if (val) {
424 string_field = (char **)field;
425 if (!no_free && *string_field)
426 free (*string_field); /* free previous string */
427 *string_field = gengetopt_strdup (val);
428 }
429 break;
430 default:
431 break;
432 };
433
434 /* check numeric conversion */
435 switch(arg_type) {
436 case ARG_LONG:
437 if (val && !(stop_char && *stop_char == '\0')) {
438 fprintf(stderrstderr, "%s: invalid numeric value: %s\n", package_name, val);
439 return 1; /* failure */
440 }
441 break;
442 default:
443 ;
444 };
445
446 /* store the original value */
447 switch(arg_type) {
448 case ARG_NO:
449 case ARG_FLAG:
450 break;
451 default:
452 if (value && orig_field) {
453 if (no_free) {
454 *orig_field = value;
455 } else {
456 if (*orig_field)
457 free (*orig_field); /* free previous string */
458 *orig_field = gengetopt_strdup (value);
459 }
460 }
461 };
462
463 return 0; /* OK */
464}
465
466
467int
468cmdline_parser_internal (
469 int argc, char **argv, struct gengetopt_args_info *args_info,
470 struct cmdline_parser_params *params, const char *additional_error)
471{
472 int c; /* Character of the parsed option. */
473
474 int error_occurred = 0;
475 struct gengetopt_args_info local_args_info;
476
477 int override;
478 int initialize;
479 int check_required;
480 int check_ambiguity;
481
482 package_name = argv[0];
483
484 /* TODO: Why is this here? It is not used anywhere. */
485 override = params->override;
486 FIX_UNUSED(override)(void) (override);
487
488 initialize = params->initialize;
489 check_required = params->check_required;
490
491 /* TODO: Why is this here? It is not used anywhere. */
492 check_ambiguity = params->check_ambiguity;
493 FIX_UNUSED(check_ambiguity)(void) (check_ambiguity);
494
495 if (initialize)
3
Assuming 'initialize' is 0
4
Taking false branch
496 cmdline_parser_init (args_info);
497
498 cmdline_parser_init (&local_args_info);
499
500 optarg = 0;
501 optind = 0;
502 opterr = params->print_errors;
503 optopt = '?';
504
505 while (1)
5
Loop condition is true. Entering loop body
506 {
507 int option_index = 0;
508
509 static struct option long_options[] = {
510 { "help", 0, NULL((void*)0), 'h' },
511 { "version", 0, NULL((void*)0), 'V' },
512 { "major", 1, NULL((void*)0), 'm' },
513 { "list-mechanisms", 0, NULL((void*)0), 'l' },
514 { "accept-sec-context", 2, NULL((void*)0), 'a' },
515 { "init-sec-context", 1, NULL((void*)0), 'i' },
516 { "server-name", 1, NULL((void*)0), 'n' },
517 { "quiet", 0, NULL((void*)0), 'q' },
518 { 0, 0, 0, 0 }
519 };
520
521 c = getopt_long (argc, argv, "hVm:la::i:n:q", long_options, &option_index);
522
523 if (c == -1) break; /* Exit from `while (1)' loop. */
6
Assuming the condition is false
7
Taking false branch
524
525 switch (c)
8
Control jumps to 'case 113:' at line 615
526 {
527 case 'h': /* Print help and exit. */
528
529
530 if (update_arg( 0 ,
531 0 , &(args_info->help_given),
532 &(local_args_info.help_given), optarg, 0, 0, ARG_NO,
533 check_ambiguity, override, 0, 0,
534 "help", 'h',
535 additional_error))
536 goto failure;
537 cmdline_parser_free (&local_args_info);
538 return 0;
539
540 break;
541 case 'V': /* Print version and exit. */
542
543
544 if (update_arg( 0 ,
545 0 , &(args_info->version_given),
546 &(local_args_info.version_given), optarg, 0, 0, ARG_NO,
547 check_ambiguity, override, 0, 0,
548 "version", 'V',
549 additional_error))
550 goto failure;
551 cmdline_parser_free (&local_args_info);
552 return 0;
553
554 break;
555 case 'm': /* See gss.c for doc string. */
556
557
558 if (update_arg( (void *)&(args_info->major_arg),
559 &(args_info->major_orig), &(args_info->major_given),
560 &(local_args_info.major_given), optarg, 0, 0, ARG_LONG,
561 check_ambiguity, override, 0, 0,
562 "major", 'm',
563 additional_error))
564 goto failure;
565
566 break;
567 case 'l': /* See gss.c for doc string. */
568
569
570 if (update_arg( 0 ,
571 0 , &(args_info->list_mechanisms_given),
572 &(local_args_info.list_mechanisms_given), optarg, 0, 0, ARG_NO,
573 check_ambiguity, override, 0, 0,
574 "list-mechanisms", 'l',
575 additional_error))
576 goto failure;
577
578 break;
579 case 'a': /* See gss.c for doc string. */
580
581
582 if (update_arg( (void *)&(args_info->accept_sec_context_arg),
583 &(args_info->accept_sec_context_orig), &(args_info->accept_sec_context_given),
584 &(local_args_info.accept_sec_context_given), optarg, 0, 0, ARG_STRING,
585 check_ambiguity, override, 0, 0,
586 "accept-sec-context", 'a',
587 additional_error))
588 goto failure;
589
590 break;
591 case 'i': /* See gss.c for doc string. */
592
593
594 if (update_arg( (void *)&(args_info->init_sec_context_arg),
595 &(args_info->init_sec_context_orig), &(args_info->init_sec_context_given),
596 &(local_args_info.init_sec_context_given), optarg, 0, 0, ARG_STRING,
597 check_ambiguity, override, 0, 0,
598 "init-sec-context", 'i',
599 additional_error))
600 goto failure;
601
602 break;
603 case 'n': /* See gss.c for doc string. */
604
605
606 if (update_arg( (void *)&(args_info->server_name_arg),
607 &(args_info->server_name_orig), &(args_info->server_name_given),
608 &(local_args_info.server_name_given), optarg, 0, 0, ARG_STRING,
609 check_ambiguity, override, 0, 0,
610 "server-name", 'n',
611 additional_error))
612 goto failure;
613
614 break;
615 case 'q': /* Silent operation. */
616
617
618 if (update_arg((void *)&(args_info->quiet_flag), 0, &(args_info->quiet_given),
9
Passing value via 1st parameter 'field'
10
Calling 'update_arg'
619 &(local_args_info.quiet_given), optarg, 0, 0, ARG_FLAG,
620 check_ambiguity, override, 1, 0, "quiet", 'q',
621 additional_error))
622 goto failure;
623
624 break;
625
626 case 0: /* Long option with no short option */
627 case '?': /* Invalid option. */
628 /* `getopt_long' already printed an error message. */
629 goto failure;
630
631 default: /* bug: option not considered. */
632 fprintf (stderrstderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE"gss", c, (additional_error ? additional_error : ""));
633 abort ();
634 } /* switch */
635 } /* while */
636
637
638
639 FIX_UNUSED(check_required)(void) (check_required);
640
641 cmdline_parser_release (&local_args_info);
642
643 if ( error_occurred )
644 return (EXIT_FAILURE1);
645
646 return 0;
647
648failure:
649
650 cmdline_parser_release (&local_args_info);
651 return (EXIT_FAILURE1);
652}
653/* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */