diff options
author | Damien Miller <djm@mindrot.org> | 2013-02-20 21:13:27 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2013-02-20 21:13:27 +1100 |
commit | 283e575a7db49addd1cffe1a7cb6c5503a98e027 (patch) | |
tree | 033746cb9365ef7cd9a98491d77c1ad9fe31def2 /regress/modpipe.c | |
parent | c31db8cd6e301c8d4024cb9250e3178d13d1be44 (diff) |
- djm@cvs.openbsd.org 2013/02/20 08:27:50
[regress/integrity.sh regress/modpipe.c]
Add an option to modpipe that warns if the modification offset it not
reached in it's stream and turn it on for t-integrity. This should catch
cases where the session is not fuzzed for being too short (cf. my last
"oops" commit)
Diffstat (limited to 'regress/modpipe.c')
-rwxr-xr-x | regress/modpipe.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/regress/modpipe.c b/regress/modpipe.c index 1d4229885..dca927603 100755 --- a/regress/modpipe.c +++ b/regress/modpipe.c | |||
@@ -14,7 +14,7 @@ | |||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /* $Id: modpipe.c,v 1.3 2013/02/20 03:01:52 tim Exp $ */ | 17 | /* $Id: modpipe.c,v 1.4 2013/02/20 10:13:29 djm Exp $ */ |
18 | 18 | ||
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <unistd.h> | 20 | #include <unistd.h> |
@@ -56,7 +56,7 @@ errx(int r, const char *fmt, ...) | |||
56 | static void | 56 | static void |
57 | usage(void) | 57 | usage(void) |
58 | { | 58 | { |
59 | fprintf(stderr, "Usage: modpipe [-m modspec ...] < in > out\n"); | 59 | fprintf(stderr, "Usage: modpipe -w [-m modspec ...] < in > out\n"); |
60 | fprintf(stderr, "modspec is one of:\n"); | 60 | fprintf(stderr, "modspec is one of:\n"); |
61 | fprintf(stderr, " xor:offset:value - XOR \"value\" at \"offset\"\n"); | 61 | fprintf(stderr, " xor:offset:value - XOR \"value\" at \"offset\"\n"); |
62 | fprintf(stderr, " andor:offset:val1:val2 - AND \"val1\" then OR \"val2\" at \"offset\"\n"); | 62 | fprintf(stderr, " andor:offset:val1:val2 - AND \"val1\" then OR \"val2\" at \"offset\"\n"); |
@@ -100,15 +100,18 @@ main(int argc, char **argv) | |||
100 | size_t total; | 100 | size_t total; |
101 | ssize_t r, s, o; | 101 | ssize_t r, s, o; |
102 | struct modification mods[MAX_MODIFICATIONS]; | 102 | struct modification mods[MAX_MODIFICATIONS]; |
103 | u_int i, num_mods = 0; | 103 | u_int i, wflag = 0, num_mods = 0; |
104 | 104 | ||
105 | while ((ch = getopt(argc, argv, "m:")) != -1) { | 105 | while ((ch = getopt(argc, argv, "wm:")) != -1) { |
106 | switch (ch) { | 106 | switch (ch) { |
107 | case 'm': | 107 | case 'm': |
108 | if (num_mods >= MAX_MODIFICATIONS) | 108 | if (num_mods >= MAX_MODIFICATIONS) |
109 | errx(1, "Too many modifications"); | 109 | errx(1, "Too many modifications"); |
110 | parse_modification(optarg, &(mods[num_mods++])); | 110 | parse_modification(optarg, &(mods[num_mods++])); |
111 | break; | 111 | break; |
112 | case 'w': | ||
113 | wflag = 1; | ||
114 | break; | ||
112 | default: | 115 | default: |
113 | usage(); | 116 | usage(); |
114 | /* NOTREACHED */ | 117 | /* NOTREACHED */ |
@@ -117,7 +120,7 @@ main(int argc, char **argv) | |||
117 | for (total = 0;;) { | 120 | for (total = 0;;) { |
118 | r = s = read(STDIN_FILENO, buf, sizeof(buf)); | 121 | r = s = read(STDIN_FILENO, buf, sizeof(buf)); |
119 | if (r == 0) | 122 | if (r == 0) |
120 | return 0; | 123 | break; |
121 | if (r < 0) { | 124 | if (r < 0) { |
122 | if (errno == EAGAIN || errno == EINTR) | 125 | if (errno == EAGAIN || errno == EINTR) |
123 | continue; | 126 | continue; |
@@ -140,7 +143,7 @@ main(int argc, char **argv) | |||
140 | for (o = 0; o < s; o += r) { | 143 | for (o = 0; o < s; o += r) { |
141 | r = write(STDOUT_FILENO, buf, s - o); | 144 | r = write(STDOUT_FILENO, buf, s - o); |
142 | if (r == 0) | 145 | if (r == 0) |
143 | return 0; | 146 | break; |
144 | if (r < 0) { | 147 | if (r < 0) { |
145 | if (errno == EAGAIN || errno == EINTR) | 148 | if (errno == EAGAIN || errno == EINTR) |
146 | continue; | 149 | continue; |
@@ -149,5 +152,13 @@ main(int argc, char **argv) | |||
149 | } | 152 | } |
150 | total += s; | 153 | total += s; |
151 | } | 154 | } |
152 | return 0; | 155 | /* Warn if modifications not reached in input stream */ |
156 | r = 0; | ||
157 | for (i = 0; wflag && i < num_mods; i++) { | ||
158 | if (mods[i].offset < total) | ||
159 | continue; | ||
160 | r = 1; | ||
161 | fprintf(stderr, "modpipe: warning - mod %u not reached\n", i); | ||
162 | } | ||
163 | return r; | ||
153 | } | 164 | } |