1
0

040-Fix-error-handling-with-git-style-patches.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From 424da221cec76ea200cff1fa9b08a6f3d94c28a7 Mon Sep 17 00:00:00 2001
  2. From: Lubomir Rintel <lkundrak@v3.sk>
  3. Date: Wed, 31 Oct 2018 16:39:13 -0700
  4. Subject: [PATCH] Fix error handling with git-style patches
  5. When an error is encountered in output_files(), the subsequent call to
  6. cleanup() calls back into output_files() resulting in an infinte recursion.
  7. This is trivially reproduced with a git-style patch (which utilizes
  8. output_file_later()) that tries to patch a nonexistent or unreadable
  9. file (see attached test case).
  10. * src/patch.c: (output_files) clear the files_to_output list before
  11. iterating it, so that recursive calls won't iterate the same files.
  12. ---
  13. src/patch.c | 12 ++++++++----
  14. 1 file changed, 8 insertions(+), 4 deletions(-)
  15. --- a/src/patch.c
  16. +++ b/src/patch.c
  17. @@ -1938,8 +1938,12 @@ output_files (struct stat const *st)
  18. {
  19. gl_list_iterator_t iter;
  20. const void *elt;
  21. + gl_list_t files;
  22. - iter = gl_list_iterator (files_to_output);
  23. + files = files_to_output;
  24. + init_files_to_output ();
  25. +
  26. + iter = gl_list_iterator (files);
  27. while (gl_list_iterator_next (&iter, &elt, NULL))
  28. {
  29. const struct file_to_output *file_to_output = elt;
  30. @@ -1957,8 +1961,8 @@ output_files (struct stat const *st)
  31. /* Free the list up to here. */
  32. for (;;)
  33. {
  34. - const void *elt2 = gl_list_get_at (files_to_output, 0);
  35. - gl_list_remove_at (files_to_output, 0);
  36. + const void *elt2 = gl_list_get_at (files, 0);
  37. + gl_list_remove_at (files, 0);
  38. if (elt == elt2)
  39. break;
  40. }
  41. @@ -1967,7 +1971,7 @@ output_files (struct stat const *st)
  42. }
  43. }
  44. gl_list_iterator_free (&iter);
  45. - gl_list_clear (files_to_output);
  46. + gl_list_clear (files);
  47. }
  48. /* Fatal exit with cleanup. */