fdisk: remove stack jumping
PATCH 1/4 fdisk: remove stack jumping
From: Davidlohr Bueso <[email protected]>
This patch eliminates the long/setjmp code. The current logic does not do anything with stack jumps as it only exits from print_partition_table_from_option() when a fatal error occurs.
Signed-off-by Davidlohr Bueso <[email protected]>
--- fdisk/fdisk.c | 17 ++--------------- 1 files changed, 2 insertions(+), 15 deletions(-)
fdisk/fdisk.c +2 -15
@@ -14,7 +14,6 @@#include <string.h> #include <fcntl.h> #include <ctype.h> -#include <setjmp.h> #include <errno.h> #include <getopt.h> #include <sys/stat.h>
@@ -245,8 +244,6 @@ int has_topology;enum labeltype disklabel;/* Current disklabel */ -jmp_buf listingbuf; -static void __attribute__ ((__noreturn__))usage (FILE *out) { fprintf(out, _("Usage:\n"
@@ -266,13 +263,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)exit (out == stderr ?EXIT_FAILURE :EXIT_SUCCESS ); } -void fatal (enum failure why) { - -if (listing) { -close (fd); -longjmp (listingbuf,1 ); - } - +void fatal (enum failure why) +{switch (why) {case unable_to_open:err (EXIT_FAILURE ,_ ("unable to open %s" ), disk_device);
@@ -2708,8 +2700,6 @@ print_partition_table_from_option(char *device)int gb; disk_device = device; -if (setjmp (listingbuf)) -return ;gpt_warning (device); gb =get_boot (1 );if (gb <0 ) {/* no DOS signature */
@@ -2950,9 +2940,6 @@ main(int argc, char **argv) { nowarn =1 ;if (argc > optind) {int k; -/* avoid gcc warning: -variable `k' might be clobbered by `longjmp' */ -dummy (&k); listing =1 ;for (k = optind; k < argc; k++)print_partition_table_from_option (argv[k]);
Signature · 1 line
1.7.4.1
Quoted 5 lines · Davidlohr Bueso
From: Davidlohr Bueso <[email protected]>
This patch eliminates the long/setjmp code. The current logic does not do anything with stack jumps as it only exits from
print_partition_table_from_option()when a fatal error occurs.
The stack jumping makes fdisk remain silent and return success (!) if the listing fails on any of the devices. Not that I think this is useful behavior, but IMHO this change in behavior is worth mentioning in the release notes.
Reviewed-by Petr Uzel <[email protected]>
Quoted 71 lines
Signed-off-by Davidlohr Bueso <[email protected]>--- fdisk/fdisk.c | 17 ++--------------- 1 files changed, 2 insertions(+), 15 deletions(-)fdisk/fdisk.c +2
-15@@ -14,7 +14,6 @@#include <string.h> #include <fcntl.h> #include <ctype.h> -#include <setjmp.h> #include <errno.h> #include <getopt.h> #include <sys/stat.h> @@ -245,8 +244,6 @@ int has_topology;enum labeltype disklabel;/* Current disklabel */ -jmp_buf listingbuf; -static void __attribute__ ((__noreturn__))usage (FILE *out) { fprintf(out, _("Usage:\n"@@ -266,13 +263,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)exit (out == stderr ?EXIT_FAILURE :EXIT_SUCCESS ); } -void fatal (enum failure why) { - -if (listing) { -close (fd); -longjmp (listingbuf,1 ); - } - +void fatal (enum failure why) +{switch (why) {case unable_to_open:err (EXIT_FAILURE ,_ ("unable to open %s" ), disk_device);@@ -2708,8 +2700,6 @@ print_partition_table_from_option(char *device)int gb; disk_device = device; -if (setjmp (listingbuf)) -return ;gpt_warning (device); gb =get_boot (1 );if (gb <0 ) {/* no DOS signature */ @@ -2950,9 +2940,6 @@ main(int argc, char **argv) { nowarn =1 ;if (argc > optind) {int k; -/* avoid gcc warning: -variable `k' might be clobbered by `longjmp' */ -dummy (&k); listing =1 ;for (k = optind; k < argc; k++)print_partition_table_from_option (argv[k]);Signature · 9 lines
1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Petr
Signature · 2 lines
Petr Uzel IRC: ptr_uzl @ freenode
Quoted 2 lines · Davidlohr Bueso
fdisk/fdisk.c | 17 ++--------------- 1 files changed, 2 insertions(+), 15 deletions(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com