patch-lib_binsrch_c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. $OpenBSD: patch-lib_binsrch_c,v 1.1 2008/09/01 20:02:53 sthen Exp $
  2. --- lib/binsrch.c.orig Wed Nov 29 21:02:21 2006
  3. +++ lib/binsrch.c Mon Sep 1 20:53:39 2008
  4. @@ -28,7 +28,7 @@ char *read_index(long offset, FILE *fp) {
  5. char *linep;
  6. linep = line;
  7. - line[0] = '0';
  8. + line[0] = '\0';
  9. fseek( fp, offset, SEEK_SET );
  10. fgets(linep, LINE_LEN, fp);
  11. @@ -58,6 +58,8 @@ char *bin_search(char *searchkey, FILE *fp)
  12. last_bin_search_offset = ftell( fp );
  13. fgets(linep, LINE_LEN, fp);
  14. length = (int)(strchr(linep, ' ') - linep);
  15. + if (length > (sizeof(key) - 1))
  16. + return(NULL);
  17. strncpy(key, linep, length);
  18. key[length] = '\0';
  19. if(strcmp(key, searchkey) < 0) {
  20. @@ -110,6 +112,8 @@ static int bin_search_key(char *searchkey, FILE *fp)
  21. line[length++] = c;
  22. if (getc(fp) == EOF) { /* only 1 line in file */
  23. length = (int)(strchr(linep, ' ') - linep);
  24. + if (length > (sizeof(key) - 1))
  25. + return(0);
  26. strncpy(key, linep, length);
  27. key[length] = '\0';
  28. if(strcmp(key, searchkey) > 0) {
  29. @@ -132,6 +136,8 @@ static int bin_search_key(char *searchkey, FILE *fp)
  30. if (fgets(linep, LINE_LEN, fp) != NULL) {
  31. offset2 = ftell(fp); /* offset at start of next line */
  32. length = (int)(strchr(linep, ' ') - linep);
  33. + if (length > (sizeof(key) - 1))
  34. + return(0);
  35. strncpy(key, linep, length);
  36. key[length] = '\0';
  37. if(strcmp(key, searchkey) < 0) { /* further in file */