From a1045f556c11172064c57b96974b85ddbf9b6ea8 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Fri, 30 Aug 2024 16:18:13 -0400 Subject: [PATCH 01/11] Fix Unbounded Source Buffer --- display/d.mon/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/display/d.mon/main.c b/display/d.mon/main.c index 11c832ac56c..7d10cd3c8d7 100644 --- a/display/d.mon/main.c +++ b/display/d.mon/main.c @@ -32,6 +32,8 @@ #include "proto.h" +#define MONITOR_NAME_LIMIT 256 + int main(int argc, char *argv[]) { struct GModule *module; @@ -176,7 +178,7 @@ int main(int argc, char *argv[]) if (list_flag->answer) G_warning(_("Flag -%c ignored"), list_flag->key); mon = G_getenv_nofatal("MONITOR"); - if (mon) { + if (mon && strlen(mon) < MONITOR_NAME_LIMIT) { if (selected_flag->answer) { G_verbose_message(_("Currently selected monitor:")); fprintf(stdout, "%s\n", mon); @@ -194,8 +196,12 @@ int main(int argc, char *argv[]) ret = stop_mon(mon); } } - else + else if (!mon) { G_important_message(_("No monitor selected")); + } + else { + G_important_message(_("Monitor name is too long")); + } exit(EXIT_SUCCESS); } From c246b03874d8be7baff8d7b0d87c3ac7b19c2862 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Sun, 1 Sep 2024 17:34:20 -0400 Subject: [PATCH 02/11] Added checks in file --- display/d.mon/list.c | 3 +++ display/d.mon/main.c | 2 +- display/d.mon/stop.c | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index ab346302a61..0cdadaa4f52 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -105,6 +105,9 @@ int check_mon(const char *name) /* list related commands for given monitor */ void list_cmd(const char *name, FILE *fd_out) { + if (strlen(name) >= GPATH_MAX) { + G_fatal_error(_("Monitor name <%s> is too long."), name); + } char *mon_path; char cmd_file[GPATH_MAX], buf[4096]; FILE *fd; diff --git a/display/d.mon/main.c b/display/d.mon/main.c index 7d10cd3c8d7..c568c8f69ab 100644 --- a/display/d.mon/main.c +++ b/display/d.mon/main.c @@ -32,7 +32,7 @@ #include "proto.h" -#define MONITOR_NAME_LIMIT 256 +#define MONITOR_NAME_LIMIT (GPATH_MAX - strlen("/MONITORS/") - 1) int main(int argc, char *argv[]) { diff --git a/display/d.mon/stop.c b/display/d.mon/stop.c index d131a374d4b..4efd82b1587 100644 --- a/display/d.mon/stop.c +++ b/display/d.mon/stop.c @@ -14,6 +14,10 @@ static int stop(const char *); int stop_mon(const char *name) { + if (strlen(name) >= GPATH_MAX) { + G_fatal_error(_("Monitor name <%s> is too long."), name); + } + if (!check_mon(name)) { G_fatal_error(_("Monitor <%s> is not running"), name); } From aee6c48c466b0d31183a3e6ef377abd0c86d4db8 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Sun, 1 Sep 2024 17:36:54 -0400 Subject: [PATCH 03/11] added checks --- display/d.mon/list.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index 0cdadaa4f52..6305e45d90c 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -139,6 +139,9 @@ void list_files(const char *name, FILE *fd_out) strcat(tmpdir, "MONITORS"); strcat(tmpdir, "/"); strcat(tmpdir, name); + if (strlen(tmpdir) >= GPATH_MAX) { + G_fatal_error(_("The path for monitor <%s> is too long."), name); + } G_file_name(mon_path, tmpdir, NULL, G_mapset()); fprintf(fd_out, "path=%s\n", mon_path); From 1889258aeb5310c82f3cf3baacca6a4bd5f61520 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Thu, 5 Sep 2024 19:52:53 -0400 Subject: [PATCH 04/11] Requested changes --- display/d.mon/list.c | 60 ++++++++++++++++++++++++++++++++++---------- display/d.mon/main.c | 4 +-- display/d.mon/stop.c | 4 --- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index 6305e45d90c..019cc45a3d2 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -12,13 +12,33 @@ char *get_path(const char *name, int fpath) { char tmpdir[GPATH_MAX]; + int available_space; G_temp_element(tmpdir); - strcat(tmpdir, "/"); - strcat(tmpdir, "MONITORS"); + available_space = GPATH_MAX - strlen(tmpdir) - 1; + if (available_space < strlen("/MONITORS")) { + G_fatal_error( + _("Insufficient space to append /MONITORS to the path for <%s>."), + name); + } + strncat(tmpdir, "/MONITORS", available_space); + available_space -= strlen("/MONITORS"); if (name) { - strcat(tmpdir, "/"); - strcat(tmpdir, name); + if (available_space < strlen("/")) { + G_fatal_error( + _("Insufficient space to append / to the path for <%s>."), + name); + } + strncat(tmpdir, "/", available_space); + available_space -= strlen("/"); + + if (available_space < strlen(name)) { + G_fatal_error(_("Insufficient space to append the monitor name " + "<%s> to the path."), + name); + } + strncat(tmpdir, name, available_space); + available_space -= strlen(name); } if (fpath) { @@ -105,9 +125,6 @@ int check_mon(const char *name) /* list related commands for given monitor */ void list_cmd(const char *name, FILE *fd_out) { - if (strlen(name) >= GPATH_MAX) { - G_fatal_error(_("Monitor name <%s> is too long."), name); - } char *mon_path; char cmd_file[GPATH_MAX], buf[4096]; FILE *fd; @@ -133,15 +150,32 @@ void list_files(const char *name, FILE *fd_out) char tmpdir[GPATH_MAX], mon_path[GPATH_MAX]; struct dirent *dp; DIR *dirp; + int available_space; G_temp_element(tmpdir); - strcat(tmpdir, "/"); - strcat(tmpdir, "MONITORS"); - strcat(tmpdir, "/"); - strcat(tmpdir, name); - if (strlen(tmpdir) >= GPATH_MAX) { - G_fatal_error(_("The path for monitor <%s> is too long."), name); + available_space = GPATH_MAX - strlen(tmpdir) - 1; + if (available_space < strlen("/MONITORS")) { + G_fatal_error( + _("Insufficient space to append /MONITORS to the path for <%s>."), + name); + } + strncat(tmpdir, "/MONITORS", available_space); + available_space -= strlen("/MONITORS"); + + if (available_space < strlen("/")) { + G_fatal_error(_("Insufficient space to append / to the path for <%s>."), + name); + } + strncat(tmpdir, "/", available_space); + available_space -= strlen("/"); + + if (available_space < strlen(name)) { + G_fatal_error(_("Insufficient space to append the monitor name <%s> to " + "the path."), + name); } + strncat(tmpdir, name, available_space); + available_space -= strlen(name); G_file_name(mon_path, tmpdir, NULL, G_mapset()); fprintf(fd_out, "path=%s\n", mon_path); diff --git a/display/d.mon/main.c b/display/d.mon/main.c index c568c8f69ab..6e93a8c89ea 100644 --- a/display/d.mon/main.c +++ b/display/d.mon/main.c @@ -32,8 +32,6 @@ #include "proto.h" -#define MONITOR_NAME_LIMIT (GPATH_MAX - strlen("/MONITORS/") - 1) - int main(int argc, char *argv[]) { struct GModule *module; @@ -178,7 +176,7 @@ int main(int argc, char *argv[]) if (list_flag->answer) G_warning(_("Flag -%c ignored"), list_flag->key); mon = G_getenv_nofatal("MONITOR"); - if (mon && strlen(mon) < MONITOR_NAME_LIMIT) { + if (mon && strlen(mon) < GNAME_MAX) { if (selected_flag->answer) { G_verbose_message(_("Currently selected monitor:")); fprintf(stdout, "%s\n", mon); diff --git a/display/d.mon/stop.c b/display/d.mon/stop.c index 4efd82b1587..d131a374d4b 100644 --- a/display/d.mon/stop.c +++ b/display/d.mon/stop.c @@ -14,10 +14,6 @@ static int stop(const char *); int stop_mon(const char *name) { - if (strlen(name) >= GPATH_MAX) { - G_fatal_error(_("Monitor name <%s> is too long."), name); - } - if (!check_mon(name)) { G_fatal_error(_("Monitor <%s> is not running"), name); } From 523c36cf0b535f399486cf5e88f9b1b2f9c35ed1 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Thu, 5 Sep 2024 20:15:58 -0400 Subject: [PATCH 05/11] Updated --- display/d.mon/list.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index 019cc45a3d2..c5f38615f38 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -21,7 +21,7 @@ char *get_path(const char *name, int fpath) _("Insufficient space to append /MONITORS to the path for <%s>."), name); } - strncat(tmpdir, "/MONITORS", available_space); + strcat(tmpdir, "/MONITORS"); available_space -= strlen("/MONITORS"); if (name) { if (available_space < strlen("/")) { @@ -29,7 +29,7 @@ char *get_path(const char *name, int fpath) _("Insufficient space to append / to the path for <%s>."), name); } - strncat(tmpdir, "/", available_space); + strcat(tmpdir, "/"); available_space -= strlen("/"); if (available_space < strlen(name)) { @@ -37,7 +37,7 @@ char *get_path(const char *name, int fpath) "<%s> to the path."), name); } - strncat(tmpdir, name, available_space); + strcat(tmpdir, name); available_space -= strlen(name); } @@ -159,14 +159,14 @@ void list_files(const char *name, FILE *fd_out) _("Insufficient space to append /MONITORS to the path for <%s>."), name); } - strncat(tmpdir, "/MONITORS", available_space); + strcat(tmpdir, "/MONITORS"); available_space -= strlen("/MONITORS"); if (available_space < strlen("/")) { G_fatal_error(_("Insufficient space to append / to the path for <%s>."), name); } - strncat(tmpdir, "/", available_space); + strcat(tmpdir, "/"); available_space -= strlen("/"); if (available_space < strlen(name)) { @@ -174,7 +174,7 @@ void list_files(const char *name, FILE *fd_out) "the path."), name); } - strncat(tmpdir, name, available_space); + strcat(tmpdir, name); available_space -= strlen(name); G_file_name(mon_path, tmpdir, NULL, G_mapset()); From 05e9f80013249b1e39782296f692273a1a3df614 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Thu, 5 Sep 2024 20:42:43 -0400 Subject: [PATCH 06/11] changes --- display/d.mon/list.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index c5f38615f38..84e58f5d228 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -16,13 +16,20 @@ char *get_path(const char *name, int fpath) G_temp_element(tmpdir); available_space = GPATH_MAX - strlen(tmpdir) - 1; - if (available_space < strlen("/MONITORS")) { + if (available_space < strlen("/")) { + G_fatal_error( + _("Insufficient space to append / to the path for <%s>."), + name); + } + strcat(tmpdir, "/"); + available_space -= strlen("/"); + if (available_space < strlen("MONITORS")) { G_fatal_error( - _("Insufficient space to append /MONITORS to the path for <%s>."), + _("Insufficient space to append MONITORS to the path for <%s>."), name); } - strcat(tmpdir, "/MONITORS"); - available_space -= strlen("/MONITORS"); + strcat(tmpdir, "MONITORS"); + available_space -= strlen("MONITORS"); if (name) { if (available_space < strlen("/")) { G_fatal_error( @@ -154,13 +161,20 @@ void list_files(const char *name, FILE *fd_out) G_temp_element(tmpdir); available_space = GPATH_MAX - strlen(tmpdir) - 1; - if (available_space < strlen("/MONITORS")) { + if (available_space < strlen("/")) { + G_fatal_error( + _("Insufficient space to append / to the path for <%s>."), + name); + } + strcat(tmpdir, "/"); + available_space -= strlen("/"); + if (available_space < strlen("MONITORS")) { G_fatal_error( - _("Insufficient space to append /MONITORS to the path for <%s>."), + _("Insufficient space to append MONITORS to the path for <%s>."), name); } - strcat(tmpdir, "/MONITORS"); - available_space -= strlen("/MONITORS"); + strcat(tmpdir, "MONITORS"); + available_space -= strlen("MONITORS"); if (available_space < strlen("/")) { G_fatal_error(_("Insufficient space to append / to the path for <%s>."), From 9dc9fb3424ad2f8194827cbe1196b9900a3d0bd6 Mon Sep 17 00:00:00 2001 From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com> Date: Thu, 5 Sep 2024 20:45:05 -0400 Subject: [PATCH 07/11] Update display/d.mon/list.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- display/d.mon/list.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index 84e58f5d228..91d38986979 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -162,9 +162,8 @@ void list_files(const char *name, FILE *fd_out) G_temp_element(tmpdir); available_space = GPATH_MAX - strlen(tmpdir) - 1; if (available_space < strlen("/")) { - G_fatal_error( - _("Insufficient space to append / to the path for <%s>."), - name); + G_fatal_error(_("Insufficient space to append / to the path for <%s>."), + name); } strcat(tmpdir, "/"); available_space -= strlen("/"); From 80c514eb0d29320e781f97dce9c59b3308f3d7da Mon Sep 17 00:00:00 2001 From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com> Date: Thu, 5 Sep 2024 20:45:13 -0400 Subject: [PATCH 08/11] Update display/d.mon/list.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- display/d.mon/list.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index 91d38986979..db4411138a6 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -17,9 +17,8 @@ char *get_path(const char *name, int fpath) G_temp_element(tmpdir); available_space = GPATH_MAX - strlen(tmpdir) - 1; if (available_space < strlen("/")) { - G_fatal_error( - _("Insufficient space to append / to the path for <%s>."), - name); + G_fatal_error(_("Insufficient space to append / to the path for <%s>."), + name); } strcat(tmpdir, "/"); available_space -= strlen("/"); From f04df52e62d76f37a93e987f0b98351836924d14 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Thu, 5 Sep 2024 21:48:34 -0400 Subject: [PATCH 09/11] updated code --- display/d.mon/list.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index 84e58f5d228..7b6071eab40 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -12,7 +12,7 @@ char *get_path(const char *name, int fpath) { char tmpdir[GPATH_MAX]; - int available_space; + size_t available_space; G_temp_element(tmpdir); available_space = GPATH_MAX - strlen(tmpdir) - 1; @@ -157,7 +157,7 @@ void list_files(const char *name, FILE *fd_out) char tmpdir[GPATH_MAX], mon_path[GPATH_MAX]; struct dirent *dp; DIR *dirp; - int available_space; + size_t available_space; G_temp_element(tmpdir); available_space = GPATH_MAX - strlen(tmpdir) - 1; From de760d86d601fdd7afa97faf57daa174a23f747d Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Mon, 16 Sep 2024 16:37:01 -0400 Subject: [PATCH 10/11] used G_strlcat --- display/d.mon/list.c | 66 +++++++++++--------------------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index aaa299096f6..f60d3529dbc 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -12,39 +12,21 @@ char *get_path(const char *name, int fpath) { char tmpdir[GPATH_MAX]; - size_t available_space; G_temp_element(tmpdir); - available_space = GPATH_MAX - strlen(tmpdir) - 1; - if (available_space < strlen("/")) { - G_fatal_error(_("Insufficient space to append / to the path for <%s>."), - name); + if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) { + G_fatal_error(_("Failed to append '/' to path")); } - strcat(tmpdir, "/"); - available_space -= strlen("/"); - if (available_space < strlen("MONITORS")) { - G_fatal_error( - _("Insufficient space to append MONITORS to the path for <%s>."), - name); + if (G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir)) >= sizeof(tmpdir)) { + G_fatal_error(_("Failed to append 'MONITORS' to path")); } - strcat(tmpdir, "MONITORS"); - available_space -= strlen("MONITORS"); if (name) { - if (available_space < strlen("/")) { - G_fatal_error( - _("Insufficient space to append / to the path for <%s>."), - name); + if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) { + G_fatal_error(_("Failed to append '/' to path")); } - strcat(tmpdir, "/"); - available_space -= strlen("/"); - - if (available_space < strlen(name)) { - G_fatal_error(_("Insufficient space to append the monitor name " - "<%s> to the path."), - name); + if (G_strlcat(tmpdir, name, sizeof(tmpdir)) >= sizeof(tmpdir)) { + G_fatal_error(_("Failed to append <%s> to path"), name); } - strcat(tmpdir, name); - available_space -= strlen(name); } if (fpath) { @@ -156,38 +138,22 @@ void list_files(const char *name, FILE *fd_out) char tmpdir[GPATH_MAX], mon_path[GPATH_MAX]; struct dirent *dp; DIR *dirp; - size_t available_space; G_temp_element(tmpdir); - available_space = GPATH_MAX - strlen(tmpdir) - 1; - if (available_space < strlen("/")) { - G_fatal_error(_("Insufficient space to append / to the path for <%s>."), - name); + if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) { + G_fatal_error(_("Failed to append '/' to path")); } - strcat(tmpdir, "/"); - available_space -= strlen("/"); - if (available_space < strlen("MONITORS")) { - G_fatal_error( - _("Insufficient space to append MONITORS to the path for <%s>."), - name); + if (G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir)) >= sizeof(tmpdir)) { + G_fatal_error(_("Failed to append 'MONITORS' to path")); } - strcat(tmpdir, "MONITORS"); - available_space -= strlen("MONITORS"); - if (available_space < strlen("/")) { - G_fatal_error(_("Insufficient space to append / to the path for <%s>."), - name); + if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) { + G_fatal_error(_("Failed to append '/' to path")); } - strcat(tmpdir, "/"); - available_space -= strlen("/"); - if (available_space < strlen(name)) { - G_fatal_error(_("Insufficient space to append the monitor name <%s> to " - "the path."), - name); + if (G_strlcat(tmpdir, name, sizeof(tmpdir)) >= sizeof(tmpdir)) { + G_fatal_error(_("Failed to append <%s> to path"), name); } - strcat(tmpdir, name); - available_space -= strlen(name); G_file_name(mon_path, tmpdir, NULL, G_mapset()); fprintf(fd_out, "path=%s\n", mon_path); From 74b88c466bd9a3d6dc22628bdf43ed849e360036 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Wed, 18 Sep 2024 19:07:30 -0400 Subject: [PATCH 11/11] Requested changes for G_strlcat --- display/d.mon/list.c | 25 ++++++------------------- display/d.mon/main.c | 8 ++------ 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/display/d.mon/list.c b/display/d.mon/list.c index f60d3529dbc..c61c1081991 100644 --- a/display/d.mon/list.c +++ b/display/d.mon/list.c @@ -14,16 +14,10 @@ char *get_path(const char *name, int fpath) char tmpdir[GPATH_MAX]; G_temp_element(tmpdir); - if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) { - G_fatal_error(_("Failed to append '/' to path")); - } - if (G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir)) >= sizeof(tmpdir)) { - G_fatal_error(_("Failed to append 'MONITORS' to path")); - } + (void)G_strlcat(tmpdir, "/", sizeof(tmpdir)); + (void)G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir)); if (name) { - if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) { - G_fatal_error(_("Failed to append '/' to path")); - } + (void)G_strlcat(tmpdir, "/", sizeof(tmpdir)); if (G_strlcat(tmpdir, name, sizeof(tmpdir)) >= sizeof(tmpdir)) { G_fatal_error(_("Failed to append <%s> to path"), name); } @@ -140,16 +134,9 @@ void list_files(const char *name, FILE *fd_out) DIR *dirp; G_temp_element(tmpdir); - if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) { - G_fatal_error(_("Failed to append '/' to path")); - } - if (G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir)) >= sizeof(tmpdir)) { - G_fatal_error(_("Failed to append 'MONITORS' to path")); - } - - if (G_strlcat(tmpdir, "/", sizeof(tmpdir)) >= sizeof(tmpdir)) { - G_fatal_error(_("Failed to append '/' to path")); - } + (void)G_strlcat(tmpdir, "/", sizeof(tmpdir)); + (void)G_strlcat(tmpdir, "MONITORS", sizeof(tmpdir)); + (void)G_strlcat(tmpdir, "/", sizeof(tmpdir)); if (G_strlcat(tmpdir, name, sizeof(tmpdir)) >= sizeof(tmpdir)) { G_fatal_error(_("Failed to append <%s> to path"), name); diff --git a/display/d.mon/main.c b/display/d.mon/main.c index 6e93a8c89ea..11c832ac56c 100644 --- a/display/d.mon/main.c +++ b/display/d.mon/main.c @@ -176,7 +176,7 @@ int main(int argc, char *argv[]) if (list_flag->answer) G_warning(_("Flag -%c ignored"), list_flag->key); mon = G_getenv_nofatal("MONITOR"); - if (mon && strlen(mon) < GNAME_MAX) { + if (mon) { if (selected_flag->answer) { G_verbose_message(_("Currently selected monitor:")); fprintf(stdout, "%s\n", mon); @@ -194,12 +194,8 @@ int main(int argc, char *argv[]) ret = stop_mon(mon); } } - else if (!mon) { + else G_important_message(_("No monitor selected")); - } - else { - G_important_message(_("Monitor name is too long")); - } exit(EXIT_SUCCESS); }