[med-svn] [pftools] 01/04: Prevent crashes when providing random options

Andreas Tille tille at debian.org
Fri Mar 31 11:37:24 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository pftools.

commit ebea065fa5d16c671182b5e3c3068726627850e6
Author: Andreas Tille <tille at debian.org>
Date:   Fri Mar 31 13:05:28 2017 +0200

    Prevent crashes when providing random options
---
 debian/patches/getopt_for_pgdump.patch | 49 ++++++++++++++++++++++++++++++++++
 debian/patches/series                  |  1 +
 2 files changed, 50 insertions(+)

diff --git a/debian/patches/getopt_for_pgdump.patch b/debian/patches/getopt_for_pgdump.patch
new file mode 100644
index 0000000..fcab4af
--- /dev/null
+++ b/debian/patches/getopt_for_pgdump.patch
@@ -0,0 +1,49 @@
+Author: Andreas Tille <tille at debian.org>
+Last-Update: Tue, 21 Mar 2017 22:14:51 +0100
+Description: pfdump was crashing if any option (-x) was given.
+ To prevent SIGSEGV crashes getopt is introduced by this patch
+
+--- a/src/C/utils/io.c
++++ b/src/C/utils/io.c
+@@ -3,6 +3,7 @@
+ #include <inttypes.h>
+ #include <stdbool.h>
+ #include <mm_malloc.h>
++#include <getopt.h>
+ #include <errno.h>
+ #define _GNU_SOURCE
+ #include <string.h>
+@@ -1025,11 +1026,29 @@ int main(int argc, char *argv[])
+ {
+   struct Profile prf;
+ 
+-  if (argc < 2 ) {
+-     fputs("Give at least a profile file name\n" , stderr);
+-     return 1;
++  /* getopt_long stores the option index here. */
++  struct option long_options[] =
++  {
++        {"help",                        no_argument,            0,      'h'},
++  };
++  while (1) {
++    int option_index = 0;
++    const int c = getopt_long (argc, argv, "h", long_options, &option_index);
++
++    /* Detect the end of the options. */
++    if (c == -1) break;
++    switch (c) {
++      case 'h':
++      default:
++        fprintf(stderr, "Usage: %s <profile_file>\n", argv[0]);
++        return 1;
++    }
++  }
++  if (optind == argc) {
++    fputs("Give at least a profile file name\n", stderr);
++    return 1;
+   }
+-  if (ReadProfile(argv[1], &prf) != 0) {
++  if (ReadProfile(argv[optind], &prf) != 0) {
+     FreeProfile(&prf);
+     return 1;
+   }
diff --git a/debian/patches/series b/debian/patches/series
index 321484d..6a9d397 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -4,3 +4,4 @@
 fix_path_in_test_script.patch
 fix_test_output.patch
 build_gtop.patch
+getopt_for_pgdump.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/pftools.git



More information about the debian-med-commit mailing list