forked from eurecom-s3/symcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings.c
62 lines (52 loc) · 1.82 KB
/
strings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// This file is part of SymCC.
//
// SymCC is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// SymCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
// A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// SymCC. If not, see <https://www.gnu.org/licenses/>.
// RUN: %symcc -O2 %s -o %t
// RUN: echo -n test | %t 2>&1 | %filecheck %s
//
// Test the symbolic versions of string functions.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
char buffer[5];
if (read(STDIN_FILENO, buffer, sizeof(buffer) - 1) !=
sizeof(buffer) - 1) {
fprintf(stderr, "Failed to read the input\n");
return -1;
}
buffer[4] = '\0';
// Fully concrete
fputs(strchr("foobar", 'o') != NULL ? "found" : "nope", stderr);
// SIMPLE-NOT: Trying to solve
// QSYM-NOT: SMT
// ANY: found
// Symbolic buffer, concrete char
fputs(strchr(buffer, 'x') != NULL ? "found" : "nope", stderr);
// SIMPLE-COUNT-4: Found diverging input
// QSYM: SMT
// ANY: nope
// Concrete buffer, symbolic char
fputs(strchr("test", buffer[0]) != NULL ? "found" : "nope", stderr);
// SIMPLE: Trying to solve
//
// QSYM's back-off mechanism kicks in because we're generating too many
// queries; let's not check them anymore.
//
// ANY: found
// Symbolic buffer, symbolic char
fputs(strchr(buffer, buffer[1]) != NULL ? "found" : "nope", stderr);
// SIMPLE-COUNT-2: Trying to solve
// ANY: found
return 0;
}