]> diplodocus.org Git - nmh/blob - sbr/unquote.c
Fix invalid pointer arithmetic.
[nmh] / sbr / unquote.c
1 /* unquote.c -- Handle quote removal and quoted-pair strings on
2 * RFC 2822-5322 atoms.
3 *
4 * This code is Copyright (c) 2013, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
7 */
8
9 #include <h/mh.h>
10 #include "unquote.h"
11
12 /*
13 * Remove quotes (and handle escape strings) from RFC 5322 quoted-strings.
14 *
15 * Since we never add characters to the string, the output buffer is assumed
16 * to have at least as many characters as the input string.
17 *
18 */
19
20 void
21 unquote_string(const char *input, char *output)
22 {
23 int n = 0; /* n is the position in the input buffer */
24 int m = 0; /* m is the position in the output buffer */
25
26 while ( input[n] != '\0') {
27 switch ( input[n] ) {
28 case '\\':
29 n++;
30 if ( input[n] != '\0')
31 output[m++] = input[n++];
32 break;
33 case '"':
34 n++;
35 break;
36 default:
37 output[m++] = input[n++];
38 break;
39 }
40 }
41
42 output[m] = '\0';
43 }