patch-Wnn_uum_jhlp_c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. $OpenBSD: patch-Wnn_uum_jhlp_c,v 1.7 2017/04/29 14:31:40 espie Exp $
  2. --- Wnn/uum/jhlp.c.orig
  3. +++ Wnn/uum/jhlp.c
  4. @@ -49,7 +49,11 @@ static char *rcs_id = "$Id: jhlp.c,v 1.40 1994/08/19 0
  5. /* Version 4.0
  6. */
  7. #include <stdio.h>
  8. +#include <stdlib.h>
  9. #include <signal.h>
  10. +#include <string.h>
  11. +#include <unistd.h>
  12. +#include <sys/stat.h>
  13. #include "jllib.h"
  14. #include "commonhd.h"
  15. #include "sdefine.h"
  16. @@ -61,7 +65,7 @@ static char *rcs_id = "$Id: jhlp.c,v 1.40 1994/08/19 0
  17. #ifndef SYSVR2
  18. #include <fcntl.h>
  19. #endif /* !SYSVR2 */
  20. -#include <sys/errno.h>
  21. +#include <errno.h>
  22. #include <pwd.h>
  23. #include <sys/time.h>
  24. #ifdef UX386
  25. @@ -80,6 +84,9 @@ struct passwd *getpwuid();
  26. jmp_buf kk_env;
  27. +#if (defined(__unix__) || defined(unix)) && !defined(USG)
  28. +#include <sys/param.h>
  29. +#endif
  30. #ifdef SYSVR2
  31. # include <sys/param.h>
  32. #endif /* SYSVR2 */
  33. @@ -88,9 +95,21 @@ jmp_buf kk_env;
  34. # include <sys/wait.h>
  35. #endif /* HAVE_WAIT3 */
  36. +#if defined(__OpenBSD__)
  37. +#define USE_TERMIOS
  38. +#else
  39. #ifdef BSD42
  40. +#define USE_SGTTY
  41. +#endif
  42. +#endif
  43. +
  44. +#ifdef linux
  45. +#define USE_TERMIOS
  46. +#endif
  47. +
  48. +#ifdef USE_SGTTY
  49. # include <sgtty.h>
  50. -#endif /* BSD42 */
  51. +#endif
  52. #ifdef SYSVR2
  53. #ifdef TERMINFO
  54. @@ -101,7 +120,7 @@ jmp_buf kk_env;
  55. #if defined(SVR4) || defined(hpux) || defined(sgi)
  56. #include <sys/termio.h>
  57. #endif
  58. -#ifdef linux
  59. +#ifdef USE_TERMIOS
  60. #include <termios.h>
  61. #endif
  62. @@ -133,11 +152,10 @@ char *cmdnm = "csh"; /* char *cmdnm = "csh"; */
  63. int child_id;
  64. char *prog;
  65. -extern int errno;
  66. extern char *optarg;
  67. extern int optind;
  68. -extern char *ttyname(), *malloc(), *getenv();
  69. +extern char *ttyname();
  70. static void save_signals();
  71. static void restore_signals();
  72. @@ -148,7 +166,7 @@ static void do_end(), open_pty(), open_ttyp(), do_main
  73. change_size(), default_usage();
  74. /** メイン */
  75. -void
  76. +int
  77. main(argc, argv)
  78. int argc;
  79. char **argv;
  80. @@ -166,14 +184,14 @@ char **argv;
  81. flow_control = FLOW_CONTROL;
  82. code_trans = default_code_trans;
  83. - strcpy(username, getpwuid(getuid())->pw_name);
  84. + strlcpy(username, getpwuid(getuid())->pw_name, PATHNAMELEN);
  85. if((name = getenv(WNN_USERNAME_ENV)) != NULL){
  86. - strcpy(username, name);
  87. + strlcpy(username, name, PATHNAMELEN);
  88. }
  89. for (i = 1; i < argc;) {
  90. if (!strcmp(argv[i++], "-L")) {
  91. if (i >= argc || argv[i][0] == '-') default_usage();
  92. - strcpy(lang_dir, argv[i++]);
  93. + strlcpy(lang_dir, argv[i++], 32);
  94. for (;i < argc; i++) {
  95. argv[i - 2] = argv[i];
  96. }
  97. @@ -185,12 +203,7 @@ char **argv;
  98. if(*lang_dir == '\0') {
  99. if ((p = getenv("LANG")) != NULL) {
  100. - if (strlen(p) >= 4) {
  101. - strncpy(lang_dir, p, 5);
  102. - lang_dir[5] = '\0';
  103. - } else {
  104. - strcpy(lang_dir, p);
  105. - }
  106. + strlcpy(lang_dir, p, 5);
  107. }
  108. }
  109. for (f = function_db; *lang_dir && f && f->lang; f++) {
  110. @@ -233,8 +246,8 @@ char **argv;
  111. server_env = WNN_DEF_SERVER_ENV;
  112. }
  113. if(name = getenv(server_env)) {
  114. - strcpy(def_servername, name);
  115. - strcpy(def_reverse_servername, name);
  116. + strlcpy(def_servername, name, PATHNAMELEN);
  117. + strlcpy(def_reverse_servername, name, PATHNAMELEN);
  118. }
  119. }
  120. @@ -244,7 +257,7 @@ char **argv;
  121. }
  122. if((p = getenv(WNN_COUNTDOWN_ENV)) == NULL) {
  123. - setenv(WNN_COUNTDOWN_ENV,"0");
  124. + setenv(WNN_COUNTDOWN_ENV,"0", 1);
  125. } else if (atoi(p) <= 0) {
  126. puteustring(MSG_GET(4), stdout);
  127. /*
  128. @@ -253,7 +266,7 @@ char **argv;
  129. exit(126);
  130. } else {
  131. sprintf(p,"%d",atoi(p) - 1);
  132. - setenv(WNN_COUNTDOWN_ENV,p);
  133. + setenv(WNN_COUNTDOWN_ENV,p, 1);
  134. }
  135. if((tname = getenv("TERM")) == NULL) {
  136. @@ -263,9 +276,11 @@ char **argv;
  137. #if defined(BSD42) && !defined(DGUX)
  138. +#if !(defined(BSD) && (BSD >= 199306))
  139. if (saveutmp() < 0) {
  140. puts("Can't save utmp\n");
  141. }
  142. +#endif
  143. #endif /* BSD42 */
  144. @@ -312,7 +327,7 @@ char **argv;
  145. #endif /* TERMCAP */
  146. open_pty();
  147. -#ifndef linux
  148. +#if !(defined(linux) || defined(__OpenBSD__))
  149. open_ttyp();
  150. #endif
  151. exec_cmd(argv);
  152. @@ -492,7 +507,7 @@ static int do_X_opt()
  153. static int do_k_opt()
  154. {
  155. - strcpy(uumkey_name_in_uumrc, optarg);
  156. + strlcpy(uumkey_name_in_uumrc, optarg, PATHNAMELEN);
  157. if (*uumkey_name_in_uumrc == '\0') {
  158. return -1;
  159. }
  160. @@ -502,7 +517,7 @@ static int do_k_opt()
  161. static int do_c_opt()
  162. {
  163. - strcpy(convkey_name_in_uumrc, optarg);
  164. + strlcpy(convkey_name_in_uumrc, optarg, PATHNAMELEN);
  165. if (*convkey_name_in_uumrc == '\0') {
  166. return -1;
  167. }
  168. @@ -512,7 +527,7 @@ static int do_c_opt()
  169. static int do_r_opt()
  170. {
  171. - strcpy(rkfile_name_in_uumrc, optarg);
  172. + strlcpy(rkfile_name_in_uumrc, optarg, PATHNAMELEN);
  173. if (*rkfile_name_in_uumrc == '\0') {
  174. return -1;
  175. }
  176. @@ -528,8 +543,8 @@ static int do_l_opt()
  177. static int do_D_opt()
  178. {
  179. - strcpy(def_servername, optarg);
  180. - strcpy(def_reverse_servername, optarg);
  181. + strlcpy(def_servername, optarg, PATHNAMELEN);
  182. + strlcpy(def_reverse_servername, optarg, PATHNAMELEN);
  183. if (*def_servername == '\0') {
  184. return -1;
  185. }
  186. @@ -538,7 +553,7 @@ static int do_D_opt()
  187. static int do_n_opt()
  188. {
  189. - strcpy(username, optarg);
  190. + strlcpy(username, optarg, PATHNAMELEN);
  191. if (*username == '\0') {
  192. return -1;
  193. }
  194. @@ -581,14 +596,14 @@ char **argv;
  195. #endif /* SYSVR2 */
  196. extern char *index();
  197. - strcpy(ostr, default_getoptstr);
  198. - strcat(ostr, lang_db->getoptstr);
  199. + strlcpy(ostr, default_getoptstr, sizeof(ostr));
  200. + strlcat(ostr, lang_db->getoptstr, sizeof(ostr));
  201. while ((c = getopt(argc, argv, ostr)) != EOF) {
  202. if (!(p = index(default_ostr, c)) || (*do_opt[p - default_ostr])() < 0) {
  203. if (!(p = index(lang_db->ostr, c)) ||
  204. (*lang_db->do_opt[p - lang_db->ostr])() < 0) {
  205. - strcpy(ostr, default_ostr);
  206. - strcat(ostr, lang_db->ostr);
  207. + strlcpy(ostr, default_ostr, sizeof(ostr));
  208. + strlcat(ostr, lang_db->ostr, sizeof(ostr));
  209. usage(ostr);
  210. }
  211. }
  212. @@ -600,7 +615,7 @@ char **argv;
  213. /** tty に対する ioctl のセット */
  214. -#ifdef BSD42
  215. +#ifdef USE_SGTTY
  216. struct sgttyb savetmio;
  217. /*
  218. struct sgttyb ttyb =
  219. @@ -642,11 +657,11 @@ j_term_init()
  220. }
  221. #endif /* BSD42 */
  222. -#ifdef SYSVR2
  223. +#if defined(SYSVR2) || defined(USE_TERMIOS)
  224. #define UNDEF_STTY 0xff
  225. -struct termio savetmio;
  226. -struct termio terms = {
  227. +struct termios savetmio;
  228. +struct termios terms = {
  229. IGNBRK | ICRNL | IXON, /* c_iflag */
  230. ONLCR | OPOST, /* c_oflag */
  231. B9600 | CS8 | CSTOPB | CREAD | CLOCAL, /* c_cflag */
  232. @@ -678,13 +693,13 @@ get_rubout()
  233. int
  234. j_term_init()
  235. {
  236. - struct termio buf1;
  237. + struct termios buf1;
  238. #if defined(uniosu)
  239. struct jtermio buf2;
  240. #endif /* defined(uniosu) */
  241. buf1 = savetmio;
  242. -#ifdef linux
  243. +#ifdef USE_TERMIOS
  244. buf1.c_lflag &= ~(ECHONL | ECHOK | ECHOE | ECHO | XCASE | ICANON | ISIG);
  245. buf1.c_iflag = 0;
  246. buf1.c_oflag &= ~OPOST;
  247. @@ -705,7 +720,7 @@ j_term_init()
  248. buf1.c_cc[VEOF] = 1; /* cf. ICANON */
  249. buf1.c_cc[VEOL] = 0;
  250. #endif /* linux */
  251. - if(ioctl(ttyfd, TCSETA, &buf1) == -1){
  252. + if (tcsetattr(ttyfd, TCSANOW, &buf1) == -1) {
  253. fprintf(stderr, "error in ioctl TCSETA.\n");
  254. exit(1);
  255. }
  256. @@ -764,19 +779,20 @@ intfntype
  257. chld_handler()
  258. {
  259. #ifdef HAVE_WAIT3
  260. -#ifdef linux
  261. int status;
  262. -#else
  263. - union wait status;
  264. -#endif
  265. int pid;
  266. - if ((pid = wait3(&status, WNOHANG | WUNTRACED, NULL)) == child_id) {
  267. +/*
  268. + * Remove warning.
  269. + * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/20
  270. + */
  271. +/* if ((pid = wait3(&status, WNOHANG | WUNTRACED, NULL)) == child_id) { */
  272. + if ((pid = wait3((int *)&status, WNOHANG | WUNTRACED, NULL)) == child_id) {
  273. if (WIFSTOPPED(status)) {
  274. #ifdef SIGCONT
  275. kill(pid, SIGCONT);
  276. #ifndef SYSVR2
  277. - pid = getpgrp(pid);
  278. + pid = getpgrp();
  279. killpg(pid, SIGCONT);
  280. #else
  281. #if defined(uniosu)
  282. @@ -1107,9 +1123,9 @@ char **argv;
  283. #ifdef BSD42
  284. int pid;
  285. #endif
  286. -#ifdef linux
  287. +#if defined(linux) || defined(__OpenBSD__)
  288. struct winsize win;
  289. - extern Term_RowWidth,crow;
  290. + extern int Term_RowWidth,crow;
  291. #endif
  292. #if defined(SYSVR2) && !defined(linux)
  293. setpgrp();
  294. @@ -1140,16 +1156,18 @@ char **argv;
  295. setpgrp(0, pid);
  296. #endif /* BSD42 */
  297. +#if !(defined(BSD) && (BSD >= 199306))
  298. if (setutmp(ttypfd) == ERROR) {
  299. puts("Can't set utmp.");
  300. }
  301. +#endif
  302. -#ifdef linux
  303. +#if defined(linux) || defined(__OpenBSD__)
  304. setsid();
  305. open_ttyp();
  306. close(ptyfd);
  307. ioctl(ttyfd, TIOCGWINSZ, &win);
  308. - ioctl(ttypfd, TCSETA, &savetmio);
  309. + tcsetattr(ttypfd, TCSANOW, &savetmio);
  310. dup2(ttypfd, 0);
  311. dup2(ttypfd, 1);
  312. dup2(ttypfd, 2);
  313. @@ -1187,7 +1205,7 @@ char **argv;
  314. err("Can't set utmp.");
  315. }
  316. */
  317. -#ifdef linux
  318. +#if defined(linux) || defined(__OpenBSD__)
  319. crow = win.ws_row = Term_RowWidth = win.ws_row - conv_lines;
  320. ioctl(ttyfd, TIOCSWINSZ, &win);
  321. setgid(getgid());
  322. @@ -1198,6 +1216,7 @@ char **argv;
  323. }
  324. }
  325. +#if 0
  326. /** 環境変数のセット */
  327. void
  328. setenv(var, value)
  329. @@ -1234,6 +1253,7 @@ char *value;
  330. strcat(environ[i], "=");
  331. strcat(environ[i], value);
  332. }
  333. +#endif
  334. #ifdef SVR4
  335. static int
  336. @@ -1342,7 +1362,7 @@ open_ttyp()
  337. chown(nmbuf, getuid(), getgid());
  338. chmod(nmbuf, 0622);
  339. #endif /* !linux */
  340. -#ifdef BSD42
  341. +#ifdef USE_SGTTY
  342. ioctl(ttyfd, TIOCGETC, &tcharsv);
  343. ioctl(ttyfd, TIOCGLTC, &ltcharsv);
  344. ioctl(ttyfd, TIOCGETP, &ttyb);
  345. @@ -1446,11 +1466,23 @@ open_ttyp()
  346. close(open(ttyname(ttypfd), O_WRONLY, 0));
  347. */
  348. #endif /* defined(SYSVR2) && !defined(linux) */
  349. +#ifdef __OpenBSD__
  350. + {
  351. + struct winsize win;
  352. +
  353. + if (ioctl(ttyfd, TIOCGWINSZ, &win) != -1) {
  354. + win.ws_row = crow;
  355. + win.ws_col = maxlength;
  356. + ioctl(ttypfd, TIOCSWINSZ, &win);
  357. + }
  358. + }
  359. +#else
  360. #ifdef TIOCSSIZE
  361. pty_rowcol.ts_lines = crow; /* instead of lines */
  362. pty_rowcol.ts_cols = maxlength; /* instead of columns */
  363. ioctl(ttypfd, TIOCSSIZE, &pty_rowcol);
  364. #endif /* TIOCSSIZE */
  365. +#endif
  366. }
  367. /** pty のオープン */
  368. @@ -1524,15 +1556,13 @@ do_end()
  369. signal(SIGCHLD, SIG_DFL);
  370. fcntl(ttyfd, F_SETFL, 0);
  371. -#ifdef BSD42
  372. +#ifdef USE_SGTTY
  373. ioctl(ttyfd, TIOCSETP, &savetmio);
  374. -#endif /* BSD42 */
  375. -#if defined(BSD43) || defined(DGUX)
  376. ioctl(ttyfd, TIOCLSET, &local_mode_sv);
  377. #endif /* BSD43 */
  378. -#ifdef SYSVR2
  379. - if(ioctl(ttyfd, TCSETA, &savetmio) < 0) {
  380. +#ifdef USE_TERMIOS
  381. + if(tcsetattr(ttyfd, TCSANOW, &savetmio) < 0) {
  382. fprintf(stderr, "error in ioctl TCSETA.\n");
  383. exit(1);
  384. }
  385. @@ -1562,9 +1592,11 @@ do_end()
  386. perror(prog);
  387. }
  388. +#if !(defined(BSD) && (BSD >= 199306))
  389. if (resetutmp(ttypfd) == ERROR) {
  390. printf("Can't reset utmp.");
  391. }
  392. +#endif
  393. #ifdef TIOCSSIZE
  394. pty_rowcol.ts_lines = 0;
  395. pty_rowcol.ts_cols = 0;
  396. @@ -1636,7 +1668,16 @@ ptyname(b, pty, no)
  397. char *b, *pty;
  398. int no;
  399. {
  400. +/*
  401. + * Change pseudo-devices.
  402. + * Because FreeBSD's master pseudo-devices are pty[p-sP-S][0-9a-v].
  403. + * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/20
  404. + */
  405. +#if (defined(BSD) && (BSD >= 199306)) /* 4.4BSD-Lite by Taoka */
  406. + sprintf(b, "%s%1c%1c", pty, "pqrsPQRS"[(no >> 5)], ((no & 0x1f > 9)? 'a' : '0') + (no & 0x1f));
  407. +#else /* ! 4.4BSD-Lite */
  408. sprintf(b, "%s%1c%1x", pty, 'p' + (no >> 4), no & 0x0f);
  409. +#endif /* ! 4.4BSD-Lite */
  410. }
  411. #endif /* !sgi */
  412. @@ -1722,7 +1763,7 @@ setsize()
  413. {
  414. register int i;
  415. struct winsize win;
  416. - extern Term_LineWidth,Term_RowWidth,maxlength,crow;
  417. + extern int Term_LineWidth,Term_RowWidth,maxlength,crow;
  418. if (ioctl(ttyfd, TIOCGWINSZ, &win) < 0) {
  419. /* Default set at getTermData() */
  420. @@ -1744,7 +1785,7 @@ change_size()
  421. {
  422. register int i;
  423. struct winsize win;
  424. - extern Term_LineWidth,Term_RowWidth,maxlength,crow;
  425. + extern int Term_LineWidth,Term_RowWidth,maxlength,crow;
  426. if (ioctl(ttyfd, TIOCGWINSZ, &win) < 0) {
  427. /* Default set at getTermData() */
  428. @@ -1755,14 +1796,14 @@ change_size()
  429. if ((i = win.ws_row) != 0) {
  430. crow = Term_RowWidth = i - conv_lines;
  431. -#ifdef linux
  432. +#if defined(linux) || defined(__OpenBSD__)
  433. win.ws_row = crow;
  434. #endif
  435. }
  436. if ((i = win.ws_col) != 0) {
  437. maxlength = Term_LineWidth = i;
  438. }
  439. -#ifdef linux
  440. +#if defined(linux) || defined(__OpenBSD__)
  441. ioctl(ttypfd, TIOCSWINSZ, &win);
  442. #else /* linux */
  443. #ifdef TIOCSSIZE
  444. @@ -1770,7 +1811,8 @@ change_size()
  445. pty_rowcol.ts_cols = maxlength; /* instead of columns */
  446. ioctl(ttypfd, TIOCSSIZE, &pty_rowcol);
  447. #endif /* TIOCSSIZE */
  448. -#ifdef sun /* When your machine needs SIGWINCH, add your machine */
  449. +#endif
  450. +#if defined(sun) || defined(__OpenBSD__) /* When your machine needs SIGWINCH, add your machine */
  451. {
  452. int grp;
  453. ioctl(ptyfd, TIOCGPGRP, &grp);
  454. @@ -1781,7 +1823,6 @@ change_size()
  455. #endif
  456. }
  457. #endif /* sun */
  458. -#endif /* linux */
  459. set_scroll_region(0, crow - 1);
  460. if (henkan_off_flag) {