DOC PREVIEW
CMU CS 15441 - Exam

This preview shows page 1-2-3-4-5 out of 14 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14– 1 –15-441Exam FeedbackMar. 8, 2006TopicsTopics•reading list•finger clientLxx_Exam15-441Computer Networking– 1 –15-441SynchronizationTextbookTextbook•Looking Backward / Forward•Section 3.3 (ATM)•Section 4.4 (Multicast), 4.5 (MPLS)•Section 9.1 (DNS)•The TCP Adventure•Section 2.5 (Reliable Transfer)•Chapter 5: Transport (ok if you read 5.3 lightly)•Chapter 6: Congestion Control– 1 –15-441OutlineThe finger questionThe finger questionMythsMyths– 1 –15-441fingerProblemProblem•Here is a finger client•Connect to TCP port 79•send username•print out server's response•Say what's wrong•This was a “target-rich environment”– 1 –15-441finger.cint main(int argc, char *argv[]){ int s, len; struct sockaddr_in server; struct hostent *hp; char c, buf[8192]; if (argc != 3) { fprintf(stderr, "usage: %s host user\n", argv[0]); exit(9); } server.sin_family = AF_INET; server.sin_port = 79; server.sin_addr.s_addr = gethostbyname(argv[1]); s = socket(AF_INET, SOCK_DGRAM, 0); bind(s, (struct sockaddr *) &server, sizeof (server)); write(s, argv[2], strlen(argv[2])); write(s, "\r\n", 2); if ((len = read(s, buf, sizeof (buf))) > 0) write(1, buf, len); exit(0);}– 1 –15-441finger.cint main(int argc, char *argv[]){ int s, len; struct sockaddr_in server; struct hostent *hp; char c, buf[8192]; if (argc != 3) { fprintf(stderr, "usage: %s host user\n", argv[0]); exit(9); } server.sin_family = AF_INET; server.sin_port = 79; server.sin_addr.s_addr = gethostbyname(argv[1]); s = socket(AF_INET, SOCK_DGRAM, 0); bind(s, (struct sockaddr *) &server, sizeof (server)); write(s, argv[2], strlen(argv[2])); write(s, "\r\n", 2); if ((len = read(s, buf, sizeof (buf))) > 0) write(1, buf, len); exit(0);}– 1 –15-441finger.c server.sin_family = AF_INET; server.sin_port = 79; server.sin_addr.s_addr = gethostbyname(argv[1]); s = socket(AF_INET, SOCK_DGRAM, 0); bind(s, (struct sockaddr *) &server, sizeof (server)); write(s, argv[2], strlen(argv[2])); write(s, "\r\n", 2); if ((len = read(s, buf, sizeof (buf))) > 0) write(1, buf, len);Pretty much all of this is wrongPretty much all of this is wrong– 1 –15-441finger.c server.sin_family = AF_INET; server.sin_port = 79; server.sin_addr.s_addr = gethostbyname(argv[1]); s = socket(AF_INET, SOCK_DGRAM, 0); bind(s, (struct sockaddr *) &server, sizeof (server)); write(s, argv[2], strlen(argv[2])); write(s, "\r\n", 2); if ((len = read(s, buf, sizeof (buf))) > 0) write(1, buf, len);– 1 –15-441finger.cBadBad server.sin_port = 79;GoodGood server.sin_port = htons(79);BadBad server.sin_addr.s_addr = gethostbyname(argv[1]);GoodGood hp = gethostbyname(argv[1]); memmove(&server.sin_addr, hp->h_addr, hp->h_length);– 1 –15-441finger.cBadBad s = socket(AF_INET, SOCK_DGRAM, 0);GoodGood s = socket(AF_INET, SOCK_STREAM, 0);BadBad bind(s, (struct sockaddr *) &server, sizeof (server));GoodGood connect(s, (struct sockaddr *) &server, sizeof (server));– 1 –15-441finger.cBadBad if ((len = read(s, buf, sizeof (buf))) > 0) write(1, buf, len);GoodGood while ((len = read(s, buf, sizeof (buf))) > 0) write(1, buf, len);– 1 –15-441MythsMust close sockets before exit()Must close sockets before exit()•If that were true we'd all be in big trouble!•exit()'s job is to clean up process resourcessizeof(buf) == 4•That's like a real problem...•sizeof (pretty much any pointer) == 4 (on many machines)•sizeof (array) is, well, the size of the array, in bytes»“Doesn't work” for array parameters to a function»They're actually pointers (call by reference), not arrayswrite(stdout, ...)•That's mixing metaphors – file descriptors aren't stdio streams•You could write write(fileno(stdout), ...)•But if fileno(stdout) != 1 something very very odd is going on– 1 –15-441MythsCannot use write() and read() on UDP socketsCannot use write() and read() on UDP sockets•Sure you can!read() doesn't block to wait for server responseread() doesn't block to wait for server response•Yes, it does!strings must be converted to network byte orderstrings must be converted to network byte order•The network byte order for strings is:•Send the first byte, then the second, then the third...•“Byte order” is a problem when you have N-byte chunks•Integer is a 4-byte chunk•You could have a string byte-order problem with Unicode•Out of scope– 1 –15-441MythsBuffer overflows!Buffer overflows! write(s, argv[2], strlen(argv[2]));•We aren't putting anything into a buffer!•Certainly not one of fixed size, without a length check•The kernel might be putting these bytes in a buffer•If the kernel does that unsafely we have problems beyond finger•The finger server might carelessly handle this request•But we can't save it from other people triggering that read(s, buf, sizeof (buf))•Ok, this is a buffer•But we are very carefully not overflowing it!•If the kernel puts more than sizeof (buf) bytes into buf then we have problems bigger than fingerNot all buffer uses are buffer overflows!Not all buffer uses are buffer


View Full Document

CMU CS 15441 - Exam

Documents in this Course
lecture

lecture

34 pages

lecture

lecture

38 pages

lecture

lecture

18 pages

lecture

lecture

28 pages

lecture

lecture

11 pages

Lecture

Lecture

64 pages

lecture

lecture

10 pages

lecture

lecture

19 pages

Lecture 6

Lecture 6

43 pages

lecture

lecture

38 pages

Debugging

Debugging

23 pages

lecture

lecture

60 pages

review

review

27 pages

lecture

lecture

12 pages

The Web

The Web

28 pages

Lecture

Lecture

40 pages

lecture

lecture

42 pages

lecture

lecture

9 pages

lecture

lecture

10 pages

lecture

lecture

49 pages

lecture

lecture

26 pages

Project

Project

5 pages

lecture

lecture

40 pages

lecture

lecture

9 pages

lecture

lecture

41 pages

lecture

lecture

32 pages

lecture

lecture

36 pages

lecture

lecture

34 pages

lecture

lecture

45 pages

lecture

lecture

26 pages

lecture

lecture

6 pages

lecture

lecture

51 pages

Project

Project

16 pages

lecture

lecture

44 pages

lecture

lecture

13 pages

lecture

lecture

42 pages

lecture

lecture

36 pages

Project

Project

13 pages

Project

Project

33 pages

lecture

lecture

43 pages

lecture

lecture

49 pages

Load more
Download Exam
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exam and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exam 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?