0003-Fix-NULL-dereference-when-duplicating-string-argumen.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. From f5de3401b974ce103ffd93af8f9d43505a04aaf9 Mon Sep 17 00:00:00 2001
  2. Message-Id: <f5de3401b974ce103ffd93af8f9d43505a04aaf9.1680094621.git.stefan@agner.ch>
  3. From: Damian Kurek <starfire24680@gmail.com>
  4. Date: Thu, 7 Jul 2022 03:39:16 +0000
  5. Subject: [PATCH] Fix NULL dereference when duplicating string argument
  6. poptGetArg can return NULL if there are no additional arguments, which
  7. makes strdup dereference NULL on strlen
  8. Signed-off-by: Stefan Agner <stefan@agner.ch>
  9. Upstream: https://sourceforge.net/p/gptfdisk/code/ci/f5de3401b974ce103ffd93af8f9d43505a04aaf9
  10. ---
  11. gptcl.cc | 6 ++++--
  12. 1 file changed, 4 insertions(+), 2 deletions(-)
  13. diff --git a/gptcl.cc b/gptcl.cc
  14. index 0d578eb..ab95239 100644
  15. --- a/gptcl.cc
  16. +++ b/gptcl.cc
  17. @@ -155,10 +155,11 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
  18. } // while
  19. // Assume first non-option argument is the device filename....
  20. - device = strdup((char*) poptGetArg(poptCon));
  21. - poptResetContext(poptCon);
  22. + device = (char*) poptGetArg(poptCon);
  23. if (device != NULL) {
  24. + device = strdup(device);
  25. + poptResetContext(poptCon);
  26. JustLooking(); // reset as necessary
  27. BeQuiet(); // Tell called functions to be less verbose & interactive
  28. if (LoadPartitions((string) device)) {
  29. @@ -498,6 +499,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
  30. cerr << "Error encountered; not saving changes.\n";
  31. retval = 4;
  32. } // if
  33. + free(device);
  34. } // if (device != NULL)
  35. poptFreeContext(poptCon);
  36. return retval;
  37. --
  38. 2.40.0