1. This patch was created by oCert according to
  2. http://www.ocert.org/advisories/ocert-2008-014.html
  3. and can be downloaded from
  4. http://www.ocert.org/analysis/2008-014/wordnet.patch
  5. Unfortunately the original patch had a problem which
  6. caused 'wordnet test -synsn' to fail. The critical
  7. part of the patch was removed from the whole patch
  8. set and is moved to 51_overflows_memcpy.patch which
  9. uses memcpy instead of the formerly used strcpy.
  10. Index: wordnet-3.0/lib/binsrch.c
  11. ===================================================================
  12. --- wordnet-3.0.orig/lib/binsrch.c 2013-02-19 16:03:01.698031603 +0800
  13. +++ wordnet-3.0/lib/binsrch.c 2013-02-19 16:03:01.686031603 +0800
  14. @@ -28,7 +28,7 @@
  15. char *linep;
  16. linep = line;
  17. - line[0] = '0';
  18. + line[0] = '\0';
  19. fseek( fp, offset, SEEK_SET );
  20. fgets(linep, LINE_LEN, fp);
  21. @@ -58,6 +58,8 @@
  22. last_bin_search_offset = ftell( fp );
  23. fgets(linep, LINE_LEN, fp);
  24. length = (int)(strchr(linep, ' ') - linep);
  25. + if (length > (sizeof(key) - 1))
  26. + return(NULL);
  27. strncpy(key, linep, length);
  28. key[length] = '\0';
  29. if(strcmp(key, searchkey) < 0) {
  30. @@ -110,6 +112,8 @@
  31. line[length++] = c;
  32. if (getc(fp) == EOF) { /* only 1 line in file */
  33. length = (int)(strchr(linep, ' ') - linep);
  34. + if (length > (sizeof(key) - 1))
  35. + return(0);
  36. strncpy(key, linep, length);
  37. key[length] = '\0';
  38. if(strcmp(key, searchkey) > 0) {
  39. @@ -132,6 +136,8 @@
  40. if (fgets(linep, LINE_LEN, fp) != NULL) {
  41. offset2 = ftell(fp); /* offset at start of next line */
  42. length = (int)(strchr(linep, ' ') - linep);
  43. + if (length > (sizeof(key) - 1))
  44. + return(0);
  45. strncpy(key, linep, length);
  46. key[length] = '\0';
  47. if(strcmp(key, searchkey) < 0) { /* further in file */
  48. Index: wordnet-3.0/lib/morph.c
  49. ===================================================================
  50. --- wordnet-3.0.orig/lib/morph.c 2013-02-19 16:03:01.698031603 +0800
  51. +++ wordnet-3.0/lib/morph.c 2013-02-19 16:06:14.850029761 +0800
  52. @@ -51,21 +51,21 @@
  53. char *str;
  54. int strlen;
  55. } prepositions[NUMPREPS] = {
  56. - "to", 2,
  57. - "at", 2,
  58. - "of", 2,
  59. - "on", 2,
  60. - "off", 3,
  61. - "in", 2,
  62. - "out", 3,
  63. - "up", 2,
  64. - "down", 4,
  65. - "from", 4,
  66. - "with", 4,
  67. - "into", 4,
  68. - "for", 3,
  69. - "about", 5,
  70. - "between", 7,
  71. + { "to", 2 },
  72. + { "at", 2 },
  73. + { "of", 2 },
  74. + { "on", 2 },
  75. + { "off", 3 },
  76. + { "in", 2 },
  77. + { "out", 3 },
  78. + { "up", 2 },
  79. + { "down", 4 },
  80. + { "from", 4 },
  81. + { "with", 4 },
  82. + { "into", 4 },
  83. + { "for", 3 },
  84. + { "about", 5 },
  85. + { "between", 7 }
  86. };
  87. static FILE *exc_fps[NUMPARTS + 1];
  88. @@ -144,18 +144,19 @@
  89. } else
  90. sprintf(searchdir, DEFAULTPATH);
  91. #else
  92. - if ((env = getenv("WNSEARCHDIR")) != NULL)
  93. - strcpy(searchdir, env);
  94. - else if ((env = getenv("WNHOME")) != NULL)
  95. - sprintf(searchdir, "%s%s", env, DICTDIR);
  96. - else
  97. + if ((env = getenv("WNSEARCHDIR")) != NULL) {
  98. + snprintf(searchdir, sizeof(searchdir), "%s", env);
  99. + } else if ((env = getenv("WNHOME")) != NULL) {
  100. + snprintf(searchdir, sizeof(searchdir), "%s%s", env, DICTDIR);
  101. + } else {
  102. strcpy(searchdir, DEFAULTPATH);
  103. + }
  104. #endif
  105. for (i = 1; i <= NUMPARTS; i++) {
  106. - sprintf(fname, EXCFILE, searchdir, partnames[i]);
  107. + snprintf(fname, sizeof(fname), EXCFILE, searchdir, partnames[i]);
  108. if ((exc_fps[i] = fopen(fname, "r")) == NULL) {
  109. - sprintf(msgbuf,
  110. + snprintf(msgbuf, sizeof(msgbuf),
  111. "WordNet library error: Can't open exception file(%s)\n\n",
  112. fname);
  113. display_message(msgbuf);
  114. @@ -178,13 +179,16 @@
  115. int prep;
  116. char *end_idx1, *end_idx2;
  117. char *append;
  118. -
  119. +
  120. if (pos == SATELLITE)
  121. pos = ADJ;
  122. /* First time through for this string */
  123. if (origstr != NULL) {
  124. + if (strlen(origstr) > WORDBUF - 1)
  125. + return(NULL);
  126. +
  127. /* Assume string hasn't had spaces substitued with '_' */
  128. strtolower(strsubst(strcpy(str, origstr), ' ', '_'));
  129. searchstr[0] = '\0';
  130. @@ -232,7 +236,7 @@
  131. if (end_idx < 0) return(NULL); /* shouldn't do this */
  132. strncpy(word, str + st_idx, end_idx - st_idx);
  133. word[end_idx - st_idx] = '\0';
  134. - if(tmp = morphword(word, pos))
  135. + if ((tmp = morphword(word, pos)) != NULL)
  136. strcat(searchstr,tmp);
  137. else
  138. strcat(searchstr,word);
  139. @@ -240,7 +244,7 @@
  140. st_idx = end_idx + 1;
  141. }
  142. - if(tmp = morphword(strcpy(word, str + st_idx), pos))
  143. + if ((tmp = morphword(strcpy(word, str + st_idx), pos)) != NULL)
  144. strcat(searchstr,tmp);
  145. else
  146. strcat(searchstr,word);
  147. @@ -270,16 +274,15 @@
  148. {
  149. int offset, cnt;
  150. int i;
  151. - static char retval[WORDBUF];
  152. - char *tmp, tmpbuf[WORDBUF], *end;
  153. -
  154. - sprintf(retval,"");
  155. - sprintf(tmpbuf, "");
  156. - end = "";
  157. -
  158. + static char retval[WORDBUF] = "";
  159. + char *tmp, tmpbuf[WORDBUF] = "", *end = "";
  160. +
  161. if(word == NULL)
  162. return(NULL);
  163. + if (strlen(word) > WORDBUF - 1)
  164. + return(NULL);
  165. +
  166. /* first look for word on exception list */
  167. if((tmp = exc_lookup(word, pos)) != NULL)
  168. @@ -335,7 +338,10 @@
  169. {
  170. char *pt1;
  171. static char copy[WORDBUF];
  172. -
  173. +
  174. + if (strlen(word) > WORDBUF - 1)
  175. + return(NULL);
  176. +
  177. strcpy(copy, word);
  178. if(strend(copy,sufx[ender])) {
  179. pt1=strchr(copy,'\0');
  180. @@ -368,13 +374,14 @@
  181. {
  182. static char line[WORDBUF], *beglp, *endlp;
  183. char *excline;
  184. - int found = 0;
  185. if (exc_fps[pos] == NULL)
  186. return(NULL);
  187. /* first time through load line from exception file */
  188. if(word != NULL){
  189. + if (strlen(word) > WORDBUF - 1)
  190. + return(NULL);
  191. if ((excline = bin_search(word, exc_fps[pos])) != NULL) {
  192. strcpy(line, excline);
  193. endlp = strchr(line,' ');
  194. @@ -403,6 +410,9 @@
  195. char word[WORDBUF], end[WORDBUF];
  196. static char retval[WORDBUF];
  197. + if (strlen(s) > WORDBUF - 1)
  198. + return (NULL);
  199. +
  200. /* Assume that the verb is the first word in the phrase. Strip it
  201. off, check for validity, then try various morphs with the
  202. rest of the phrase tacked on, trying to find a match. */
  203. @@ -410,7 +420,7 @@
  204. rest = strchr(s, '_');
  205. last = strrchr(s, '_');
  206. if (rest != last) { /* more than 2 words */
  207. - if (lastwd = morphword(last + 1, NOUN)) {
  208. + if ((lastwd = morphword(last + 1, NOUN)) != NULL) {
  209. strncpy(end, rest, last - rest + 1);
  210. end[last-rest+1] = '\0';
  211. strcat(end, lastwd);
  212. Index: wordnet-3.0/lib/search.c
  213. ===================================================================
  214. --- wordnet-3.0.orig/lib/search.c 2013-02-19 16:03:01.698031603 +0800
  215. +++ wordnet-3.0/lib/search.c 2013-02-19 16:03:01.690031603 +0800
  216. @@ -13,6 +13,7 @@
  217. #include <stdlib.h>
  218. #include <string.h>
  219. #include <assert.h>
  220. +#include <limits.h>
  221. #include "wn.h"
  222. @@ -119,33 +120,22 @@
  223. if ( !line )
  224. line = read_index( offset, indexfps[dbase] );
  225. - idx = (IndexPtr)malloc(sizeof(Index));
  226. + idx = (IndexPtr)calloc(1, sizeof(Index));
  227. assert(idx);
  228. /* set offset of entry in index file */
  229. idx->idxoffset = offset;
  230. - idx->wd='\0';
  231. - idx->pos='\0';
  232. - idx->off_cnt=0;
  233. - idx->tagged_cnt = 0;
  234. - idx->sense_cnt=0;
  235. - idx->offset='\0';
  236. - idx->ptruse_cnt=0;
  237. - idx->ptruse='\0';
  238. -
  239. /* get the word */
  240. ptrtok=strtok(line," \n");
  241. - idx->wd = malloc(strlen(ptrtok) + 1);
  242. + idx->wd = strdup(ptrtok);
  243. assert(idx->wd);
  244. - strcpy(idx->wd, ptrtok);
  245. /* get the part of speech */
  246. ptrtok=strtok(NULL," \n");
  247. - idx->pos = malloc(strlen(ptrtok) + 1);
  248. + idx->pos = strdup(ptrtok);
  249. assert(idx->pos);
  250. - strcpy(idx->pos, ptrtok);
  251. /* get the collins count */
  252. ptrtok=strtok(NULL," \n");
  253. @@ -154,7 +144,12 @@
  254. /* get the number of pointers types */
  255. ptrtok=strtok(NULL," \n");
  256. idx->ptruse_cnt = atoi(ptrtok);
  257. -
  258. +
  259. + if (idx->ptruse_cnt < 0 || (unsigned int)idx->ptruse_cnt > UINT_MAX/sizeof(int)) {
  260. + free_index(idx);
  261. + return(NULL);
  262. + }
  263. +
  264. if (idx->ptruse_cnt) {
  265. idx->ptruse = (int *) malloc(idx->ptruse_cnt * (sizeof(int)));
  266. assert(idx->ptruse);
  267. @@ -173,9 +168,14 @@
  268. /* get the number of senses that are tagged */
  269. ptrtok=strtok(NULL," \n");
  270. idx->tagged_cnt = atoi(ptrtok);
  271. -
  272. +
  273. + if (idx->off_cnt < 0 || (unsigned long)idx->off_cnt > ULONG_MAX/sizeof(long)) {
  274. + free_index(idx);
  275. + return(NULL);
  276. + }
  277. +
  278. /* make space for the offsets */
  279. - idx->offset = (long *) malloc(idx->off_cnt * (sizeof(long)));
  280. + idx->offset = (unsigned long *) malloc(idx->off_cnt * sizeof(long));
  281. assert(idx->offset);
  282. /* get the offsets */
  283. @@ -197,15 +197,21 @@
  284. char strings[MAX_FORMS][WORDBUF]; /* vector of search strings */
  285. static IndexPtr offsets[MAX_FORMS];
  286. static int offset;
  287. -
  288. +
  289. /* This works like strrok(): if passed with a non-null string,
  290. prepare vector of search strings and offsets. If string
  291. is null, look at current list of offsets and return next
  292. one, or NULL if no more alternatives for this word. */
  293. if (searchstr != NULL) {
  294. + /* Bail out if the input is too long for us to handle */
  295. + if (strlen(searchstr) > (WORDBUF - 1)) {
  296. + strcpy(msgbuf, "WordNet library error: search term is too long\n");
  297. + display_message(msgbuf);
  298. + return(NULL);
  299. + }
  300. - offset = 0;
  301. + offset = 0;
  302. strtolower(searchstr);
  303. for (i = 0; i < MAX_FORMS; i++) {
  304. strcpy(strings[i], searchstr);
  305. @@ -229,11 +235,11 @@
  306. /* Get offset of first entry. Then eliminate duplicates
  307. and get offsets of unique strings. */
  308. - if (strings[0][0] != NULL)
  309. + if (strings[0] != NULL)
  310. offsets[0] = index_lookup(strings[0], dbase);
  311. for (i = 1; i < MAX_FORMS; i++)
  312. - if ((strings[i][0]) != NULL && (strcmp(strings[0], strings[i])))
  313. + if (strings[i] != NULL && (strcmp(strings[0], strings[i])))
  314. offsets[i] = index_lookup(strings[i], dbase);
  315. }
  316. @@ -272,7 +278,7 @@
  317. SynsetPtr parse_synset(FILE *fp, int dbase, char *word)
  318. {
  319. static char line[LINEBUF];
  320. - char tbuf[SMLINEBUF];
  321. + char tbuf[SMLINEBUF] = "";
  322. char *ptrtok;
  323. char *tmpptr;
  324. int foundpert = 0;
  325. @@ -286,33 +292,11 @@
  326. if ((tmpptr = fgets(line, LINEBUF, fp)) == NULL)
  327. return(NULL);
  328. - synptr = (SynsetPtr)malloc(sizeof(Synset));
  329. + synptr = (SynsetPtr)calloc(1, sizeof(Synset));
  330. assert(synptr);
  331. -
  332. - synptr->hereiam = 0;
  333. +
  334. synptr->sstype = DONT_KNOW;
  335. - synptr->fnum = 0;
  336. - synptr->pos = '\0';
  337. - synptr->wcount = 0;
  338. - synptr->words = '\0';
  339. - synptr->whichword = 0;
  340. - synptr->ptrcount = 0;
  341. - synptr->ptrtyp = '\0';
  342. - synptr->ptroff = '\0';
  343. - synptr->ppos = '\0';
  344. - synptr->pto = '\0';
  345. - synptr->pfrm = '\0';
  346. - synptr->fcount = 0;
  347. - synptr->frmid = '\0';
  348. - synptr->frmto = '\0';
  349. - synptr->defn = '\0';
  350. - synptr->key = 0;
  351. - synptr->nextss = NULL;
  352. - synptr->nextform = NULL;
  353. synptr->searchtype = -1;
  354. - synptr->ptrlist = NULL;
  355. - synptr->headword = NULL;
  356. - synptr->headsense = 0;
  357. ptrtok = line;
  358. @@ -322,7 +306,7 @@
  359. /* sanity check - make sure starting file offset matches first field */
  360. if (synptr->hereiam != loc) {
  361. - sprintf(msgbuf, "WordNet library error: no synset at location %d\n",
  362. + sprintf(msgbuf, "WordNet library error: no synset at location %ld\n",
  363. loc);
  364. display_message(msgbuf);
  365. free(synptr);
  366. @@ -335,16 +319,20 @@
  367. /* looking at POS */
  368. ptrtok = strtok(NULL, " \n");
  369. - synptr->pos = malloc(strlen(ptrtok) + 1);
  370. + synptr->pos = strdup(ptrtok);
  371. assert(synptr->pos);
  372. - strcpy(synptr->pos, ptrtok);
  373. if (getsstype(synptr->pos) == SATELLITE)
  374. synptr->sstype = INDIRECT_ANT;
  375. /* looking at numwords */
  376. ptrtok = strtok(NULL, " \n");
  377. synptr->wcount = strtol(ptrtok, NULL, 16);
  378. -
  379. +
  380. + if (synptr->wcount < 0 || (unsigned int)synptr->wcount > UINT_MAX/sizeof(char *)) {
  381. + free_syns(synptr);
  382. + return(NULL);
  383. + }
  384. +
  385. synptr->words = (char **)malloc(synptr->wcount * sizeof(char *));
  386. assert(synptr->words);
  387. synptr->wnsns = (int *)malloc(synptr->wcount * sizeof(int));
  388. @@ -354,9 +342,8 @@
  389. for (i = 0; i < synptr->wcount; i++) {
  390. ptrtok = strtok(NULL, " \n");
  391. - synptr->words[i] = malloc(strlen(ptrtok) + 1);
  392. + synptr->words[i] = strdup(ptrtok);
  393. assert(synptr->words[i]);
  394. - strcpy(synptr->words[i], ptrtok);
  395. /* is this the word we're looking for? */
  396. @@ -371,6 +358,12 @@
  397. ptrtok = strtok(NULL," \n");
  398. synptr->ptrcount = atoi(ptrtok);
  399. + /* Should we check for long here as well? */
  400. + if (synptr->ptrcount < 0 || (unsigned int)synptr->ptrcount > UINT_MAX/sizeof(int)) {
  401. + free_syns(synptr);
  402. + return(NULL);
  403. + }
  404. +
  405. if (synptr->ptrcount) {
  406. /* alloc storage for the pointers */
  407. @@ -455,21 +448,23 @@
  408. ptrtok = strtok(NULL," \n");
  409. if (ptrtok) {
  410. ptrtok = strtok(NULL," \n");
  411. - sprintf(tbuf, "");
  412. while (ptrtok != NULL) {
  413. + if (strlen(ptrtok) + strlen(tbuf) + 1 + 1 > sizeof(tbuf)) {
  414. + free_syns(synptr);
  415. + return(NULL);
  416. + }
  417. strcat(tbuf,ptrtok);
  418. ptrtok = strtok(NULL, " \n");
  419. if(ptrtok)
  420. strcat(tbuf," ");
  421. }
  422. - assert((1 + strlen(tbuf)) < sizeof(tbuf));
  423. - synptr->defn = malloc(strlen(tbuf) + 4);
  424. + synptr->defn = malloc(strlen(tbuf) + 3);
  425. assert(synptr->defn);
  426. sprintf(synptr->defn,"(%s)",tbuf);
  427. }
  428. if (keyindexfp) { /* we have unique keys */
  429. - sprintf(tmpbuf, "%c:%8.8d", partchars[dbase], synptr->hereiam);
  430. + sprintf(tmpbuf, "%c:%8.8ld", partchars[dbase], synptr->hereiam);
  431. synptr->key = GetKeyForOffset(tmpbuf);
  432. }
  433. @@ -635,7 +630,7 @@
  434. if ((ptrtyp == PERTPTR || ptrtyp == PPLPTR) &&
  435. synptr->pto[i] != 0) {
  436. - sprintf(tbuf, " (Sense %d)\n",
  437. + snprintf(tbuf, sizeof(tbuf), " (Sense %d)\n",
  438. cursyn->wnsns[synptr->pto[i] - 1]);
  439. printsynset(prefix, cursyn, tbuf, DEFOFF, synptr->pto[i],
  440. SKIP_ANTS, PRINT_MARKER);
  441. @@ -656,7 +651,7 @@
  442. traceptrs(cursyn, HYPERPTR, getpos(cursyn->pos), 0);
  443. }
  444. } else if (ptrtyp == ANTPTR && dbase != ADJ && synptr->pto[i] != 0) {
  445. - sprintf(tbuf, " (Sense %d)\n",
  446. + snprintf(tbuf, sizeof(tbuf), " (Sense %d)\n",
  447. cursyn->wnsns[synptr->pto[i] - 1]);
  448. printsynset(prefix, cursyn, tbuf, DEFOFF, synptr->pto[i],
  449. SKIP_ANTS, PRINT_MARKER);
  450. @@ -817,7 +812,7 @@
  451. cursyn = read_synset(synptr->ppos[i], synptr->ptroff[i], "");
  452. - sprintf(tbuf, "#%d\n",
  453. + snprintf(tbuf, sizeof(tbuf), "#%d\n",
  454. cursyn->wnsns[synptr->pto[i] - 1]);
  455. printsynset(prefix, cursyn, tbuf, DEFOFF, synptr->pto[i],
  456. SKIP_ANTS, SKIP_MARKER);
  457. @@ -989,12 +984,12 @@
  458. char sentbuf[512];
  459. if (vsentfilefp != NULL) {
  460. - if (line = bin_search(offset, vsentfilefp)) {
  461. + if ((line = bin_search(offset, vsentfilefp)) != NULL) {
  462. while(*line != ' ')
  463. line++;
  464. printbuffer(" EX: ");
  465. - sprintf(sentbuf, line, wd);
  466. + snprintf(sentbuf, sizeof(sentbuf), line, wd);
  467. printbuffer(sentbuf);
  468. }
  469. }
  470. @@ -1011,7 +1006,7 @@
  471. if (vidxfilefp != NULL) {
  472. wdnum = synptr->whichword - 1;
  473. - sprintf(tbuf,"%s%%%-1.1d:%-2.2d:%-2.2d::",
  474. + snprintf(tbuf, sizeof(tbuf), "%s%%%-1.1d:%-2.2d:%-2.2d::",
  475. synptr->words[wdnum],
  476. getpos(synptr->pos),
  477. synptr->fnum,
  478. @@ -1124,7 +1119,7 @@
  479. if (cnt >= 17 && cnt <= 32) familiar = 6;
  480. if (cnt > 32 ) familiar = 7;
  481. - sprintf(tmpbuf,
  482. + snprintf(tmpbuf, sizeof(tmpbuf),
  483. "\n%s used as %s is %s (polysemy count = %d)\n",
  484. index->wd, a_an[getpos(index->pos)], freqcats[familiar], cnt);
  485. printbuffer(tmpbuf);
  486. @@ -1147,6 +1142,9 @@
  487. }
  488. rewind(inputfile);
  489. + if (strlen(word_passed) + 1 > sizeof(word))
  490. + return;
  491. +
  492. strcpy (word, word_passed);
  493. ToLowerCase(word); /* map to lower case for index file search */
  494. strsubst (word, ' ', '_'); /* replace spaces with underscores */
  495. @@ -1169,7 +1167,7 @@
  496. ((line[loc + wordlen] == '-') || (line[loc + wordlen] == '_')))
  497. ) {
  498. strsubst (line, '_', ' ');
  499. - sprintf (tmpbuf, "%s\n", line);
  500. + snprintf (tmpbuf, sizeof(tmpbuf), "%s\n", line);
  501. printbuffer (tmpbuf);
  502. break;
  503. }
  504. @@ -1683,9 +1681,8 @@
  505. cursyn = read_synset(synptr->ppos[i],
  506. synptr->ptroff[i],
  507. "");
  508. - synptr->headword = malloc(strlen(cursyn->words[0]) + 1);
  509. + synptr->headword = strdup(cursyn->words[0]);
  510. assert(synptr->headword);
  511. - strcpy(synptr->headword, cursyn->words[0]);
  512. synptr->headsense = cursyn->lexid[0];
  513. free_synset(cursyn);
  514. break;
  515. @@ -2013,7 +2010,7 @@
  516. strsubst(strcpy(wdbuf, synptr->words[whichword - 1]), ' ', '_');
  517. strtolower(wdbuf);
  518. - if (idx = index_lookup(wdbuf, getpos(synptr->pos))) {
  519. + if ((idx = index_lookup(wdbuf, getpos(synptr->pos))) != NULL) {
  520. for (i = 0; i < idx->off_cnt; i++)
  521. if (idx->offset[i] == synptr->hereiam) {
  522. free_index(idx);
  523. @@ -2037,7 +2034,7 @@
  524. by flags */
  525. if (offsetflag) /* print synset offset */
  526. - sprintf(tbuf + strlen(tbuf),"{%8.8d} ", synptr->hereiam);
  527. + sprintf(tbuf + strlen(tbuf),"{%8.8ld} ", synptr->hereiam);
  528. if (fileinfoflag) { /* print lexicographer file information */
  529. sprintf(tbuf + strlen(tbuf), "<%s> ", lexfiles[synptr->fnum]);
  530. prlexid = 1; /* print lexicographer id after word */
  531. @@ -2072,7 +2069,7 @@
  532. tbuf[0] = '\0';
  533. if (offsetflag)
  534. - sprintf(tbuf,"{%8.8d} ", synptr->hereiam);
  535. + sprintf(tbuf,"{%8.8ld} ", synptr->hereiam);
  536. if (fileinfoflag) {
  537. sprintf(tbuf + strlen(tbuf),"<%s> ", lexfiles[synptr->fnum]);
  538. prlexid = 1;
  539. Index: wordnet-3.0/lib/wnutil.c
  540. ===================================================================
  541. --- wordnet-3.0.orig/lib/wnutil.c 2013-02-19 16:03:01.698031603 +0800
  542. +++ wordnet-3.0/lib/wnutil.c 2013-02-19 16:03:01.690031603 +0800
  543. @@ -48,7 +48,7 @@
  544. char *env;
  545. if (!done) {
  546. - if (env = getenv("WNDBVERSION")) {
  547. + if ((env = getenv("WNDBVERSION")) != NULL) {
  548. wnrelease = strdup(env); /* set release */
  549. assert(wnrelease);
  550. }
  551. @@ -70,7 +70,7 @@
  552. closefps();
  553. - if (env = getenv("WNDBVERSION")) {
  554. + if ((env = getenv("WNDBVERSION")) != NULL) {
  555. wnrelease = strdup(env); /* set release */
  556. assert(wnrelease);
  557. }
  558. @@ -149,25 +149,25 @@
  559. sprintf(searchdir, DEFAULTPATH);
  560. #else
  561. if ((env = getenv("WNSEARCHDIR")) != NULL)
  562. - strcpy(searchdir, env);
  563. + snprintf(searchdir, sizeof(searchdir), "%s", env);
  564. else if ((env = getenv("WNHOME")) != NULL)
  565. - sprintf(searchdir, "%s%s", env, DICTDIR);
  566. + snprintf(searchdir, sizeof(searchdir), "%s%s", env, DICTDIR);
  567. else
  568. strcpy(searchdir, DEFAULTPATH);
  569. #endif
  570. for (i = 1; i < NUMPARTS + 1; i++) {
  571. - sprintf(tmpbuf, DATAFILE, searchdir, partnames[i]);
  572. + snprintf(tmpbuf, sizeof(tmpbuf), DATAFILE, searchdir, partnames[i]);
  573. if((datafps[i] = fopen(tmpbuf, "r")) == NULL) {
  574. - sprintf(msgbuf,
  575. + snprintf(msgbuf, sizeof(msgbuf),
  576. "WordNet library error: Can't open datafile(%s)\n",
  577. tmpbuf);
  578. display_message(msgbuf);
  579. openerr = -1;
  580. }
  581. - sprintf(tmpbuf, INDEXFILE, searchdir, partnames[i]);
  582. + snprintf(tmpbuf, sizeof(tmpbuf), INDEXFILE, searchdir, partnames[i]);
  583. if((indexfps[i] = fopen(tmpbuf, "r")) == NULL) {
  584. - sprintf(msgbuf,
  585. + snprintf(msgbuf, sizeof(msgbuf),
  586. "WordNet library error: Can't open indexfile(%s)\n",
  587. tmpbuf);
  588. display_message(msgbuf);
  589. @@ -178,35 +178,35 @@
  590. /* This file isn't used by the library and doesn't have to
  591. be present. No error is reported if the open fails. */
  592. - sprintf(tmpbuf, SENSEIDXFILE, searchdir);
  593. + snprintf(tmpbuf, sizeof(tmpbuf), SENSEIDXFILE, searchdir);
  594. sensefp = fopen(tmpbuf, "r");
  595. /* If this file isn't present, the runtime code will skip printint out
  596. the number of times each sense was tagged. */
  597. - sprintf(tmpbuf, CNTLISTFILE, searchdir);
  598. + snprintf(tmpbuf, sizeof(tmpbuf), CNTLISTFILE, searchdir);
  599. cntlistfp = fopen(tmpbuf, "r");
  600. /* This file doesn't have to be present. No error is reported if the
  601. open fails. */
  602. - sprintf(tmpbuf, KEYIDXFILE, searchdir);
  603. + snprintf(tmpbuf, sizeof(tmpbuf), KEYIDXFILE, searchdir);
  604. keyindexfp = fopen(tmpbuf, "r");
  605. - sprintf(tmpbuf, REVKEYIDXFILE, searchdir);
  606. + snprintf(tmpbuf, sizeof(tmpbuf), REVKEYIDXFILE, searchdir);
  607. revkeyindexfp = fopen(tmpbuf, "r");
  608. - sprintf(tmpbuf, VRBSENTFILE, searchdir);
  609. + snprintf(tmpbuf, sizeof(tmpbuf), VRBSENTFILE, searchdir);
  610. if ((vsentfilefp = fopen(tmpbuf, "r")) == NULL) {
  611. - sprintf(msgbuf,
  612. + snprintf(msgbuf, sizeof(msgbuf),
  613. "WordNet library warning: Can't open verb example sentence file(%s)\n",
  614. tmpbuf);
  615. display_message(msgbuf);
  616. }
  617. - sprintf(tmpbuf, VRBIDXFILE, searchdir);
  618. + snprintf(tmpbuf, sizeof(tmpbuf), VRBIDXFILE, searchdir);
  619. if ((vidxfilefp = fopen(tmpbuf, "r")) == NULL) {
  620. - sprintf(msgbuf,
  621. + snprintf(msgbuf, sizeof(msgbuf),
  622. "WordNet library warning: Can't open verb example sentence index file(%s)\n",
  623. tmpbuf);
  624. display_message(msgbuf);
  625. Index: wordnet-3.0/src/wn.c
  626. ===================================================================
  627. --- wordnet-3.0.orig/src/wn.c 2013-02-19 16:03:01.698031603 +0800
  628. +++ wordnet-3.0/src/wn.c 2013-02-19 16:03:01.690031603 +0800
  629. @@ -131,7 +131,7 @@
  630. printsearches(char *, int, unsigned long);
  631. static int error_message(char *);
  632. -main(int argc,char *argv[])
  633. +int main(int argc,char *argv[])
  634. {
  635. display_message = error_message;
  636. @@ -228,14 +228,14 @@
  637. printf("\n%s of %s %s\n%s",
  638. label, partnames[pos], searchword, outbuf);
  639. - if (morphword = morphstr(searchword, pos))
  640. + if ((morphword = morphstr(searchword, pos)) != NULL)
  641. do {
  642. outbuf = findtheinfo(morphword, pos, search, whichsense);
  643. totsenses += wnresults.printcnt;
  644. if (strlen(outbuf) > 0)
  645. printf("\n%s of %s %s\n%s",
  646. label, partnames[pos], morphword, outbuf);
  647. - } while (morphword = morphstr(NULL, pos));
  648. + } while ((morphword = morphstr(NULL, pos)) != NULL);
  649. return(totsenses);
  650. }