patch-jhead_c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. --- jhead.c.orig Mon Feb 2 23:24:06 2015
  2. +++ jhead.c Wed Feb 4 07:43:36 2015
  3. @@ -164,7 +164,8 @@
  4. }
  5. if (strlen(Editor) > PATH_MAX) ErrFatal("env too long");
  6. - sprintf(QuotedPath, "%s \"%s\"",Editor, TempFileName);
  7. + snprintf(QuotedPath, sizeof(QuotedPath), "%s \"%s\"",Editor,
  8. + TempFileName);
  9. a = system(QuotedPath);
  10. }
  11. @@ -271,7 +272,8 @@
  12. if (!HasScandate && !ImageInfo.DateTime[0]){
  13. // Scan date is not in the file yet, and it doesn't have one built in. Add it.
  14. char Temp[40];
  15. - sprintf(Temp, "scan_date=%s", ctime(&ImageInfo.FileDateTime));
  16. + snprintf(Temp, sizeof(Temp),
  17. + "scan_date=%s", ctime(&ImageInfo.FileDateTime));
  18. strncat(OutComment, Temp, MAX_COMMENT_SIZE-5-strlen(OutComment));
  19. Modified = TRUE;
  20. }
  21. @@ -303,8 +305,10 @@
  22. if (scale < 0.4) scale = 0.4; // Don't scale down by too much.
  23. - sprintf(CommandString, "mogrify -geometry %dx%d -quality 85 &i",(int)(ImageInfo.Width*scale+0.5),
  24. - (int)(ImageInfo.Height*scale+0.5));
  25. + snprintf(CommandString, sizeof(CommandString),
  26. + "mogrify -geometry %dx%d -quality 85 &i",
  27. + (int)(ImageInfo.Width*scale+0.5), (int)(ImageInfo.Height*scale+0.5));
  28. +
  29. return TRUE;
  30. }
  31. @@ -625,7 +629,8 @@
  32. memcpy(pat, pattern+ppos, 4);
  33. pat[a-ppos] = 'd'; // Replace 'i' with 'd' for '%d'
  34. pat[a-ppos+1] = '\0';
  35. - sprintf(num, pat, FileSequence); // let printf do the number formatting.
  36. + // let printf do the number formatting.
  37. + snprintf(num, sizeof(num), pat, FileSequence);
  38. nl = strlen(num);
  39. l = strlen(pattern+a+1);
  40. if (ppos+nl+l+1 >= PATH_MAX) ErrFatal("str overflow");
  41. @@ -641,7 +646,7 @@
  42. strftime(NewName, PATH_MAX, pattern, &tm);
  43. }else{
  44. // My favourite scheme.
  45. - sprintf(NewName, "%02d%02d-%02d%02d%02d",
  46. + snprintf(NewName, sizeof(NewName), "%02d%02d-%02d%02d%02d",
  47. tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  48. }
  49. @@ -670,7 +675,7 @@
  50. NameExtra[0] = 0;
  51. }
  52. - sprintf(NewName, "%s%s.jpg", NewBaseName, NameExtra);
  53. + snprintf(NewName, sizeof(NewName), "%s%s.jpg", NewBaseName, NameExtra);
  54. if (!strcmp(FileName, NewName)) break; // Skip if its already this name.
  55. @@ -685,7 +690,8 @@
  56. printf("%s --> %s\n",FileName, NewName);
  57. #ifdef _WIN32
  58. if (RenameAssociatedFiles){
  59. - sprintf(NewName, "%s%s", NewBaseName, NameExtra);
  60. + snprintf(NewName, sizeof(NewName),
  61. + "%s%s", NewBaseName, NameExtra);
  62. RenameAssociated(FileName, NewName);
  63. }
  64. #endif
  65. @@ -718,7 +724,8 @@
  66. ErrNonfatal("Unknown orientation tag",0,0);
  67. return TRUE; // Image is still modified.
  68. }
  69. - sprintf(RotateCommand, "jpegtran -trim -%s -outfile &o &i", Argument);
  70. + snprintf(RotateCommand, sizeof(RotateCommand),
  71. + "jpegtran -trim -%s -outfile &o &i", Argument);
  72. ApplyCommand = RotateCommand;
  73. DoCommand(FileName, FALSE);
  74. ApplyCommand = NULL;
  75. @@ -737,7 +744,8 @@
  76. strcpy(ThumbTempName_out, FileName);
  77. strcat(ThumbTempName_out, ".tho");
  78. SaveThumbnail(ThumbTempName_in);
  79. - sprintf(RotateCommand,"jpegtran -trim -%s -outfile \"%s\" \"%s\"",
  80. + snprintf(RotateCommand, sizeof(RotateCommand),
  81. + "jpegtran -trim -%s -outfile \"%s\" \"%s\"",
  82. Argument, ThumbTempName_out, ThumbTempName_in);
  83. if (system(RotateCommand) == 0){
  84. @@ -765,7 +773,8 @@
  85. return FALSE;
  86. }
  87. - sprintf(ThumbnailGenCommand, "mogrify -thumbnail %dx%d \"%s\"",
  88. + snprintf(ThumbnailGenCommand, sizeof(ThumbnailGenCommand),
  89. + "mogrify -thumbnail %dx%d \"%s\"",
  90. RegenThumbnail, RegenThumbnail, FileName);
  91. if (system(ThumbnailGenCommand) == 0){
  92. @@ -1134,7 +1143,7 @@
  93. // Print to temp buffer first to avoid putting null termination in destination.
  94. // snprintf() would do the trick, hbut not available everywhere (like FreeBSD 4.4)
  95. - sprintf(TempBuf, "%04d:%02d:%02d %02d:%02d:%02d",
  96. + snprintf(TempBuf, sizeof(TempBuf), "%04d:%02d:%02d %02d:%02d:%02d",
  97. tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
  98. tm.tm_hour, tm.tm_min, tm.tm_sec);