annotate uptools/sms-pdu-decode/sms-pdu-decode.c @ 1011:6d9b10633f10

etmsync Pirelli IMEI retrieval: fix poor use of printf() Bug reported by Vadim Yanitskiy <fixeria@osmocom.org>: the construct where a static-allocated string was passed to printf() without any format arguments causes newer compilers to report a security problem. Given that formatted output is not needed here, just fixed string output, change printf() to fputs(), and direct the error message to stderr while at it.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 23 May 2024 17:29:57 +0000
parents 7da1ac6431dc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
337
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <ctype.h>
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdio.h>
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <stdlib.h>
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <string.h>
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <strings.h>
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <unistd.h>
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
598
9f7a263ad7f0 sms-pdu-decode split in preparation for pcm-sms-decode addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 468
diff changeset
9 extern int ascii_ext_mode, global_hexdump_mode;
9f7a263ad7f0 sms-pdu-decode split in preparation for pcm-sms-decode addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 468
diff changeset
10 extern u_char pdu[176];
9f7a263ad7f0 sms-pdu-decode split in preparation for pcm-sms-decode addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 468
diff changeset
11 extern unsigned pdu_length;
337
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
598
9f7a263ad7f0 sms-pdu-decode split in preparation for pcm-sms-decode addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 468
diff changeset
13 static char *infname;
9f7a263ad7f0 sms-pdu-decode split in preparation for pcm-sms-decode addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 468
diff changeset
14 static FILE *inf;
961
7da1ac6431dc sms-pdu-decode utility: add -n option for TPDUs without SC address
Mychaela Falconia <falcon@freecalypso.org>
parents: 960
diff changeset
15 static int keep_raw_pdu, pdu_has_sca = 1;
337
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
598
9f7a263ad7f0 sms-pdu-decode split in preparation for pcm-sms-decode addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 468
diff changeset
17 static char input_line[1024];
337
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
598
9f7a263ad7f0 sms-pdu-decode split in preparation for pcm-sms-decode addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 468
diff changeset
19 static
337
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 process_cmdline(argc, argv)
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char **argv;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int c;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern int optind;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
961
7da1ac6431dc sms-pdu-decode utility: add -n option for TPDUs without SC address
Mychaela Falconia <falcon@freecalypso.org>
parents: 960
diff changeset
26 while ((c = getopt(argc, argv, "ehnpu")) != EOF)
337
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 switch (c) {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 case 'e':
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 ascii_ext_mode = 1;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 continue;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 case 'h':
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 global_hexdump_mode = 1;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 continue;
961
7da1ac6431dc sms-pdu-decode utility: add -n option for TPDUs without SC address
Mychaela Falconia <falcon@freecalypso.org>
parents: 960
diff changeset
34 case 'n':
7da1ac6431dc sms-pdu-decode utility: add -n option for TPDUs without SC address
Mychaela Falconia <falcon@freecalypso.org>
parents: 960
diff changeset
35 pdu_has_sca = 0;
7da1ac6431dc sms-pdu-decode utility: add -n option for TPDUs without SC address
Mychaela Falconia <falcon@freecalypso.org>
parents: 960
diff changeset
36 continue;
386
bae0fd7285dd sms-pdu-decode: added -p option to keep the raw PDUs in the output
Mychaela Falconia <falcon@freecalypso.org>
parents: 339
diff changeset
37 case 'p':
bae0fd7285dd sms-pdu-decode: added -p option to keep the raw PDUs in the output
Mychaela Falconia <falcon@freecalypso.org>
parents: 339
diff changeset
38 keep_raw_pdu = 1;
bae0fd7285dd sms-pdu-decode: added -p option to keep the raw PDUs in the output
Mychaela Falconia <falcon@freecalypso.org>
parents: 339
diff changeset
39 continue;
337
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 case 'u':
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 ascii_ext_mode = 2;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 continue;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 default:
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 fprintf(stderr, "%s: invalid option\n", argv[0]);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (argc > optind)
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 infname = argv[optind];
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
598
9f7a263ad7f0 sms-pdu-decode split in preparation for pcm-sms-decode addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 468
diff changeset
51 static
337
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 swallow_empty_line()
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 int c;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 c = getc(inf);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (c != '\n')
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 ungetc(c, inf);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 main(argc, argv)
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 char **argv;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 char *nl;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 int lineno, cc;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 process_cmdline(argc, argv);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (infname) {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 inf = fopen(infname, "r");
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!inf) {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 perror(infname);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 exit(1);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 } else {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 inf = stdin;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 infname = "stdin";
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 for (lineno = 1; fgets(input_line, sizeof input_line, inf); lineno++) {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 nl = index(input_line, '\n');
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (!nl) {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 fprintf(stderr, "%s line %d: no newline\n",
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 infname, lineno);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 exit(1);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 *nl = '\0';
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 cc = decode_hex_line(input_line, pdu, sizeof pdu);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (cc <= 0) {
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 puts(input_line);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 continue;
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 pdu_length = cc;
386
bae0fd7285dd sms-pdu-decode: added -p option to keep the raw PDUs in the output
Mychaela Falconia <falcon@freecalypso.org>
parents: 339
diff changeset
92 if (keep_raw_pdu)
bae0fd7285dd sms-pdu-decode: added -p option to keep the raw PDUs in the output
Mychaela Falconia <falcon@freecalypso.org>
parents: 339
diff changeset
93 printf("%s\n\n", input_line);
961
7da1ac6431dc sms-pdu-decode utility: add -n option for TPDUs without SC address
Mychaela Falconia <falcon@freecalypso.org>
parents: 960
diff changeset
94 process_pdu(1, pdu_has_sca);
337
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 putchar('\n');
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 swallow_empty_line();
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 exit(0);
560af437a429 sms-pdu-decode main program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }