aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/firejail/util.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c
index 05c5f26d8..7ee83a13e 100644
--- a/src/firejail/util.c
+++ b/src/firejail/util.c
@@ -49,22 +49,28 @@
49#define EMPTY_STRING ("") 49#define EMPTY_STRING ("")
50 50
51 51
52long long unsigned parse_arg_size (char * str) { 52long long unsigned parse_arg_size(char *str) {
53 long long unsigned result = 0; 53 long long unsigned result = 0;
54 int len = strlen(str); 54 int len = strlen(str);
55 sscanf(str,"%llu",&result); 55 sscanf(str, "%llu", &result);
56 56
57 char suffix = *(str + len - 1); 57 char suffix = *(str + len - 1);
58 if (!isdigit(suffix)) { 58 if (isdigit(suffix))
59 if ( suffix == 'k' ) { 59 return result;
60 result *= 1024; 60
61 } else if ( suffix == 'm' ) { 61 switch (result) {
62 result *= 1024*1024; 62 case 'k':
63 } else if ( suffix == 'g' ) { 63 result *= 1024;
64 result *= 1024*1024*1024; 64 break;
65 } else { 65 case 'm':
66 return 0; 66 result *= 1024 * 1024;
67 } 67 break;
68 case 'g':
69 result *= 1024 * 1024 * 1024;
70 break;
71 default:
72 result = 0;
73 break;
68 } 74 }
69 75
70 return result; 76 return result;