comparison lib-src/gnuslib.c @ 3556:2161ac78b41e

[xemacs-hg @ 2006-08-11 17:37:17 by james] Prevent potential buffer overflows. Also enable use of shutdown() on linux. <m37j1jez4n.fsf@jerrypc.cs.usu.edu>
author james
date Fri, 11 Aug 2006 17:37:18 +0000
parents b39c14581166
children e6508b64ee08 061f4f90f874
comparison
equal deleted inserted replaced
3555:db783273b399 3556:2161ac78b41e
407 int add_newline = 1; 407 int add_newline = 1;
408 int length; 408 int length;
409 409
410 send_string(s,EOT_STR); /* make sure server gets string */ 410 send_string(s,EOT_STR); /* make sure server gets string */
411 411
412 #if !defined (linux) && !defined (_SCO_DS) 412 #ifndef _SCO_DS
413 /* 413 /*
414 * shutdown is completely hozed under linux. If s is a unix domain socket, 414 * There used to be a comment here complaining about ancient Linux
415 * you'll get EOPNOTSUPP back from it. If s is an internet socket, you get 415 * versions. It is no longer relevant. I don't know why _SCO_DS is
416 * a broken pipe when you try to read a bit later. The latter 416 * verboten here, as the original comment did not say.
417 * problem is fixed for linux versions >= 1.1.46, but the problem
418 * with unix sockets persists. Sigh.
419 */ 417 */
420 418
421 if (shutdown(s,1) == -1) { 419 if (shutdown(s,1) == -1) {
422 perror(progname); 420 perror(progname);
423 fprintf(stderr, "%s: unable to shutdown socket\n",progname); 421 fprintf(stderr, "%s: unable to shutdown socket\n",progname);
432 add_newline = (buffer[length-1] != '\n'); 430 add_newline = (buffer[length-1] != '\n');
433 }; /* while */ 431 }; /* while */
434 #else 432 #else
435 while ((length = read(s,buffer,GSERV_BUFSZ)) > 0 || 433 while ((length = read(s,buffer,GSERV_BUFSZ)) > 0 ||
436 (length == -1 && errno == EINTR)) { 434 (length == -1 && errno == EINTR)) {
437 if (length) { 435 if (length > 0) {
438 buffer[length] = '\0'; 436 buffer[length] = '\0';
439 if (echo) { 437 if (echo) {
440 fputs(buffer,stdout); 438 fputs(buffer,stdout);
441 add_newline = (buffer[length-1] != '\n'); 439 add_newline = (buffer[length-1] != '\n');
442 }; /* if */ 440 }; /* if */