Created
January 8, 2021 16:38
-
-
Save GoldsteinE/2581c1442abc837060f5a2ddc72387cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
00000000 75 73 69 6e 67 20 3c 73 74 64 69 6f 2e 68 3e 3a |using <stdio.h>:| | |
00000010 3a 7b 70 72 69 6e 74 66 7d 3b 0a 0a 70 75 62 20 |:{printf};..pub | | |
00000020 74 68 65 6f 72 79 20 69 73 6f 70 65 6e 28 53 6f |theory isopen(So| | |
00000030 63 6b 65 74 2a 73 29 20 2d 3e 20 62 6f 6f 6c 3b |cket*s) -> bool;| | |
00000040 0a 0a 73 74 72 75 63 74 20 53 6f 63 6b 65 74 20 |..struct Socket | | |
00000050 7b 0a 20 20 20 20 69 6e 74 20 6d 75 74 20 66 64 |{. int mut fd| | |
00000060 3b 0a 7d 0a 0a 66 6e 20 6f 70 65 6e 28 53 6f 63 |;.}..fn open(Soc| | |
00000070 6b 65 74 20 6d 75 74 2a 20 73 65 6c 66 29 0a 20 |ket mut* self). | | |
00000080 20 20 20 6d 6f 64 65 6c 20 69 73 6f 70 65 6e 28 | model isopen(| | |
00000090 2a 73 65 6c 66 29 0a 7b 0a 20 20 20 20 73 74 61 |*self).{. sta| | |
000000a0 74 69 63 5f 61 74 74 65 73 74 28 69 73 6f 70 65 |tic_attest(isope| | |
000000b0 6e 28 2a 73 65 6c 66 29 20 3d 3d 20 74 72 75 65 |n(*self) == true| | |
000000c0 29 3b 0a 20 20 20 20 73 74 61 74 69 63 5f 61 73 |);. static_as| | |
000000d0 73 65 72 74 28 69 73 6f 70 65 6e 28 2a 73 65 6c |sert(isopen(*sel| | |
000000e0 66 29 20 3d 3d 20 74 72 75 65 29 3b 0a 20 20 20 |f) == true);. | | |
000000f0 20 73 65 6c 66 2d 3e 66 64 20 3d 20 32 3b 0a 7d | self->fd = 2;.}| | |
00000100 0a 0a 66 6e 20 72 65 61 64 28 53 6f 63 6b 65 74 |..fn read(Socket| | |
00000110 20 6d 75 74 2a 20 73 65 6c 66 29 0a 20 20 20 20 | mut* self). | | |
00000120 77 68 65 72 65 20 69 73 6f 70 65 6e 28 2a 73 65 |where isopen(*se| | |
00000130 6c 66 29 0a 20 20 20 20 6d 6f 64 65 6c 20 69 73 |lf). model is| | |
00000140 6f 70 65 6e 28 2a 73 65 6c 66 29 0a 7b 0a 20 20 |open(*self).{. | | |
00000150 20 20 69 6e 74 20 62 6c 61 20 3d 20 73 65 6c 66 | int bla = self| | |
00000160 2d 3e 66 64 3b 0a 7d 0a 0a 66 6e 20 63 6c 6f 73 |->fd;.}..fn clos| | |
00000170 65 28 53 6f 63 6b 65 74 20 6d 75 74 2a 20 73 65 |e(Socket mut* se| | |
00000180 6c 66 29 0a 20 20 20 20 77 68 65 72 65 20 69 73 |lf). where is| | |
00000190 6f 70 65 6e 28 2a 73 65 6c 66 29 0a 20 20 20 20 |open(*self). | | |
000001a0 6d 6f 64 65 6c 20 21 69 73 6f 70 65 6e 28 2a 73 |model !isopen(*s| | |
000001b0 65 6c 66 29 0a 7b 0a 20 20 20 20 2f 2f 63 6f 6e |elf).{. //con| | |
000001c0 76 69 6e 63 65 20 74 68 65 20 73 79 6d 62 6f 6c |vince the symbol| | |
000001d0 69 63 20 65 78 65 63 75 74 6f 72 20 74 68 61 74 |ic executor that| | |
000001e0 20 77 65 20 64 69 64 20 73 6f 6d 65 74 68 69 6e | we did somethin| | |
000001f0 67 2c 20 73 6f 20 77 65 20 63 61 6e 20 68 61 76 |g, so we can hav| | |
00000200 65 20 6e 65 77 20 63 6f 6e 73 74 72 61 69 6e 74 |e new constraint| | |
00000210 73 0a 20 20 20 20 2a 73 65 6c 66 20 3d 20 53 6f |s. *self = So| | |
00000220 63 6b 65 74 7b 66 64 3a 20 30 7d 3b 0a 20 20 20 |cket{fd: 0};. | | |
00000230 20 73 74 61 74 69 63 5f 61 74 74 65 73 74 28 69 | static_attest(i| | |
00000240 73 6f 70 65 6e 28 2a 73 65 6c 66 29 20 3d 3d 20 |sopen(*self) == | | |
00000250 66 61 6c 73 65 29 3b 0a 7d 0a 0a 65 78 70 6f 72 |false);.}..expor| | |
00000260 74 20 66 6e 20 6d 61 69 6e 28 29 20 2d 3e 20 69 |t fn main() -> i| | |
00000270 6e 74 20 7b 0a 0a 20 20 20 20 53 6f 63 6b 65 74 |nt {.. Socket| | |
00000280 20 6d 75 74 20 73 6f 63 6b 20 3d 20 7b 30 7d 3b | mut sock = {0};| | |
00000290 0a 20 20 20 20 6f 70 65 6e 28 26 73 6f 63 6b 29 |. open(&sock)| | |
000002a0 3b 0a 20 20 20 20 72 65 61 64 28 26 73 6f 63 6b |;. read(&sock| | |
000002b0 29 3b 0a 20 20 20 20 63 6c 6f 73 65 28 26 73 6f |);. close(&so| | |
000002c0 63 6b 29 3b 0a 0a 20 20 20 20 70 72 69 6e 74 66 |ck);.. printf| | |
000002d0 28 22 68 65 6c 6c 6f 20 74 61 69 6e 74 5c 6e 22 |("hello taint\n"| | |
000002e0 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b |);. return 0;| | |
000002f0 0a 7d 0a |.}.| | |
000002f3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment