Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
9 int
10 main(int argc, char **argv)
11 {
12 char *curstr;
13 char *nextstr;
14 unsigned int firstval;
15 unsigned int secondval;
16 unsigned int val;
17 unsigned char buf[5];
18 int count;
20 if ( argc != 2 ) {
21 fprintf(stderr, "wrong number of args\n");
22 exit(-1);
23 }
25 curstr = argv[1];
27 nextstr = strchr(curstr, '.');
29 if ( nextstr == NULL ) {
30 fprintf(stderr, "only one component\n");
31 exit(-1);
32 }
34 *nextstr = '\0';
35 firstval = atoi(curstr);
37 curstr = nextstr + 1;
39 nextstr = strchr(curstr, '.');
41 if ( nextstr ) {
42 *nextstr = '\0';
43 }
45 secondval = atoi(curstr);
47 if ( ( firstval < 0 ) || ( firstval > 2 ) ) {
48 fprintf(stderr, "first component out of range\n");
49 exit(-1);
51 }
53 if ( ( secondval < 0 ) || ( secondval > 39 ) ) {
54 fprintf(stderr, "second component out of range\n");
55 exit(-1);
56 }
58 printf("0x%x, ", ( firstval * 40 ) + secondval );
59 while ( nextstr ) {
60 curstr = nextstr + 1;
62 nextstr = strchr(curstr, '.');
64 if ( nextstr ) {
65 *nextstr = '\0';
66 }
68 memset(buf, 0, sizeof(buf));
69 val = atoi(curstr);
70 count = 0;
71 while ( val ) {
72 buf[count] = ( val & 0x7f );
73 val = val >> 7;
74 count++;
75 }
77 while ( count-- ) {
78 if ( count ) {
79 printf("0x%x, ", buf[count] | 0x80 );
80 } else {
81 printf("0x%x, ", buf[count] );
82 }
83 }
84 }
85 printf("\n");
86 return 0;
87 }