annotate uptools/libcoding/gsm7_decode_qstring.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 f023a1c187a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
799
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements a function for decoding GSM7 strings
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * to ASCII with output to a stdio file; it is an implementation
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * of lossless conversion per our SIM-data-formats spec
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * in freecalypso-docs.
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/types.h>
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 static char basic_table[128] = {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 '@', 0, '$', 0, 0, 0, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 0, 0, 'n'|0x80, 0, 0, 'r'|0x80, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 0, '_', 0, 0, 0, 0, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 0, 0, 0, 0, 0, 0, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 ' ', '!', '"'|0x80, '#', 0, '%', '&', 0x27,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 '(', ')', '*', '+', ',', '-', '.', '/',
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 '0', '1', '2', '3', '4', '5', '6', '7',
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 '8', '9', ':', ';', '<', '=', '>', '?',
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 'X', 'Y', 'Z', 0, 0, 0, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 'x', 'y', 'z', 0, 0, 0, 0, 0
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 };
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static char escape_table[128] = {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 0, 0, 0, 0, '^', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 0, 0, 0, 0, 0, 0, 0, 0, '{', '}', 0, 0, 0, 0, 0, '\\'|0x80,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '[', '~', ']', 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 '|', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 0, 0, 0, 0, 0,'E'|0x80,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 };
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 void
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 print_gsm7_string_to_file(data, nbytes, outf)
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 u_char *data;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 unsigned nbytes;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 FILE *outf;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 u_char *dp, *endp;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 int b, c;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 dp = data;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 endp = data + nbytes;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 putc('"', outf);
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 while (dp < endp) {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 b = *dp++;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (b == 0x1B) {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (dp >= endp || *dp == 0x1B || *dp == '\n' ||
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 *dp == '\r') {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 putc('\\', outf);
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 putc('e', outf);
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 continue;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 b = *dp++;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 c = escape_table[b];
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (!c) {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 fprintf(outf, "\\e\\%02X", b);
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 continue;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 } else {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 c = basic_table[b];
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!c) {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 fprintf(outf, "\\%02X", b);
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 continue;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (c & 0x80) {
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 putc('\\', outf);
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 c &= 0x7F;
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 putc(c, outf);
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 putc('"', outf);
f023a1c187a9 uptools/libcoding: import print_gsm7_string_to_file()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }