gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 729d337 2/2: Sanity check added on value to --


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 729d337 2/2: Sanity check added on value to --section in Crop
Date: Mon, 3 Dec 2018 15:18:10 -0500 (EST)

branch: master
commit 729d3375ad546080121ed71d8aa07b7a8a35f980
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Sanity check added on value to --section in Crop
    
    Until now, there was no sanity checks on the values given to the
    `--section' option in Crop! Therefore if (for example) there are alphabetic
    characters in the value, it will fall into an infinite loop and hang! With
    this commit, if any unrecognized character is encountered, Crop will abort
    with an informative description.
    
    This fixes bug #55157.
---
 NEWS               |  1 +
 bin/crop/onecrop.c | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/NEWS b/NEWS
index b898bf8..5341eda 100644
--- a/NEWS
+++ b/NEWS
@@ -130,6 +130,7 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   bug #54810: Arithmetic crash when previously named operand renamed.
   bug #55025: MakeCatalog's `--prepforconv' option being ignored.
   bug #55079: Blank EPS or PDF page when width options not given.
+  bug #55157: No sanity check on values given to Crop's --section.
 
 
 * Noteworthy changes in release 0.7 (library 5.0.0) (2018-08-08) [stable]
diff --git a/bin/crop/onecrop.c b/bin/crop/onecrop.c
index 9b97718..7dcefc7 100644
--- a/bin/crop/onecrop.c
+++ b/bin/crop/onecrop.c
@@ -127,7 +127,23 @@ onecrop_parse_section(struct cropparams *p, size_t *dsize,
           add=1;                /* If it is an asterisk, then add the */
           ++pt;                 /* given value to the maximum size of */
           break;                /* the image. */
+
+        /* Numerical characters signify the start of a number, so we don't
+           need to increment the pointer and can just break out. */
+        case '0': case '1': case '2': case '3': case '4': case '5':
+        case '6': case '7': case '8': case '9': case '-':
+          break;
+
+        /* An un-recognized character should crash the program. */
         default:
+          error(EXIT_FAILURE, 0, "value to `--section' must only contain "
+                "integer numbers and these special characters between them: "
+                "`,', `:', `*' when necessary. But it is `%s' (the first "
+                "non-acceptable character is `%c').\n\n"
+                "Please run the command below to learn more about this "
+                "option in Gnuastro's Crop program:\n\n"
+                "    $ info gnuastro \"Crop section syntax\"\n", p->section,
+                *pt);
           break;
         }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]