diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-08 12:49:22 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-08 12:49:22 +0000 |
commit | 87d25a2b8535dc627a02eb539fa3946be2a24647 (patch) | |
tree | fc4d14a910593d1235318bb36abe5e9f72d2039e | |
parent | 81177b14907e73f11560f69e0b4ec34371f1a7d5 (diff) | |
download | busybox-w32-87d25a2b8535dc627a02eb539fa3946be2a24647.tar.gz busybox-w32-87d25a2b8535dc627a02eb539fa3946be2a24647.tar.bz2 busybox-w32-87d25a2b8535dc627a02eb539fa3946be2a24647.zip |
attempt to regularize atoi mess.
git-svn-id: svn://busybox.net/trunk/busybox@16342 69ca8d6d-28ef-0310-b511-8ec308f3f277
98 files changed, 803 insertions, 849 deletions
@@ -296,9 +296,6 @@ Minor stuff: | |||
296 | --- | 296 | --- |
297 | possible code duplication ingroup() and is_a_group_member() | 297 | possible code duplication ingroup() and is_a_group_member() |
298 | --- | 298 | --- |
299 | unify itoa: netstat.c, hush.c, lash.c, msh.c | ||
300 | Put one single, robust version into e.g. safe_strtol.c | ||
301 | --- | ||
302 | Move __get_hz() to a better place and (re)use it in route.c, ash.c, msh.c | 299 | Move __get_hz() to a better place and (re)use it in route.c, ash.c, msh.c |
303 | --- | 300 | --- |
304 | 301 | ||
diff --git a/applets/applets.c b/applets/applets.c index b1f580953..5d8b80881 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
@@ -264,8 +264,8 @@ static void parse_config_file(void) | |||
264 | 264 | ||
265 | sct->m_uid = strtoul(s, &e2, 10); | 265 | sct->m_uid = strtoul(s, &e2, 10); |
266 | if (*e2 || (s == e2)) { | 266 | if (*e2 || (s == e2)) { |
267 | struct passwd *pwd; | 267 | struct passwd *pwd = getpwnam(s); |
268 | if (!(pwd = getpwnam(s))) { | 268 | if (!pwd) { |
269 | parse_error("user"); | 269 | parse_error("user"); |
270 | } | 270 | } |
271 | sct->m_uid = pwd->pw_uid; | 271 | sct->m_uid = pwd->pw_uid; |
diff --git a/archival/cpio.c b/archival/cpio.c index d0d3288ff..751e87952 100644 --- a/archival/cpio.c +++ b/archival/cpio.c | |||
@@ -35,7 +35,7 @@ int cpio_main(int argc, char **argv) | |||
35 | /* Initialise */ | 35 | /* Initialise */ |
36 | archive_handle = init_handle(); | 36 | archive_handle = init_handle(); |
37 | archive_handle->src_fd = STDIN_FILENO; | 37 | archive_handle->src_fd = STDIN_FILENO; |
38 | archive_handle->seek = seek_by_char; | 38 | archive_handle->seek = seek_by_read; |
39 | archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE; | 39 | archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE; |
40 | 40 | ||
41 | opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename); | 41 | opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename); |
diff --git a/archival/libunarchive/Kbuild b/archival/libunarchive/Kbuild index c5f1bfbfe..4e1454184 100644 --- a/archival/libunarchive/Kbuild +++ b/archival/libunarchive/Kbuild | |||
@@ -21,7 +21,7 @@ lib-y:= \ | |||
21 | \ | 21 | \ |
22 | archive_xread_all_eof.o \ | 22 | archive_xread_all_eof.o \ |
23 | \ | 23 | \ |
24 | seek_by_char.o \ | 24 | seek_by_read.o \ |
25 | seek_by_jump.o \ | 25 | seek_by_jump.o \ |
26 | \ | 26 | \ |
27 | data_align.o \ | 27 | data_align.o \ |
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c index cabb4101b..7372ada32 100644 --- a/archival/libunarchive/get_header_ar.c +++ b/archival/libunarchive/get_header_ar.c | |||
@@ -46,14 +46,14 @@ char get_header_ar(archive_handle_t *archive_handle) | |||
46 | 46 | ||
47 | /* align the headers based on the header magic */ | 47 | /* align the headers based on the header magic */ |
48 | if ((ar.formatted.magic[0] != '`') || (ar.formatted.magic[1] != '\n')) { | 48 | if ((ar.formatted.magic[0] != '`') || (ar.formatted.magic[1] != '\n')) { |
49 | bb_error_msg_and_die("Invalid ar header"); | 49 | bb_error_msg_and_die("invalid ar header"); |
50 | } | 50 | } |
51 | 51 | ||
52 | typed->mode = strtol(ar.formatted.mode, NULL, 8); | 52 | typed->mode = xstrtoul(ar.formatted.mode, 8); |
53 | typed->mtime = atoi(ar.formatted.date); | 53 | typed->mtime = xatou(ar.formatted.date); |
54 | typed->uid = atoi(ar.formatted.uid); | 54 | typed->uid = xatou(ar.formatted.uid); |
55 | typed->gid = atoi(ar.formatted.gid); | 55 | typed->gid = xatou(ar.formatted.gid); |
56 | typed->size = atoi(ar.formatted.size); | 56 | typed->size = xatoul(ar.formatted.size); |
57 | 57 | ||
58 | /* long filenames have '/' as the first character */ | 58 | /* long filenames have '/' as the first character */ |
59 | if (ar.formatted.name[0] == '/') { | 59 | if (ar.formatted.name[0] == '/') { |
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index 0c622f44a..d3cd96d0c 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -62,10 +62,10 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
62 | * Read until the end to empty the pipe from gz or bz2 | 62 | * Read until the end to empty the pipe from gz or bz2 |
63 | */ | 63 | */ |
64 | while (full_read(archive_handle->src_fd, tar.raw, 512) == 512); | 64 | while (full_read(archive_handle->src_fd, tar.raw, 512) == 512); |
65 | return(EXIT_FAILURE); | 65 | return EXIT_FAILURE; |
66 | } | 66 | } |
67 | end = 1; | 67 | end = 1; |
68 | return(EXIT_SUCCESS); | 68 | return EXIT_SUCCESS; |
69 | } | 69 | } |
70 | end = 0; | 70 | end = 0; |
71 | 71 | ||
@@ -76,19 +76,18 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
76 | #ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY | 76 | #ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY |
77 | if (strncmp(tar.formatted.magic, "\0\0\0\0\0", 5) != 0) | 77 | if (strncmp(tar.formatted.magic, "\0\0\0\0\0", 5) != 0) |
78 | #endif | 78 | #endif |
79 | bb_error_msg_and_die("Invalid tar magic"); | 79 | bb_error_msg_and_die("invalid tar magic"); |
80 | } | 80 | } |
81 | /* Do checksum on headers */ | 81 | /* Do checksum on headers */ |
82 | for (i = 0; i < 148 ; i++) { | 82 | for (i = 0; i < 148 ; i++) { |
83 | sum += tar.raw[i]; | 83 | sum += tar.raw[i]; |
84 | } | 84 | } |
85 | sum += ' ' * 8; | 85 | sum += ' ' * 8; |
86 | for (i = 156; i < 512 ; i++) { | 86 | for (i = 156; i < 512 ; i++) { |
87 | sum += tar.raw[i]; | 87 | sum += tar.raw[i]; |
88 | } | 88 | } |
89 | if (sum != strtol(tar.formatted.chksum, NULL, 8)) { | 89 | if (sum != xstrtoul(tar.formatted.chksum, 8)) { |
90 | bb_error_msg("Invalid tar header checksum"); | 90 | bb_error_msg_and_die("invalid tar header checksum"); |
91 | return(EXIT_FAILURE); | ||
92 | } | 91 | } |
93 | 92 | ||
94 | #ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS | 93 | #ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS |
@@ -102,8 +101,7 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
102 | } else | 101 | } else |
103 | #endif | 102 | #endif |
104 | { | 103 | { |
105 | file_header->name = xstrndup(tar.formatted.name,100); | 104 | file_header->name = xstrndup(tar.formatted.name, 100); |
106 | |||
107 | if (tar.formatted.prefix[0]) { | 105 | if (tar.formatted.prefix[0]) { |
108 | char *temp = file_header->name; | 106 | char *temp = file_header->name; |
109 | file_header->name = concat_path_file(tar.formatted.prefix, temp); | 107 | file_header->name = concat_path_file(tar.formatted.prefix, temp); |
@@ -111,17 +109,18 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
111 | } | 109 | } |
112 | } | 110 | } |
113 | 111 | ||
114 | file_header->uid = strtol(tar.formatted.uid, NULL, 8); | 112 | file_header->uid = xstrtoul(tar.formatted.uid, 8); |
115 | file_header->gid = strtol(tar.formatted.gid, NULL, 8); | 113 | file_header->gid = xstrtoul(tar.formatted.gid, 8); |
116 | file_header->size = strtol(tar.formatted.size, NULL, 8); | 114 | // TODO: LFS support |
117 | file_header->mtime = strtol(tar.formatted.mtime, NULL, 8); | 115 | file_header->size = xstrtoul(tar.formatted.size, 8); |
118 | file_header->link_name = (tar.formatted.linkname[0] != '\0') ? | 116 | file_header->mtime = xstrtoul(tar.formatted.mtime, 8); |
119 | xstrdup(tar.formatted.linkname) : NULL; | 117 | file_header->link_name = tar.formatted.linkname[0] ? |
120 | file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8), | 118 | xstrdup(tar.formatted.linkname) : NULL; |
121 | strtol(tar.formatted.devminor, NULL, 8)); | 119 | file_header->device = makedev(xstrtoul(tar.formatted.devmajor, 8), |
120 | xstrtoul(tar.formatted.devminor, 8)); | ||
122 | 121 | ||
123 | /* Set bits 0-11 of the files mode */ | 122 | /* Set bits 0-11 of the files mode */ |
124 | file_header->mode = 07777 & strtol(tar.formatted.mode, NULL, 8); | 123 | file_header->mode = 07777 & xstrtoul(tar.formatted.mode, 8); |
125 | 124 | ||
126 | /* Set bits 12-15 of the files mode */ | 125 | /* Set bits 12-15 of the files mode */ |
127 | switch (tar.formatted.typeflag) { | 126 | switch (tar.formatted.typeflag) { |
@@ -161,7 +160,7 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
161 | xread(archive_handle->src_fd, longname, file_header->size); | 160 | xread(archive_handle->src_fd, longname, file_header->size); |
162 | archive_handle->offset += file_header->size; | 161 | archive_handle->offset += file_header->size; |
163 | 162 | ||
164 | return(get_header_tar(archive_handle)); | 163 | return get_header_tar(archive_handle); |
165 | } | 164 | } |
166 | case 'K': { | 165 | case 'K': { |
167 | linkname = xzalloc(file_header->size + 1); | 166 | linkname = xzalloc(file_header->size + 1); |
@@ -169,7 +168,7 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
169 | archive_handle->offset += file_header->size; | 168 | archive_handle->offset += file_header->size; |
170 | 169 | ||
171 | file_header->name = linkname; | 170 | file_header->name = linkname; |
172 | return(get_header_tar(archive_handle)); | 171 | return get_header_tar(archive_handle); |
173 | } | 172 | } |
174 | case 'D': /* GNU dump dir */ | 173 | case 'D': /* GNU dump dir */ |
175 | case 'M': /* Continuation of multi volume archive*/ | 174 | case 'M': /* Continuation of multi volume archive*/ |
@@ -179,10 +178,10 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
179 | #endif | 178 | #endif |
180 | case 'g': /* pax global header */ | 179 | case 'g': /* pax global header */ |
181 | case 'x': /* pax extended header */ | 180 | case 'x': /* pax extended header */ |
182 | bb_error_msg("Ignoring extension type %c", tar.formatted.typeflag); | 181 | bb_error_msg("ignoring extension type %c", tar.formatted.typeflag); |
183 | break; | 182 | break; |
184 | default: | 183 | default: |
185 | bb_error_msg("Unknown typeflag: 0x%x", tar.formatted.typeflag); | 184 | bb_error_msg("unknown typeflag: 0x%x", tar.formatted.typeflag); |
186 | } | 185 | } |
187 | { /* Strip trailing '/' in directories */ | 186 | { /* Strip trailing '/' in directories */ |
188 | /* Must be done after mode is set as '/' is used to check if its a directory */ | 187 | /* Must be done after mode is set as '/' is used to check if its a directory */ |
@@ -204,5 +203,5 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
204 | 203 | ||
205 | free(file_header->link_name); | 204 | free(file_header->link_name); |
206 | 205 | ||
207 | return(EXIT_SUCCESS); | 206 | return EXIT_SUCCESS; |
208 | } | 207 | } |
diff --git a/archival/libunarchive/get_header_tar_bz2.c b/archival/libunarchive/get_header_tar_bz2.c index a8b630814..e3cb328fc 100644 --- a/archival/libunarchive/get_header_tar_bz2.c +++ b/archival/libunarchive/get_header_tar_bz2.c | |||
@@ -16,12 +16,12 @@ | |||
16 | char get_header_tar_bz2(archive_handle_t *archive_handle) | 16 | char get_header_tar_bz2(archive_handle_t *archive_handle) |
17 | { | 17 | { |
18 | /* Cant lseek over pipe's */ | 18 | /* Cant lseek over pipe's */ |
19 | archive_handle->seek = seek_by_char; | 19 | archive_handle->seek = seek_by_read; |
20 | 20 | ||
21 | archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream); | 21 | archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream); |
22 | archive_handle->offset = 0; | 22 | archive_handle->offset = 0; |
23 | while (get_header_tar(archive_handle) == EXIT_SUCCESS); | 23 | while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; |
24 | 24 | ||
25 | /* Can only do one file at a time */ | 25 | /* Can only do one file at a time */ |
26 | return(EXIT_FAILURE); | 26 | return EXIT_FAILURE; |
27 | } | 27 | } |
diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c index 24e4f9c9f..af059a187 100644 --- a/archival/libunarchive/get_header_tar_gz.c +++ b/archival/libunarchive/get_header_tar_gz.c | |||
@@ -13,7 +13,7 @@ char get_header_tar_gz(archive_handle_t *archive_handle) | |||
13 | unsigned char magic[2]; | 13 | unsigned char magic[2]; |
14 | 14 | ||
15 | /* Cant lseek over pipe's */ | 15 | /* Cant lseek over pipe's */ |
16 | archive_handle->seek = seek_by_char; | 16 | archive_handle->seek = seek_by_read; |
17 | 17 | ||
18 | xread(archive_handle->src_fd, &magic, 2); | 18 | xread(archive_handle->src_fd, &magic, 2); |
19 | if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { | 19 | if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { |
@@ -24,8 +24,8 @@ char get_header_tar_gz(archive_handle_t *archive_handle) | |||
24 | 24 | ||
25 | archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip); | 25 | archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip); |
26 | archive_handle->offset = 0; | 26 | archive_handle->offset = 0; |
27 | while (get_header_tar(archive_handle) == EXIT_SUCCESS); | 27 | while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; |
28 | 28 | ||
29 | /* Can only do one file at a time */ | 29 | /* Can only do one file at a time */ |
30 | return(EXIT_FAILURE); | 30 | return EXIT_FAILURE; |
31 | } | 31 | } |
diff --git a/archival/libunarchive/get_header_tar_lzma.c b/archival/libunarchive/get_header_tar_lzma.c index e38583fef..06b8daa0f 100644 --- a/archival/libunarchive/get_header_tar_lzma.c +++ b/archival/libunarchive/get_header_tar_lzma.c | |||
@@ -11,13 +11,12 @@ | |||
11 | char get_header_tar_lzma(archive_handle_t * archive_handle) | 11 | char get_header_tar_lzma(archive_handle_t * archive_handle) |
12 | { | 12 | { |
13 | /* Can't lseek over pipes */ | 13 | /* Can't lseek over pipes */ |
14 | archive_handle->seek = seek_by_char; | 14 | archive_handle->seek = seek_by_read; |
15 | 15 | ||
16 | archive_handle->src_fd = open_transformer(archive_handle->src_fd, unlzma); | 16 | archive_handle->src_fd = open_transformer(archive_handle->src_fd, unlzma); |
17 | archive_handle->offset = 0; | 17 | archive_handle->offset = 0; |
18 | while (get_header_tar(archive_handle) == EXIT_SUCCESS); | 18 | while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; |
19 | 19 | ||
20 | /* Can only do one file at a time */ | 20 | /* Can only do one file at a time */ |
21 | return EXIT_FAILURE; | 21 | return EXIT_FAILURE; |
22 | } | 22 | } |
23 | |||
diff --git a/archival/libunarchive/seek_by_jump.c b/archival/libunarchive/seek_by_jump.c index 231360fa3..e1917dd2a 100644 --- a/archival/libunarchive/seek_by_jump.c +++ b/archival/libunarchive/seek_by_jump.c | |||
@@ -16,7 +16,7 @@ void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amo | |||
16 | if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) { | 16 | if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) { |
17 | #ifdef CONFIG_FEATURE_UNARCHIVE_TAPE | 17 | #ifdef CONFIG_FEATURE_UNARCHIVE_TAPE |
18 | if (errno == ESPIPE) { | 18 | if (errno == ESPIPE) { |
19 | seek_by_char(archive_handle, amount); | 19 | seek_by_read(archive_handle, amount); |
20 | } else | 20 | } else |
21 | #endif | 21 | #endif |
22 | bb_perror_msg_and_die("Seek failure"); | 22 | bb_perror_msg_and_die("Seek failure"); |
diff --git a/archival/libunarchive/seek_by_char.c b/archival/libunarchive/seek_by_read.c index f4d8c2f2b..03cbb9ecc 100644 --- a/archival/libunarchive/seek_by_char.c +++ b/archival/libunarchive/seek_by_read.c | |||
@@ -8,14 +8,10 @@ | |||
8 | #include "unarchive.h" | 8 | #include "unarchive.h" |
9 | #include "libbb.h" | 9 | #include "libbb.h" |
10 | 10 | ||
11 | 11 | /* If we are reading through a pipe(), or from stdin then we cant lseek, | |
12 | |||
13 | /* If we are reading through a pipe(), or from stdin then we cant lseek, | ||
14 | * we must read and discard the data to skip over it. | 12 | * we must read and discard the data to skip over it. |
15 | * | ||
16 | * TODO: rename to seek_by_read | ||
17 | */ | 13 | */ |
18 | void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size) | 14 | void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size) |
19 | { | 15 | { |
20 | if (jump_size) { | 16 | if (jump_size) { |
21 | bb_copyfd_size(archive_handle->src_fd, -1, jump_size); | 17 | bb_copyfd_size(archive_handle->src_fd, -1, jump_size); |
diff --git a/archival/rpm.c b/archival/rpm.c index dc37e0edb..448a479a0 100644 --- a/archival/rpm.c +++ b/archival/rpm.c | |||
@@ -173,7 +173,7 @@ static void extract_cpio_gz(int fd) { | |||
173 | 173 | ||
174 | /* Initialise */ | 174 | /* Initialise */ |
175 | archive_handle = init_handle(); | 175 | archive_handle = init_handle(); |
176 | archive_handle->seek = seek_by_char; | 176 | archive_handle->seek = seek_by_read; |
177 | //archive_handle->action_header = header_list; | 177 | //archive_handle->action_header = header_list; |
178 | archive_handle->action_data = data_extract_all; | 178 | archive_handle->action_data = data_extract_all; |
179 | archive_handle->flags |= ARCHIVE_PRESERVE_DATE; | 179 | archive_handle->flags |= ARCHIVE_PRESERVE_DATE; |
diff --git a/archival/tar.c b/archival/tar.c index 3775598cc..b2ae3b2af 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -541,7 +541,7 @@ static llist_t *append_file_list_to_list(llist_t *list) | |||
541 | static char get_header_tar_Z(archive_handle_t *archive_handle) | 541 | static char get_header_tar_Z(archive_handle_t *archive_handle) |
542 | { | 542 | { |
543 | /* Cant lseek over pipe's */ | 543 | /* Cant lseek over pipe's */ |
544 | archive_handle->seek = seek_by_char; | 544 | archive_handle->seek = seek_by_read; |
545 | 545 | ||
546 | /* do the decompression, and cleanup */ | 546 | /* do the decompression, and cleanup */ |
547 | if (xread_char(archive_handle->src_fd) != 0x1f || | 547 | if (xread_char(archive_handle->src_fd) != 0x1f || |
@@ -805,7 +805,7 @@ int tar_main(int argc, char **argv) | |||
805 | 805 | ||
806 | if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) { | 806 | if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) { |
807 | tar_handle->src_fd = fileno(tar_stream); | 807 | tar_handle->src_fd = fileno(tar_stream); |
808 | tar_handle->seek = seek_by_char; | 808 | tar_handle->seek = seek_by_read; |
809 | } else { | 809 | } else { |
810 | tar_handle->src_fd = xopen3(tar_filename, flags, 0666); | 810 | tar_handle->src_fd = xopen3(tar_filename, flags, 0666); |
811 | } | 811 | } |
diff --git a/archival/unzip.c b/archival/unzip.c index f63925739..f70baebf9 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -51,11 +51,12 @@ typedef union { | |||
51 | } formatted ATTRIBUTE_PACKED; | 51 | } formatted ATTRIBUTE_PACKED; |
52 | } zip_header_t; | 52 | } zip_header_t; |
53 | 53 | ||
54 | /* This one never works with LARGEFILE-sized skips */ | ||
54 | static void unzip_skip(int fd, off_t skip) | 55 | static void unzip_skip(int fd, off_t skip) |
55 | { | 56 | { |
56 | if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) { | 57 | if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) { |
57 | if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) { | 58 | if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) { |
58 | bb_error_msg_and_die("Seek failure"); | 59 | bb_error_msg_and_die("seek failure"); |
59 | } | 60 | } |
60 | } | 61 | } |
61 | } | 62 | } |
@@ -65,7 +66,7 @@ static void unzip_create_leading_dirs(char *fn) | |||
65 | /* Create all leading directories */ | 66 | /* Create all leading directories */ |
66 | char *name = xstrdup(fn); | 67 | char *name = xstrdup(fn); |
67 | if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) { | 68 | if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) { |
68 | bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */ | 69 | bb_error_msg_and_die("exiting"); /* bb_make_directory is noisy */ |
69 | } | 70 | } |
70 | free(name); | 71 | free(name); |
71 | } | 72 | } |
@@ -76,7 +77,7 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) | |||
76 | /* Method 0 - stored (not compressed) */ | 77 | /* Method 0 - stored (not compressed) */ |
77 | int size = zip_header->formatted.ucmpsize; | 78 | int size = zip_header->formatted.ucmpsize; |
78 | if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) { | 79 | if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) { |
79 | bb_error_msg_and_die("Cannot complete extraction"); | 80 | bb_error_msg_and_die("cannot complete extraction"); |
80 | } | 81 | } |
81 | 82 | ||
82 | } else { | 83 | } else { |
@@ -86,12 +87,12 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) | |||
86 | inflate_cleanup(); | 87 | inflate_cleanup(); |
87 | /* Validate decompression - crc */ | 88 | /* Validate decompression - crc */ |
88 | if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) { | 89 | if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) { |
89 | bb_error_msg("Invalid compressed data--crc error"); | 90 | bb_error_msg("invalid compressed data--%s error", "crc"); |
90 | return 1; | 91 | return 1; |
91 | } | 92 | } |
92 | /* Validate decompression - size */ | 93 | /* Validate decompression - size */ |
93 | if (zip_header->formatted.ucmpsize != gunzip_bytes_out) { | 94 | if (zip_header->formatted.ucmpsize != gunzip_bytes_out) { |
94 | bb_error_msg("Invalid compressed data--length error"); | 95 | bb_error_msg("invalid compressed data--%s error", "length"); |
95 | return 1; | 96 | return 1; |
96 | } | 97 | } |
97 | } | 98 | } |
diff --git a/console-tools/chvt.c b/console-tools/chvt.c index aff66e007..bbc5a9c31 100644 --- a/console-tools/chvt.c +++ b/console-tools/chvt.c | |||
@@ -7,11 +7,6 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdio.h> | ||
11 | #include <stdlib.h> | ||
12 | #include <fcntl.h> | ||
13 | #include <sys/types.h> | ||
14 | #include <sys/ioctl.h> | ||
15 | #include "busybox.h" | 10 | #include "busybox.h" |
16 | 11 | ||
17 | /* From <linux/vt.h> */ | 12 | /* From <linux/vt.h> */ |
@@ -29,7 +24,7 @@ int chvt_main(int argc, char **argv) | |||
29 | } | 24 | } |
30 | 25 | ||
31 | fd = get_console_fd(); | 26 | fd = get_console_fd(); |
32 | num = bb_xgetlarg(argv[1], 10, 0, INT_MAX); | 27 | num = xatoul_range(argv[1], 1, 63); |
33 | if ((-1 == ioctl(fd, VT_ACTIVATE, num)) | 28 | if ((-1 == ioctl(fd, VT_ACTIVATE, num)) |
34 | || (-1 == ioctl(fd, VT_WAITACTIVE, num))) { | 29 | || (-1 == ioctl(fd, VT_WAITACTIVE, num))) { |
35 | bb_perror_msg_and_die("ioctl"); | 30 | bb_perror_msg_and_die("ioctl"); |
diff --git a/console-tools/deallocvt.c b/console-tools/deallocvt.c index b2e8e2bef..cd581b1c8 100644 --- a/console-tools/deallocvt.c +++ b/console-tools/deallocvt.c | |||
@@ -10,11 +10,6 @@ | |||
10 | 10 | ||
11 | /* no options, no getopt */ | 11 | /* no options, no getopt */ |
12 | 12 | ||
13 | #include <stdlib.h> | ||
14 | #include <stdio.h> | ||
15 | #include <fcntl.h> | ||
16 | #include <sys/types.h> | ||
17 | #include <sys/ioctl.h> | ||
18 | #include "busybox.h" | 13 | #include "busybox.h" |
19 | 14 | ||
20 | /* From <linux/vt.h> */ | 15 | /* From <linux/vt.h> */ |
@@ -26,15 +21,13 @@ int deallocvt_main(int argc, char *argv[]) | |||
26 | int num = 0; | 21 | int num = 0; |
27 | 22 | ||
28 | switch (argc) { | 23 | switch (argc) { |
29 | case 2: | 24 | case 2: |
30 | if ((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0) { | 25 | num = xatoul_range(argv[1], 1, 63); |
31 | bb_error_msg_and_die("0: illegal VT number"); | ||
32 | } | ||
33 | /* Fallthrough */ | 26 | /* Fallthrough */ |
34 | case 1: | 27 | case 1: |
35 | break; | 28 | break; |
36 | default: | 29 | default: |
37 | bb_show_usage(); | 30 | bb_show_usage(); |
38 | } | 31 | } |
39 | 32 | ||
40 | if (-1 == ioctl(get_console_fd(), VT_DISALLOCATE, num)) { | 33 | if (-1 == ioctl(get_console_fd(), VT_DISALLOCATE, num)) { |
diff --git a/console-tools/openvt.c b/console-tools/openvt.c index 0c0cef23c..f1cf5645b 100644 --- a/console-tools/openvt.c +++ b/console-tools/openvt.c | |||
@@ -10,14 +10,6 @@ | |||
10 | 10 | ||
11 | /* getopt not needed */ | 11 | /* getopt not needed */ |
12 | 12 | ||
13 | #include <stdio.h> | ||
14 | #include <stdlib.h> | ||
15 | #include <unistd.h> | ||
16 | #include <fcntl.h> | ||
17 | #include <string.h> | ||
18 | #include <sys/types.h> | ||
19 | #include <ctype.h> | ||
20 | |||
21 | #include "busybox.h" | 13 | #include "busybox.h" |
22 | 14 | ||
23 | int openvt_main(int argc, char **argv) | 15 | int openvt_main(int argc, char **argv) |
@@ -29,8 +21,8 @@ int openvt_main(int argc, char **argv) | |||
29 | if (argc < 3) { | 21 | if (argc < 3) { |
30 | bb_show_usage(); | 22 | bb_show_usage(); |
31 | } | 23 | } |
32 | /* check for Illegal vt number: < 1 or > 12 */ | 24 | /* check for illegal vt number: < 1 or > 63 */ |
33 | sprintf(vtname, VC_FORMAT, (int)bb_xgetlarg(argv[1], 10, 1, 12)); | 25 | sprintf(vtname, VC_FORMAT, (int)xatoul_range(argv[1], 1, 63)); |
34 | 26 | ||
35 | if (fork() == 0) { | 27 | if (fork() == 0) { |
36 | /* leave current vt */ | 28 | /* leave current vt */ |
diff --git a/console-tools/setkeycodes.c b/console-tools/setkeycodes.c index 607b8c785..d82525786 100644 --- a/console-tools/setkeycodes.c +++ b/console-tools/setkeycodes.c | |||
@@ -27,7 +27,6 @@ enum { | |||
27 | extern int | 27 | extern int |
28 | setkeycodes_main(int argc, char** argv) | 28 | setkeycodes_main(int argc, char** argv) |
29 | { | 29 | { |
30 | char *ep; | ||
31 | int fd, sc; | 30 | int fd, sc; |
32 | struct kbkeycode a; | 31 | struct kbkeycode a; |
33 | 32 | ||
@@ -38,19 +37,13 @@ setkeycodes_main(int argc, char** argv) | |||
38 | fd = get_console_fd(); | 37 | fd = get_console_fd(); |
39 | 38 | ||
40 | while (argc > 2) { | 39 | while (argc > 2) { |
41 | a.keycode = atoi(argv[2]); | 40 | a.keycode = xatoul_range(argv[2], 0, 127); |
42 | a.scancode = sc = strtol(argv[1], &ep, 16); | 41 | a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255); |
43 | if (*ep) { | ||
44 | bb_error_msg_and_die("error reading SCANCODE: '%s'", argv[1]); | ||
45 | } | ||
46 | if (a.scancode > 127) { | 42 | if (a.scancode > 127) { |
47 | a.scancode -= 0xe000; | 43 | a.scancode -= 0xe000; |
48 | a.scancode += 128; | 44 | a.scancode += 128; |
49 | } | 45 | } |
50 | if (a.scancode > 255 || a.keycode > 127) { | 46 | if (ioctl(fd, KDSETKEYCODE, &a)) { |
51 | bb_error_msg_and_die("SCANCODE or KEYCODE outside bounds"); | ||
52 | } | ||
53 | if (ioctl(fd,KDSETKEYCODE,&a)) { | ||
54 | bb_perror_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode); | 47 | bb_perror_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode); |
55 | } | 48 | } |
56 | argc -= 2; | 49 | argc -= 2; |
diff --git a/console-tools/setlogcons.c b/console-tools/setlogcons.c index 90f24ce9c..ae15b9b28 100644 --- a/console-tools/setlogcons.c +++ b/console-tools/setlogcons.c | |||
@@ -22,7 +22,7 @@ extern int setlogcons_main(int argc, char **argv) | |||
22 | arg.subarg = 0; /* to specified console (current as default) */ | 22 | arg.subarg = 0; /* to specified console (current as default) */ |
23 | 23 | ||
24 | if (argc == 2) | 24 | if (argc == 2) |
25 | arg.subarg = atoi(argv[1]); | 25 | arg.subarg = xatoul_range(argv[1], 0, 63); |
26 | 26 | ||
27 | if (ioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg)) | 27 | if (ioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg)) |
28 | bb_perror_msg_and_die("TIOCLINUX"); | 28 | bb_perror_msg_and_die("TIOCLINUX"); |
diff --git a/coreutils/cal.c b/coreutils/cal.c index ef914128c..e2bc5ab12 100644 --- a/coreutils/cal.c +++ b/coreutils/cal.c | |||
@@ -112,9 +112,9 @@ int cal_main(int argc, char **argv) | |||
112 | } | 112 | } |
113 | } else { | 113 | } else { |
114 | if (argc == 2) { | 114 | if (argc == 2) { |
115 | month = bb_xgetularg10_bnd(*argv++, 1, 12); | 115 | month = xatoul_range(*argv++, 1, 12); |
116 | } | 116 | } |
117 | year = bb_xgetularg10_bnd(*argv, 1, 9999); | 117 | year = xatoul_range(*argv, 1, 9999); |
118 | } | 118 | } |
119 | 119 | ||
120 | blank_string(day_headings, sizeof(day_headings) - 7 + 7*julian); | 120 | blank_string(day_headings, sizeof(day_headings) - 7 + 7*julian); |
diff --git a/coreutils/cut.c b/coreutils/cut.c index 69f28fa8d..7ba947fae 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -163,17 +163,7 @@ static void cut_file(FILE * file) | |||
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | static int getval(char *ntok) | 166 | static const char _op_on_field[] = " only when operating on fields"; |
167 | { | ||
168 | char *junk; | ||
169 | int i = strtoul(ntok, &junk, 10); | ||
170 | |||
171 | if (*junk != '\0' || i < 0) | ||
172 | bb_error_msg_and_die("invalid byte or field list"); | ||
173 | return i; | ||
174 | } | ||
175 | |||
176 | static const char * const _op_on_field = " only when operating on fields"; | ||
177 | 167 | ||
178 | int cut_main(int argc, char **argv) | 168 | int cut_main(int argc, char **argv) |
179 | { | 169 | { |
@@ -231,7 +221,7 @@ int cut_main(int argc, char **argv) | |||
231 | } else if (strlen(ntok) == 0) { | 221 | } else if (strlen(ntok) == 0) { |
232 | s = BOL; | 222 | s = BOL; |
233 | } else { | 223 | } else { |
234 | s = getval(ntok); | 224 | s = xatoi_u(ntok); |
235 | /* account for the fact that arrays are zero based, while | 225 | /* account for the fact that arrays are zero based, while |
236 | * the user expects the first char on the line to be char #1 */ | 226 | * the user expects the first char on the line to be char #1 */ |
237 | if (s != 0) | 227 | if (s != 0) |
@@ -245,7 +235,7 @@ int cut_main(int argc, char **argv) | |||
245 | } else if (strlen(ntok) == 0) { | 235 | } else if (strlen(ntok) == 0) { |
246 | e = EOL; | 236 | e = EOL; |
247 | } else { | 237 | } else { |
248 | e = getval(ntok); | 238 | e = xatoi_u(ntok); |
249 | /* if the user specified and end position of 0, that means "til the | 239 | /* if the user specified and end position of 0, that means "til the |
250 | * end of the line */ | 240 | * end of the line */ |
251 | if (e == 0) | 241 | if (e == 0) |
diff --git a/coreutils/dd.c b/coreutils/dd.c index e63244d81..d557ae46d 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -62,19 +62,19 @@ int dd_main(int argc, char **argv) | |||
62 | for (n = 1; n < argc; n++) { | 62 | for (n = 1; n < argc; n++) { |
63 | // FIXME: make them capable of eating LARGE numbers | 63 | // FIXME: make them capable of eating LARGE numbers |
64 | if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) { | 64 | if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) { |
65 | ibs = bb_xparse_number(argv[n]+4, dd_suffixes); | 65 | ibs = xatoul_sfx(argv[n]+4, dd_suffixes); |
66 | flags |= twobufs_flag; | 66 | flags |= twobufs_flag; |
67 | } else if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("obs=", argv[n], 4)) { | 67 | } else if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("obs=", argv[n], 4)) { |
68 | obs = bb_xparse_number(argv[n]+4, dd_suffixes); | 68 | obs = xatoul_sfx(argv[n]+4, dd_suffixes); |
69 | flags |= twobufs_flag; | 69 | flags |= twobufs_flag; |
70 | } else if (!strncmp("bs=", argv[n], 3)) | 70 | } else if (!strncmp("bs=", argv[n], 3)) |
71 | ibs = obs = bb_xparse_number(argv[n]+3, dd_suffixes); | 71 | ibs = obs = xatoul_sfx(argv[n]+3, dd_suffixes); |
72 | else if (!strncmp("count=", argv[n], 6)) | 72 | else if (!strncmp("count=", argv[n], 6)) |
73 | count = bb_xparse_number(argv[n]+6, dd_suffixes); | 73 | count = xatoul_sfx(argv[n]+6, dd_suffixes); |
74 | else if (!strncmp("seek=", argv[n], 5)) | 74 | else if (!strncmp("seek=", argv[n], 5)) |
75 | seek = bb_xparse_number(argv[n]+5, dd_suffixes); | 75 | seek = xatoul_sfx(argv[n]+5, dd_suffixes); |
76 | else if (!strncmp("skip=", argv[n], 5)) | 76 | else if (!strncmp("skip=", argv[n], 5)) |
77 | skip = bb_xparse_number(argv[n]+5, dd_suffixes); | 77 | skip = xatoul_sfx(argv[n]+5, dd_suffixes); |
78 | else if (!strncmp("if=", argv[n], 3)) | 78 | else if (!strncmp("if=", argv[n], 3)) |
79 | infile = argv[n]+3; | 79 | infile = argv[n]+3; |
80 | else if (!strncmp("of=", argv[n], 3)) | 80 | else if (!strncmp("of=", argv[n], 3)) |
diff --git a/coreutils/diff.c b/coreutils/diff.c index b30aad5a7..65757d7d1 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c | |||
@@ -1192,7 +1192,7 @@ int diff_main(int argc, char **argv) | |||
1192 | 1192 | ||
1193 | context = 3; /* This is the default number of lines of context. */ | 1193 | context = 3; /* This is the default number of lines of context. */ |
1194 | if (cmd_flags & FLAG_U) { | 1194 | if (cmd_flags & FLAG_U) { |
1195 | context = bb_xgetlarg(U_opt, 10, 1, INT_MAX); | 1195 | context = xatoul_range(U_opt, 1, INT_MAX); |
1196 | } | 1196 | } |
1197 | argc -= optind; | 1197 | argc -= optind; |
1198 | argv += optind; | 1198 | argv += optind; |
diff --git a/coreutils/du.c b/coreutils/du.c index 1452e5883..f61d978b7 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -215,7 +215,7 @@ int du_main(int argc, char **argv) | |||
215 | one_file_system = opt & (1 << 5); /* -x opt */ | 215 | one_file_system = opt & (1 << 5); /* -x opt */ |
216 | if((opt & (1 << 6))) { | 216 | if((opt & (1 << 6))) { |
217 | /* -d opt */ | 217 | /* -d opt */ |
218 | max_print_depth = bb_xgetularg10_bnd(smax_print_depth, 0, INT_MAX); | 218 | max_print_depth = xatoi_u(smax_print_depth); |
219 | } | 219 | } |
220 | if((opt & (1 << 7))) { | 220 | if((opt & (1 << 7))) { |
221 | /* -l opt */ | 221 | /* -l opt */ |
diff --git a/coreutils/fold.c b/coreutils/fold.c index 3b5be64fe..45f4472e4 100644 --- a/coreutils/fold.c +++ b/coreutils/fold.c | |||
@@ -62,7 +62,7 @@ int fold_main(int argc, char **argv) | |||
62 | 62 | ||
63 | flags = getopt32(argc, argv, "bsw:", &w_opt); | 63 | flags = getopt32(argc, argv, "bsw:", &w_opt); |
64 | if (flags & FLAG_WIDTH) | 64 | if (flags & FLAG_WIDTH) |
65 | width = bb_xgetlarg(w_opt, 10, 1, 10000); | 65 | width = xatoul_range(w_opt, 1, 10000); |
66 | 66 | ||
67 | argv += optind; | 67 | argv += optind; |
68 | if (!*argv) { | 68 | if (!*argv) { |
diff --git a/coreutils/head.c b/coreutils/head.c index 7d5f219d2..060febcf7 100644 --- a/coreutils/head.c +++ b/coreutils/head.c | |||
@@ -64,32 +64,30 @@ int head_main(int argc, char **argv) | |||
64 | while ((opt = getopt(argc, argv, head_opts)) > 0) { | 64 | while ((opt = getopt(argc, argv, head_opts)) > 0) { |
65 | switch (opt) { | 65 | switch (opt) { |
66 | #if ENABLE_FEATURE_FANCY_HEAD | 66 | #if ENABLE_FEATURE_FANCY_HEAD |
67 | case 'q': | 67 | case 'q': |
68 | header_threshhold = INT_MAX; | 68 | header_threshhold = INT_MAX; |
69 | break; | 69 | break; |
70 | case 'v': | 70 | case 'v': |
71 | header_threshhold = -1; | 71 | header_threshhold = -1; |
72 | break; | 72 | break; |
73 | case 'c': | 73 | case 'c': |
74 | count_bytes = 1; | 74 | count_bytes = 1; |
75 | /* fall through */ | 75 | /* fall through */ |
76 | #endif | 76 | #endif |
77 | case 'n': | 77 | case 'n': |
78 | p = optarg; | 78 | p = optarg; |
79 | #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD | 79 | #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD |
80 | GET_COUNT: | 80 | GET_COUNT: |
81 | #endif | 81 | #endif |
82 | 82 | ||
83 | #if !ENABLE_FEATURE_FANCY_HEAD | 83 | #if !ENABLE_FEATURE_FANCY_HEAD |
84 | count = bb_xgetularg10(p); | 84 | count = xatoul(p); |
85 | #else | 85 | #else |
86 | count = bb_xgetularg_bnd_sfx(p, 10, | 86 | count = xatoul_sfx(p, head_suffixes); |
87 | 0, ULONG_MAX, | ||
88 | head_suffixes); | ||
89 | #endif | 87 | #endif |
90 | break; | 88 | break; |
91 | default: | 89 | default: |
92 | bb_show_usage(); | 90 | bb_show_usage(); |
93 | } | 91 | } |
94 | } | 92 | } |
95 | 93 | ||
diff --git a/coreutils/ls.c b/coreutils/ls.c index 8ba4ab758..f34e83ebe 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -163,8 +163,8 @@ static int list_single(struct dnode *); | |||
163 | static unsigned int all_fmt; | 163 | static unsigned int all_fmt; |
164 | 164 | ||
165 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 165 | #ifdef CONFIG_FEATURE_AUTOWIDTH |
166 | static int terminal_width = TERMINAL_WIDTH; | 166 | static unsigned terminal_width = TERMINAL_WIDTH; |
167 | static unsigned short tabstops = COLUMN_GAP; | 167 | static unsigned tabstops = COLUMN_GAP; |
168 | #else | 168 | #else |
169 | #define tabstops COLUMN_GAP | 169 | #define tabstops COLUMN_GAP |
170 | #define terminal_width TERMINAL_WIDTH | 170 | #define terminal_width TERMINAL_WIDTH |
@@ -915,10 +915,10 @@ int ls_main(int argc, char **argv) | |||
915 | #endif | 915 | #endif |
916 | ); | 916 | ); |
917 | if (tabstops_str) { | 917 | if (tabstops_str) { |
918 | tabstops = atoi(tabstops_str); | 918 | tabstops = xatou(tabstops_str); |
919 | } | 919 | } |
920 | if (terminal_width_str) { | 920 | if (terminal_width_str) { |
921 | terminal_width = atoi(terminal_width_str); | 921 | terminal_width = xatou(terminal_width_str); |
922 | } | 922 | } |
923 | #else | 923 | #else |
924 | opt = getopt32(argc, argv, ls_options | 924 | opt = getopt32(argc, argv, ls_options |
diff --git a/coreutils/mknod.c b/coreutils/mknod.c index 9c97b0302..7cc478f17 100644 --- a/coreutils/mknod.c +++ b/coreutils/mknod.c | |||
@@ -9,11 +9,8 @@ | |||
9 | 9 | ||
10 | /* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ | 10 | /* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ |
11 | 11 | ||
12 | #include <stdlib.h> | ||
13 | #include <string.h> | ||
14 | #include <sys/stat.h> | ||
15 | #include <sys/sysmacros.h> // For makedev | 12 | #include <sys/sysmacros.h> // For makedev |
16 | #include <unistd.h> | 13 | |
17 | #include "busybox.h" | 14 | #include "busybox.h" |
18 | #include "libcoreutils/coreutils.h" | 15 | #include "libcoreutils/coreutils.h" |
19 | 16 | ||
@@ -37,8 +34,8 @@ int mknod_main(int argc, char **argv) | |||
37 | if ((*name != 'p') && ((argc -= 2) == 2)) { | 34 | if ((*name != 'p') && ((argc -= 2) == 2)) { |
38 | /* Autodetect what the system supports; thexe macros should | 35 | /* Autodetect what the system supports; thexe macros should |
39 | * optimize out to two constants. */ | 36 | * optimize out to two constants. */ |
40 | dev = makedev(bb_xgetularg10_bnd(argv[2], 0, major(UINT_MAX)), | 37 | dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)), |
41 | bb_xgetularg10_bnd(argv[3], 0, minor(UINT_MAX))); | 38 | xatoul_range(argv[3], 0, minor(UINT_MAX))); |
42 | } | 39 | } |
43 | 40 | ||
44 | if (argc == 2) { | 41 | if (argc == 2) { |
diff --git a/coreutils/nice.c b/coreutils/nice.c index 4c54dddbb..a347001e3 100644 --- a/coreutils/nice.c +++ b/coreutils/nice.c | |||
@@ -52,7 +52,7 @@ int nice_main(int argc, char **argv) | |||
52 | if (argc < 4) { /* Missing priority and/or utility! */ | 52 | if (argc < 4) { /* Missing priority and/or utility! */ |
53 | bb_show_usage(); | 53 | bb_show_usage(); |
54 | } | 54 | } |
55 | adjustment = bb_xgetlarg(argv[1], 10, INT_MIN, INT_MAX); | 55 | adjustment = xatoi(argv[1]); |
56 | argv += 2; | 56 | argv += 2; |
57 | } | 57 | } |
58 | 58 | ||
diff --git a/coreutils/printf.c b/coreutils/printf.c index 4a208040f..1511034a1 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
@@ -30,7 +30,7 @@ | |||
30 | 30 | ||
31 | %b = print an argument string, interpreting backslash escapes | 31 | %b = print an argument string, interpreting backslash escapes |
32 | 32 | ||
33 | The `format' argument is re-used as many times as necessary | 33 | The 'format' argument is re-used as many times as necessary |
34 | to convert all of the given arguments. | 34 | to convert all of the given arguments. |
35 | 35 | ||
36 | David MacKenzie <djm@gnu.ai.mit.edu> */ | 36 | David MacKenzie <djm@gnu.ai.mit.edu> */ |
@@ -57,7 +57,7 @@ static void multiconvert(char *arg, void *result, converter convert) | |||
57 | fputs(arg, stderr); | 57 | fputs(arg, stderr); |
58 | } | 58 | } |
59 | 59 | ||
60 | static unsigned long xstrtoul(char *arg) | 60 | static unsigned long my_xstrtoul(char *arg) |
61 | { | 61 | { |
62 | unsigned long result; | 62 | unsigned long result; |
63 | 63 | ||
@@ -65,14 +65,14 @@ static unsigned long xstrtoul(char *arg) | |||
65 | return result; | 65 | return result; |
66 | } | 66 | } |
67 | 67 | ||
68 | static long xstrtol(char *arg) | 68 | static long my_xstrtol(char *arg) |
69 | { | 69 | { |
70 | long result; | 70 | long result; |
71 | multiconvert(arg, &result, (converter)safe_strtol); | 71 | multiconvert(arg, &result, (converter)safe_strtol); |
72 | return result; | 72 | return result; |
73 | } | 73 | } |
74 | 74 | ||
75 | static double xstrtod(char *arg) | 75 | static double my_xstrtod(char *arg) |
76 | { | 76 | { |
77 | double result; | 77 | double result; |
78 | multiconvert(arg, &result, (converter)safe_strtod); | 78 | multiconvert(arg, &result, (converter)safe_strtod); |
@@ -120,13 +120,13 @@ int printf_main(int argc, char **argv) | |||
120 | } | 120 | } |
121 | 121 | ||
122 | /* Print the text in FORMAT, using ARGV (with ARGC elements) for | 122 | /* Print the text in FORMAT, using ARGV (with ARGC elements) for |
123 | arguments to any `%' directives. | 123 | arguments to any '%' directives. |
124 | Return the number of elements of ARGV used. */ | 124 | Return the number of elements of ARGV used. */ |
125 | 125 | ||
126 | static int print_formatted(char *format, int argc, char **argv) | 126 | static int print_formatted(char *format, int argc, char **argv) |
127 | { | 127 | { |
128 | int save_argc = argc; /* Preserve original value. */ | 128 | int save_argc = argc; /* Preserve original value. */ |
129 | char *f; /* Pointer into `format'. */ | 129 | char *f; /* Pointer into 'format'. */ |
130 | char *direc_start; /* Start of % directive. */ | 130 | char *direc_start; /* Start of % directive. */ |
131 | size_t direc_length; /* Length of % directive. */ | 131 | size_t direc_length; /* Length of % directive. */ |
132 | int field_width; /* Arg to first '*', or -1 if none. */ | 132 | int field_width; /* Arg to first '*', or -1 if none. */ |
@@ -158,7 +158,7 @@ static int print_formatted(char *format, int argc, char **argv) | |||
158 | ++f; | 158 | ++f; |
159 | ++direc_length; | 159 | ++direc_length; |
160 | if (argc > 0) { | 160 | if (argc > 0) { |
161 | field_width = xstrtoul(*argv); | 161 | field_width = my_xstrtoul(*argv); |
162 | ++argv; | 162 | ++argv; |
163 | --argc; | 163 | --argc; |
164 | } else | 164 | } else |
@@ -175,7 +175,7 @@ static int print_formatted(char *format, int argc, char **argv) | |||
175 | ++f; | 175 | ++f; |
176 | ++direc_length; | 176 | ++direc_length; |
177 | if (argc > 0) { | 177 | if (argc > 0) { |
178 | precision = xstrtoul(*argv); | 178 | precision = my_xstrtoul(*argv); |
179 | ++argv; | 179 | ++argv; |
180 | --argc; | 180 | --argc; |
181 | } else | 181 | } else |
@@ -235,14 +235,14 @@ print_direc(char *start, size_t length, int field_width, int precision, | |||
235 | case 'i': | 235 | case 'i': |
236 | if (field_width < 0) { | 236 | if (field_width < 0) { |
237 | if (precision < 0) | 237 | if (precision < 0) |
238 | printf(p, xstrtol(argument)); | 238 | printf(p, my_xstrtol(argument)); |
239 | else | 239 | else |
240 | printf(p, precision, xstrtol(argument)); | 240 | printf(p, precision, my_xstrtol(argument)); |
241 | } else { | 241 | } else { |
242 | if (precision < 0) | 242 | if (precision < 0) |
243 | printf(p, field_width, xstrtol(argument)); | 243 | printf(p, field_width, my_xstrtol(argument)); |
244 | else | 244 | else |
245 | printf(p, field_width, precision, xstrtol(argument)); | 245 | printf(p, field_width, precision, my_xstrtol(argument)); |
246 | } | 246 | } |
247 | break; | 247 | break; |
248 | 248 | ||
@@ -252,14 +252,14 @@ print_direc(char *start, size_t length, int field_width, int precision, | |||
252 | case 'X': | 252 | case 'X': |
253 | if (field_width < 0) { | 253 | if (field_width < 0) { |
254 | if (precision < 0) | 254 | if (precision < 0) |
255 | printf(p, xstrtoul(argument)); | 255 | printf(p, my_xstrtoul(argument)); |
256 | else | 256 | else |
257 | printf(p, precision, xstrtoul(argument)); | 257 | printf(p, precision, my_xstrtoul(argument)); |
258 | } else { | 258 | } else { |
259 | if (precision < 0) | 259 | if (precision < 0) |
260 | printf(p, field_width, xstrtoul(argument)); | 260 | printf(p, field_width, my_xstrtoul(argument)); |
261 | else | 261 | else |
262 | printf(p, field_width, precision, xstrtoul(argument)); | 262 | printf(p, field_width, precision, my_xstrtoul(argument)); |
263 | } | 263 | } |
264 | break; | 264 | break; |
265 | 265 | ||
@@ -270,14 +270,14 @@ print_direc(char *start, size_t length, int field_width, int precision, | |||
270 | case 'G': | 270 | case 'G': |
271 | if (field_width < 0) { | 271 | if (field_width < 0) { |
272 | if (precision < 0) | 272 | if (precision < 0) |
273 | printf(p, xstrtod(argument)); | 273 | printf(p, my_xstrtod(argument)); |
274 | else | 274 | else |
275 | printf(p, precision, xstrtod(argument)); | 275 | printf(p, precision, my_xstrtod(argument)); |
276 | } else { | 276 | } else { |
277 | if (precision < 0) | 277 | if (precision < 0) |
278 | printf(p, field_width, xstrtod(argument)); | 278 | printf(p, field_width, my_xstrtod(argument)); |
279 | else | 279 | else |
280 | printf(p, field_width, precision, xstrtod(argument)); | 280 | printf(p, field_width, precision, my_xstrtod(argument)); |
281 | } | 281 | } |
282 | break; | 282 | break; |
283 | 283 | ||
diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 3946c3433..e32e2157d 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "busybox.h" | 24 | #include "busybox.h" |
25 | 25 | ||
26 | #ifdef CONFIG_FEATURE_FANCY_SLEEP | 26 | #ifdef CONFIG_FEATURE_FANCY_SLEEP |
27 | static const struct suffix_mult sleep_suffixes[] = { | 27 | static const struct suffix_mult sfx[] = { |
28 | { "s", 1 }, | 28 | { "s", 1 }, |
29 | { "m", 60 }, | 29 | { "m", 60 }, |
30 | { "h", 60*60 }, | 30 | { "h", 60*60 }, |
@@ -46,9 +46,7 @@ int sleep_main(int argc, char **argv) | |||
46 | ++argv; | 46 | ++argv; |
47 | duration = 0; | 47 | duration = 0; |
48 | do { | 48 | do { |
49 | duration += bb_xgetularg_bnd_sfx(*argv, 10, | 49 | duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx); |
50 | 0, UINT_MAX-duration, | ||
51 | sleep_suffixes); | ||
52 | } while (*++argv); | 50 | } while (*++argv); |
53 | 51 | ||
54 | #else /* CONFIG_FEATURE_FANCY_SLEEP */ | 52 | #else /* CONFIG_FEATURE_FANCY_SLEEP */ |
@@ -57,11 +55,7 @@ int sleep_main(int argc, char **argv) | |||
57 | bb_show_usage(); | 55 | bb_show_usage(); |
58 | } | 56 | } |
59 | 57 | ||
60 | #if UINT_MAX == ULONG_MAX | 58 | duration = xatou(argv[1]); |
61 | duration = bb_xgetularg10(argv[1]); | ||
62 | #else | ||
63 | duration = bb_xgetularg10_bnd(argv[1], 0, UINT_MAX); | ||
64 | #endif | ||
65 | 59 | ||
66 | #endif /* CONFIG_FEATURE_FANCY_SLEEP */ | 60 | #endif /* CONFIG_FEATURE_FANCY_SLEEP */ |
67 | 61 | ||
diff --git a/coreutils/stty.c b/coreutils/stty.c index a41faaf1e..8c16c27a9 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -370,9 +370,9 @@ enum { | |||
370 | }; | 370 | }; |
371 | 371 | ||
372 | /* The width of the screen, for output wrapping */ | 372 | /* The width of the screen, for output wrapping */ |
373 | static int max_col; | 373 | static unsigned max_col = 80; /* default */ |
374 | /* Current position, to know when to wrap */ | 374 | /* Current position, to know when to wrap */ |
375 | static int current_col; | 375 | static unsigned current_col; |
376 | static const char *device_name = bb_msg_standard_input; | 376 | static const char *device_name = bb_msg_standard_input; |
377 | 377 | ||
378 | /* Return a string that is the printable representation of character CH */ | 378 | /* Return a string that is the printable representation of character CH */ |
@@ -422,7 +422,7 @@ static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode) | |||
422 | 422 | ||
423 | static speed_t string_to_baud_or_die(const char *arg) | 423 | static speed_t string_to_baud_or_die(const char *arg) |
424 | { | 424 | { |
425 | return tty_value_to_baud(bb_xparse_number(arg, 0)); | 425 | return tty_value_to_baud(xatou(arg)); |
426 | } | 426 | } |
427 | 427 | ||
428 | static void set_speed_or_die(enum speed_setting type, const char *arg, | 428 | static void set_speed_or_die(enum speed_setting type, const char *arg, |
@@ -556,9 +556,8 @@ static inline void display_window_size(int fancy) {} | |||
556 | 556 | ||
557 | #endif /* !TIOCGWINSZ */ | 557 | #endif /* !TIOCGWINSZ */ |
558 | 558 | ||
559 | static int screen_columns(void) | 559 | static int screen_columns_or_die(void) |
560 | { | 560 | { |
561 | int columns; | ||
562 | const char *s; | 561 | const char *s; |
563 | 562 | ||
564 | #ifdef TIOCGWINSZ | 563 | #ifdef TIOCGWINSZ |
@@ -574,11 +573,10 @@ static int screen_columns(void) | |||
574 | return win.ws_col; | 573 | return win.ws_col; |
575 | #endif | 574 | #endif |
576 | 575 | ||
577 | columns = 80; | 576 | s = getenv("COLUMNS"); |
578 | if ((s = getenv("COLUMNS"))) { | 577 | if (s) |
579 | columns = atoi(s); | 578 | return xatoi_u(s); |
580 | } | 579 | return 80; |
581 | return columns; | ||
582 | } | 580 | } |
583 | 581 | ||
584 | static const struct suffix_mult stty_suffixes[] = { | 582 | static const struct suffix_mult stty_suffixes[] = { |
@@ -745,14 +743,14 @@ end_option: | |||
745 | #ifdef HAVE_C_LINE | 743 | #ifdef HAVE_C_LINE |
746 | case param_line: | 744 | case param_line: |
747 | # ifndef TIOCGWINSZ | 745 | # ifndef TIOCGWINSZ |
748 | bb_xparse_number(argnext, stty_suffixes); | 746 | xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes); |
749 | break; | 747 | break; |
750 | # endif /* else fall-through */ | 748 | # endif /* else fall-through */ |
751 | #endif | 749 | #endif |
752 | #ifdef TIOCGWINSZ | 750 | #ifdef TIOCGWINSZ |
753 | case param_rows: | 751 | case param_rows: |
754 | case param_cols: | 752 | case param_cols: |
755 | bb_xparse_number(argnext, stty_suffixes); | 753 | xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes); |
756 | break; | 754 | break; |
757 | case param_size: | 755 | case param_size: |
758 | #endif | 756 | #endif |
@@ -802,7 +800,7 @@ end_option: | |||
802 | perror_on_device_and_die("%s"); | 800 | perror_on_device_and_die("%s"); |
803 | 801 | ||
804 | if (verbose_output || recoverable_output || noargs) { | 802 | if (verbose_output || recoverable_output || noargs) { |
805 | max_col = screen_columns(); | 803 | max_col = screen_columns_or_die(); |
806 | output_func(&mode); | 804 | output_func(&mode); |
807 | return EXIT_SUCCESS; | 805 | return EXIT_SUCCESS; |
808 | } | 806 | } |
@@ -846,24 +844,22 @@ end_option: | |||
846 | switch (param) { | 844 | switch (param) { |
847 | #ifdef HAVE_C_LINE | 845 | #ifdef HAVE_C_LINE |
848 | case param_line: | 846 | case param_line: |
849 | mode.c_line = bb_xparse_number(argnext, stty_suffixes); | 847 | mode.c_line = xatoul_sfx(argnext, stty_suffixes); |
850 | require_set_attr = 1; | 848 | require_set_attr = 1; |
851 | break; | 849 | break; |
852 | #endif | 850 | #endif |
853 | #ifdef TIOCGWINSZ | 851 | #ifdef TIOCGWINSZ |
854 | case param_cols: | 852 | case param_cols: |
855 | set_window_size(-1, (int) bb_xparse_number(argnext, stty_suffixes)); | 853 | set_window_size(-1, xatoul_sfx(argnext, stty_suffixes)); |
856 | break; | 854 | break; |
857 | case param_size: | 855 | case param_size: |
858 | max_col = screen_columns(); | ||
859 | display_window_size(0); | 856 | display_window_size(0); |
860 | break; | 857 | break; |
861 | case param_rows: | 858 | case param_rows: |
862 | set_window_size((int) bb_xparse_number(argnext, stty_suffixes), -1); | 859 | set_window_size(xatoul_sfx(argnext, stty_suffixes), -1); |
863 | break; | 860 | break; |
864 | #endif | 861 | #endif |
865 | case param_speed: | 862 | case param_speed: |
866 | max_col = screen_columns(); | ||
867 | display_speed(&mode, 0); | 863 | display_speed(&mode, 0); |
868 | break; | 864 | break; |
869 | case param_ispeed: | 865 | case param_ispeed: |
@@ -1096,7 +1092,7 @@ static void set_control_char_or_die(const struct control_info *info, | |||
1096 | unsigned char value; | 1092 | unsigned char value; |
1097 | 1093 | ||
1098 | if (info->name == stty_min || info->name == stty_time) | 1094 | if (info->name == stty_min || info->name == stty_time) |
1099 | value = bb_xparse_number(arg, stty_suffixes); | 1095 | value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes); |
1100 | else if (arg[0] == '\0' || arg[1] == '\0') | 1096 | else if (arg[0] == '\0' || arg[1] == '\0') |
1101 | value = arg[0]; | 1097 | value = arg[0]; |
1102 | else if (streq(arg, "^-") || streq(arg, "undef")) | 1098 | else if (streq(arg, "^-") || streq(arg, "undef")) |
@@ -1106,7 +1102,7 @@ static void set_control_char_or_die(const struct control_info *info, | |||
1106 | if (arg[1] == '?') | 1102 | if (arg[1] == '?') |
1107 | value = 127; | 1103 | value = 127; |
1108 | } else | 1104 | } else |
1109 | value = bb_xparse_number(arg, stty_suffixes); | 1105 | value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes); |
1110 | mode->c_cc[info->offset] = value; | 1106 | mode->c_cc[info->offset] = value; |
1111 | } | 1107 | } |
1112 | 1108 | ||
diff --git a/coreutils/tail.c b/coreutils/tail.c index 49f1bcd6a..82c0d99bc 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -132,7 +132,7 @@ int tail_main(int argc, char **argv) | |||
132 | #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL | 132 | #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL |
133 | GET_COUNT: | 133 | GET_COUNT: |
134 | #endif | 134 | #endif |
135 | count = bb_xgetlarg10_sfx(optarg, tail_suffixes); | 135 | count = xatol_sfx(optarg, tail_suffixes); |
136 | /* Note: Leading whitespace is an error trapped above. */ | 136 | /* Note: Leading whitespace is an error trapped above. */ |
137 | if (*optarg == '+') { | 137 | if (*optarg == '+') { |
138 | from_top = 1; | 138 | from_top = 1; |
@@ -148,7 +148,7 @@ int tail_main(int argc, char **argv) | |||
148 | header_threshhold = INT_MAX; | 148 | header_threshhold = INT_MAX; |
149 | break; | 149 | break; |
150 | case 's': | 150 | case 's': |
151 | sleep_period =bb_xgetularg10_bnd(optarg, 0, UINT_MAX); | 151 | sleep_period = xatou(optarg); |
152 | break; | 152 | break; |
153 | case 'v': | 153 | case 'v': |
154 | header_threshhold = 0; | 154 | header_threshhold = 0; |
diff --git a/coreutils/uniq.c b/coreutils/uniq.c index 26afc00f4..1b201af24 100644 --- a/coreutils/uniq.c +++ b/coreutils/uniq.c | |||
@@ -37,7 +37,7 @@ int uniq_main(int argc, char **argv) | |||
37 | 37 | ||
38 | while ((opt = getopt(argc, argv, uniq_opts)) > 0) { | 38 | while ((opt = getopt(argc, argv, uniq_opts)) > 0) { |
39 | if ((opt == 'f') || (opt == 's')) { | 39 | if ((opt == 'f') || (opt == 's')) { |
40 | int t = bb_xgetularg10(optarg); | 40 | int t = xatoul(optarg); |
41 | if (opt == 'f') { | 41 | if (opt == 'f') { |
42 | skip_fields = t; | 42 | skip_fields = t; |
43 | } else { | 43 | } else { |
diff --git a/coreutils/usleep.c b/coreutils/usleep.c index 90ddc5a57..de473a7b2 100644 --- a/coreutils/usleep.c +++ b/coreutils/usleep.c | |||
@@ -20,7 +20,7 @@ int usleep_main(int argc, char **argv) | |||
20 | bb_show_usage(); | 20 | bb_show_usage(); |
21 | } | 21 | } |
22 | 22 | ||
23 | if (usleep(bb_xgetularg10_bnd(argv[1], 0, UINT_MAX))) { | 23 | if (usleep(xatou(argv[1]))) { |
24 | bb_perror_nomsg_and_die(); | 24 | bb_perror_nomsg_and_die(); |
25 | } | 25 | } |
26 | 26 | ||
diff --git a/coreutils/watch.c b/coreutils/watch.c index 7b9c6698a..b1a7d9086 100644 --- a/coreutils/watch.c +++ b/coreutils/watch.c | |||
@@ -28,7 +28,7 @@ int watch_main(int argc, char **argv) | |||
28 | /* don't use getopt, because it permutes the arguments */ | 28 | /* don't use getopt, because it permutes the arguments */ |
29 | ++argv; | 29 | ++argv; |
30 | if ((argc > 3) && argv[0][0] == '-' && argv[0][1] == 'n') { | 30 | if ((argc > 3) && argv[0][0] == '-' && argv[0][1] == 'n') { |
31 | period = bb_xgetularg10_bnd(argv[1], 1, UINT_MAX); | 31 | period = xatou(argv[1]); |
32 | argv += 2; | 32 | argv += 2; |
33 | } | 33 | } |
34 | watched_argv = argv; | 34 | watched_argv = argv; |
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 964a221a8..f2d90b64d 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
@@ -60,31 +60,31 @@ int run_parts_main(int argc, char **argv) | |||
60 | 60 | ||
61 | umask(022); | 61 | umask(022); |
62 | 62 | ||
63 | while ((opt = getopt_long (argc, argv, "tu:a:", | 63 | while ((opt = getopt_long(argc, argv, "tu:a:", |
64 | runparts_long_options, NULL)) > 0) | 64 | runparts_long_options, NULL)) > 0) |
65 | { | 65 | { |
66 | switch (opt) { | 66 | switch (opt) { |
67 | /* Enable test mode */ | 67 | /* Enable test mode */ |
68 | case 't': | 68 | case 't': |
69 | test_mode++; | 69 | test_mode++; |
70 | break; | 70 | break; |
71 | /* Set the umask of the programs executed */ | 71 | /* Set the umask of the programs executed */ |
72 | case 'u': | 72 | case 'u': |
73 | /* Check and set the umask of the program executed. As stated in the original | 73 | /* Check and set the umask of the program executed. As stated in the original |
74 | * run-parts, the octal conversion in libc is not foolproof; it will take the | 74 | * run-parts, the octal conversion in libc is not foolproof; it will take the |
75 | * 8 and 9 digits under some circumstances. We'll just have to live with it. | 75 | * 8 and 9 digits under some circumstances. We'll just have to live with it. |
76 | */ | 76 | */ |
77 | umask(bb_xgetlarg(optarg, 8, 0, 07777)); | 77 | umask(xstrtoul_range(optarg, 8, 0, 07777)); |
78 | break; | 78 | break; |
79 | /* Pass an argument to the programs */ | 79 | /* Pass an argument to the programs */ |
80 | case 'a': | 80 | case 'a': |
81 | /* Add an argument to the commands that we will call. | 81 | /* Add an argument to the commands that we will call. |
82 | * Called once for every argument. */ | 82 | * Called once for every argument. */ |
83 | args = xrealloc(args, (argcount + 2) * (sizeof(char *))); | 83 | args = xrealloc(args, (argcount + 2) * (sizeof(char *))); |
84 | args[argcount++] = optarg; | 84 | args[argcount++] = optarg; |
85 | break; | 85 | break; |
86 | default: | 86 | default: |
87 | bb_show_usage(); | 87 | bb_show_usage(); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 57f42d8ef..6ced9caad 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -260,7 +260,7 @@ int start_stop_daemon_main(int argc, char **argv) | |||
260 | 260 | ||
261 | // USE_FEATURE_START_STOP_DAEMON_FANCY( | 261 | // USE_FEATURE_START_STOP_DAEMON_FANCY( |
262 | // if (retry_arg) | 262 | // if (retry_arg) |
263 | // retries = bb_xgetlarg(retry_arg, 10, 0, INT_MAX); | 263 | // retries = xatoi_u(retry_arg); |
264 | // ) | 264 | // ) |
265 | argc -= optind; | 265 | argc -= optind; |
266 | argv += optind; | 266 | argv += optind; |
diff --git a/editors/patch.c b/editors/patch.c index c18659eda..047de9e57 100644 --- a/editors/patch.c +++ b/editors/patch.c | |||
@@ -87,7 +87,7 @@ int patch_main(int argc, char **argv) | |||
87 | char *p, *i; | 87 | char *p, *i; |
88 | ret = getopt32(argc, argv, "p:i:", &p, &i); | 88 | ret = getopt32(argc, argv, "p:i:", &p, &i); |
89 | if (ret & 1) | 89 | if (ret & 1) |
90 | patch_level = bb_xgetlarg(p, 10, -1, USHRT_MAX); | 90 | patch_level = xatol_range(p, -1, USHRT_MAX); |
91 | if (ret & 2) { | 91 | if (ret & 2) { |
92 | patch_file = xfopen(i, "r"); | 92 | patch_file = xfopen(i, "r"); |
93 | } else { | 93 | } else { |
diff --git a/findutils/find.c b/findutils/find.c index 7e3613af4..913a778eb 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -216,53 +216,47 @@ int find_main(int argc, char **argv) | |||
216 | #endif | 216 | #endif |
217 | #ifdef CONFIG_FEATURE_FIND_PERM | 217 | #ifdef CONFIG_FEATURE_FIND_PERM |
218 | } else if (strcmp(argv[i], "-perm") == 0) { | 218 | } else if (strcmp(argv[i], "-perm") == 0) { |
219 | char *end; | ||
220 | if (++i == argc) | 219 | if (++i == argc) |
221 | bb_error_msg_and_die(bb_msg_requires_arg, "-perm"); | 220 | bb_error_msg_and_die(bb_msg_requires_arg, "-perm"); |
222 | perm_mask = strtol(argv[i], &end, 8); | 221 | perm_mask = xstrtol_range(argv[i], 8, 0, 07777); |
223 | if ((end[0] != '\0') || (perm_mask > 07777)) | 222 | perm_char = argv[i][0]; |
224 | bb_error_msg_and_die(bb_msg_invalid_arg, argv[i], "-perm"); | 223 | if (perm_char == '-') |
225 | if ((perm_char = argv[i][0]) == '-') | ||
226 | perm_mask = -perm_mask; | 224 | perm_mask = -perm_mask; |
227 | #endif | 225 | #endif |
228 | #ifdef CONFIG_FEATURE_FIND_MTIME | 226 | #ifdef CONFIG_FEATURE_FIND_MTIME |
229 | } else if (strcmp(argv[i], "-mtime") == 0) { | 227 | } else if (strcmp(argv[i], "-mtime") == 0) { |
230 | char *end; | ||
231 | if (++i == argc) | 228 | if (++i == argc) |
232 | bb_error_msg_and_die(bb_msg_requires_arg, "-mtime"); | 229 | bb_error_msg_and_die(bb_msg_requires_arg, "-mtime"); |
233 | mtime_days = strtol(argv[i], &end, 10); | 230 | mtime_days = xatol(argv[i]); |
234 | if (end[0] != '\0') | 231 | mtime_char = argv[i][0]; |
235 | bb_error_msg_and_die(bb_msg_invalid_arg, argv[i], "-mtime"); | 232 | if (mtime_char == '-') |
236 | if ((mtime_char = argv[i][0]) == '-') | ||
237 | mtime_days = -mtime_days; | 233 | mtime_days = -mtime_days; |
238 | #endif | 234 | #endif |
239 | #ifdef CONFIG_FEATURE_FIND_MMIN | 235 | #ifdef CONFIG_FEATURE_FIND_MMIN |
240 | } else if (strcmp(argv[i], "-mmin") == 0) { | 236 | } else if (strcmp(argv[i], "-mmin") == 0) { |
241 | char *end; | ||
242 | if (++i == argc) | 237 | if (++i == argc) |
243 | bb_error_msg_and_die(bb_msg_requires_arg, "-mmin"); | 238 | bb_error_msg_and_die(bb_msg_requires_arg, "-mmin"); |
244 | mmin_mins = strtol(argv[i], &end, 10); | 239 | mmin_mins = xatol(argv[i]); |
245 | if (end[0] != '\0') | 240 | mmin_char = argv[i][0]; |
246 | bb_error_msg_and_die(bb_msg_invalid_arg, argv[i], "-mmin"); | 241 | if (mmin_char == '-') |
247 | if ((mmin_char = argv[i][0]) == '-') | ||
248 | mmin_mins = -mmin_mins; | 242 | mmin_mins = -mmin_mins; |
249 | #endif | 243 | #endif |
250 | #ifdef CONFIG_FEATURE_FIND_XDEV | 244 | #ifdef CONFIG_FEATURE_FIND_XDEV |
251 | } else if (strcmp(argv[i], "-xdev") == 0) { | 245 | } else if (strcmp(argv[i], "-xdev") == 0) { |
252 | struct stat stbuf; | 246 | struct stat stbuf; |
253 | 247 | ||
254 | xdev_count = ( firstopt - 1 ) ? ( firstopt - 1 ) : 1; | 248 | xdev_count = (firstopt - 1) ? (firstopt - 1) : 1; |
255 | xdev_dev = xmalloc ( xdev_count * sizeof( dev_t )); | 249 | xdev_dev = xmalloc(xdev_count * sizeof(dev_t)); |
256 | 250 | ||
257 | if ( firstopt == 1 ) { | 251 | if (firstopt == 1) { |
258 | xstat ( ".", &stbuf ); | 252 | xstat(".", &stbuf); |
259 | xdev_dev [0] = stbuf. st_dev; | 253 | xdev_dev[0] = stbuf.st_dev; |
260 | } | 254 | } |
261 | else { | 255 | else { |
262 | 256 | ||
263 | for (i = 1; i < firstopt; i++) { | 257 | for (i = 1; i < firstopt; i++) { |
264 | xstat ( argv [i], &stbuf ); | 258 | xstat(argv[i], &stbuf); |
265 | xdev_dev [i-1] = stbuf. st_dev; | 259 | xdev_dev[i-1] = stbuf.st_dev; |
266 | } | 260 | } |
267 | } | 261 | } |
268 | #endif | 262 | #endif |
@@ -271,17 +265,14 @@ int find_main(int argc, char **argv) | |||
271 | struct stat stat_newer; | 265 | struct stat stat_newer; |
272 | if (++i == argc) | 266 | if (++i == argc) |
273 | bb_error_msg_and_die(bb_msg_requires_arg, "-newer"); | 267 | bb_error_msg_and_die(bb_msg_requires_arg, "-newer"); |
274 | xstat (argv[i], &stat_newer); | 268 | xstat(argv[i], &stat_newer); |
275 | newer_mtime = stat_newer.st_mtime; | 269 | newer_mtime = stat_newer.st_mtime; |
276 | #endif | 270 | #endif |
277 | #ifdef CONFIG_FEATURE_FIND_INUM | 271 | #ifdef CONFIG_FEATURE_FIND_INUM |
278 | } else if (strcmp(argv[i], "-inum") == 0) { | 272 | } else if (strcmp(argv[i], "-inum") == 0) { |
279 | char *end; | ||
280 | if (++i == argc) | 273 | if (++i == argc) |
281 | bb_error_msg_and_die(bb_msg_requires_arg, "-inum"); | 274 | bb_error_msg_and_die(bb_msg_requires_arg, "-inum"); |
282 | inode_num = strtol(argv[i], &end, 10); | 275 | inode_num = xatoul(argv[i]); |
283 | if (end[0] != '\0') | ||
284 | bb_error_msg_and_die(bb_msg_invalid_arg, argv[i], "-inum"); | ||
285 | #endif | 276 | #endif |
286 | #ifdef CONFIG_FEATURE_FIND_EXEC | 277 | #ifdef CONFIG_FEATURE_FIND_EXEC |
287 | } else if (strcmp(argv[i], "-exec") == 0) { | 278 | } else if (strcmp(argv[i], "-exec") == 0) { |
diff --git a/findutils/xargs.c b/findutils/xargs.c index 81997b6f6..e7cc7c379 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -426,7 +426,7 @@ int xargs_main(int argc, char **argv) | |||
426 | orig_arg_max -= 2048; /* POSIX.2 requires subtracting 2048 */ | 426 | orig_arg_max -= 2048; /* POSIX.2 requires subtracting 2048 */ |
427 | 427 | ||
428 | if (opt & OPT_UPTO_SIZE) { | 428 | if (opt & OPT_UPTO_SIZE) { |
429 | n_max_chars = bb_xgetularg10_bnd(max_chars, 1, orig_arg_max); | 429 | n_max_chars = xatoul_range(max_chars, 1, orig_arg_max); |
430 | for (i = 0; i < argc; i++) { | 430 | for (i = 0; i < argc; i++) { |
431 | n_chars += strlen(*argv) + 1; | 431 | n_chars += strlen(*argv) + 1; |
432 | } | 432 | } |
@@ -446,7 +446,7 @@ int xargs_main(int argc, char **argv) | |||
446 | max_chars = xmalloc(n_max_chars); | 446 | max_chars = xmalloc(n_max_chars); |
447 | 447 | ||
448 | if (opt & OPT_UPTO_NUMBER) { | 448 | if (opt & OPT_UPTO_NUMBER) { |
449 | n_max_arg = bb_xgetularg10_bnd(max_args, 1, INT_MAX); | 449 | n_max_arg = xatoul_range(max_args, 1, INT_MAX); |
450 | } else { | 450 | } else { |
451 | n_max_arg = n_max_chars; | 451 | n_max_arg = n_max_chars; |
452 | } | 452 | } |
diff --git a/include/libbb.h b/include/libbb.h index 11e1e62d9..a7c770400 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -267,46 +267,68 @@ extern void *xmalloc(size_t size); | |||
267 | extern void *xrealloc(void *old, size_t size); | 267 | extern void *xrealloc(void *old, size_t size); |
268 | extern void *xzalloc(size_t size); | 268 | extern void *xzalloc(size_t size); |
269 | 269 | ||
270 | extern char *xstrdup (const char *s); | 270 | extern char *xstrdup(const char *s); |
271 | extern char *xstrndup (const char *s, int n); | 271 | extern char *xstrndup(const char *s, int n); |
272 | extern char *safe_strncpy(char *dst, const char *src, size_t size); | 272 | extern char *safe_strncpy(char *dst, const char *src, size_t size); |
273 | extern int safe_strtoi(char *arg, int* value); | 273 | // FIXME: the prototype doesn't match libc strtoXX -> confusion |
274 | extern int safe_strtod(char *arg, double* value); | 274 | // FIXME: alot of unchecked strtoXXX are still in tree |
275 | extern int safe_strtol(char *arg, long* value); | 275 | // FIXME: atoi_or_else(str, N)? |
276 | extern int safe_strtoll(char *arg, long long* value); | 276 | extern int safe_strtoi(const char *arg, int* value); |
277 | extern int safe_strtoul(char *arg, unsigned long* value); | 277 | extern int safe_strtou(const char *arg, unsigned* value); |
278 | extern int safe_strtoull(char *arg, unsigned long long* value); | 278 | extern int safe_strtod(const char *arg, double* value); |
279 | extern int safe_strtol(const char *arg, long* value); | ||
280 | extern int safe_strtoll(const char *arg, long long* value); | ||
281 | extern int safe_strtoul(const char *arg, unsigned long* value); | ||
282 | extern int safe_strtoull(const char *arg, unsigned long long* value); | ||
283 | extern int safe_strtou32(const char *arg, uint32_t* value); | ||
279 | 284 | ||
280 | struct suffix_mult { | 285 | struct suffix_mult { |
281 | const char *suffix; | 286 | const char *suffix; |
282 | unsigned int mult; | 287 | unsigned int mult; |
283 | }; | 288 | }; |
284 | 289 | ||
285 | extern unsigned long bb_xgetularg_bnd_sfx(const char *arg, int base, | 290 | unsigned long xstrtoul_range_sfx(const char *numstr, int base, |
286 | unsigned long lower, | 291 | unsigned long lower, |
287 | unsigned long upper, | 292 | unsigned long upper, |
288 | const struct suffix_mult *suffixes); | 293 | const struct suffix_mult *suffixes); |
289 | extern unsigned long bb_xgetularg_bnd(const char *arg, int base, | 294 | unsigned long xstrtoul_range(const char *numstr, int base, |
290 | unsigned long lower, | 295 | unsigned long lower, |
291 | unsigned long upper); | 296 | unsigned long upper); |
292 | extern unsigned long bb_xgetularg10_bnd(const char *arg, | 297 | unsigned long xstrtoul(const char *numstr, int base); |
298 | unsigned long xatoul_range_sfx(const char *numstr, | ||
299 | unsigned long lower, | ||
300 | unsigned long upper, | ||
301 | const struct suffix_mult *suffixes); | ||
302 | unsigned long xatoul_sfx(const char *numstr, | ||
303 | const struct suffix_mult *suffixes); | ||
304 | unsigned long xatoul_range(const char *numstr, | ||
293 | unsigned long lower, | 305 | unsigned long lower, |
294 | unsigned long upper); | 306 | unsigned long upper); |
295 | extern unsigned long bb_xgetularg10(const char *arg); | 307 | unsigned long xatoul(const char *numstr); |
296 | 308 | unsigned long long xatoull(const char *numstr); | |
297 | extern long bb_xgetlarg(const char *arg, int base, | 309 | long xstrtol_range_sfx(const char *numstr, int base, |
298 | long lower, | ||
299 | long upper); | ||
300 | extern long bb_xgetlarg_bnd_sfx(const char *arg, int base, | ||
301 | long lower, | 310 | long lower, |
302 | long upper, | 311 | long upper, |
303 | const struct suffix_mult *suffixes); | 312 | const struct suffix_mult *suffixes); |
304 | extern long bb_xgetlarg10_sfx(const char *arg, const struct suffix_mult *suffixes); | 313 | long xstrtol_range(const char *numstr, int base, long lower, long upper); |
305 | 314 | long xatol_range_sfx(const char *numstr, | |
306 | 315 | long lower, | |
307 | extern unsigned long bb_xparse_number(const char *numstr, | 316 | long upper, |
308 | const struct suffix_mult *suffixes); | 317 | const struct suffix_mult *suffixes); |
309 | 318 | long xatol_range(const char *numstr, long lower, long upper); | |
319 | long xatol_sfx(const char *numstr, const struct suffix_mult *suffixes); | ||
320 | long xatol(const char *numstr); | ||
321 | /* Specialized: */ | ||
322 | unsigned xatou(const char *numstr); | ||
323 | int xatoi(const char *numstr); | ||
324 | /* Using xatoi() instead of naive atoi() is not always convenient - | ||
325 | * in many places people want *non-negative* values, but store them | ||
326 | * in signed int. Therefore we need this one: | ||
327 | * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc */ | ||
328 | int xatoi_u(const char *numstr); | ||
329 | uint32_t xatou32(const char *numstr); | ||
330 | /* Useful for reading port numbers */ | ||
331 | uint16_t xatou16(const char *numstr); | ||
310 | 332 | ||
311 | /* These parse entries in /etc/passwd and /etc/group. This is desirable | 333 | /* These parse entries in /etc/passwd and /etc/group. This is desirable |
312 | * for BusyBox since we want to avoid using the glibc NSS stuff, which | 334 | * for BusyBox since we want to avoid using the glibc NSS stuff, which |
@@ -329,7 +351,7 @@ extern int device_open(const char *device, int mode); | |||
329 | 351 | ||
330 | extern char *query_loop(const char *device); | 352 | extern char *query_loop(const char *device); |
331 | extern int del_loop(const char *device); | 353 | extern int del_loop(const char *device); |
332 | extern int set_loop(char **device, const char *file, int offset); | 354 | extern int set_loop(char **device, const char *file, unsigned long long offset); |
333 | 355 | ||
334 | #if (__GLIBC__ < 2) | 356 | #if (__GLIBC__ < 2) |
335 | extern int vdprintf(int d, const char *format, va_list ap); | 357 | extern int vdprintf(int d, const char *format, va_list ap); |
diff --git a/include/unarchive.h b/include/unarchive.h index 82a70aed6..7de6a63fe 100644 --- a/include/unarchive.h +++ b/include/unarchive.h | |||
@@ -92,7 +92,7 @@ extern char get_header_tar_lzma(archive_handle_t *archive_handle); | |||
92 | extern char get_header_tar_gz(archive_handle_t *archive_handle); | 92 | extern char get_header_tar_gz(archive_handle_t *archive_handle); |
93 | 93 | ||
94 | extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount); | 94 | extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount); |
95 | extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int amount); | 95 | extern void seek_by_read(const archive_handle_t *archive_handle, const unsigned int amount); |
96 | 96 | ||
97 | extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count); | 97 | extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count); |
98 | 98 | ||
diff --git a/init/halt.c b/init/halt.c index 2ac210e59..9e3cbb1cf 100644 --- a/init/halt.c +++ b/init/halt.c | |||
@@ -35,7 +35,7 @@ RB_AUTOBOOT | |||
35 | 35 | ||
36 | /* Parse and handle arguments */ | 36 | /* Parse and handle arguments */ |
37 | flags = getopt32(argc, argv, "d:nf", &delay); | 37 | flags = getopt32(argc, argv, "d:nf", &delay); |
38 | if (flags&1) sleep(atoi(delay)); | 38 | if (flags&1) sleep(xatou(delay)); |
39 | if (!(flags&2)) sync(); | 39 | if (!(flags&2)) sync(); |
40 | 40 | ||
41 | /* Perform action. */ | 41 | /* Perform action. */ |
diff --git a/libbb/Kbuild b/libbb/Kbuild index 909f527ba..4e992ef5b 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
@@ -15,7 +15,7 @@ lib-y:= \ | |||
15 | human_readable.o inet_common.o inode_hash.o isdirectory.o \ | 15 | human_readable.o inet_common.o inode_hash.o isdirectory.o \ |
16 | kernel_version.o last_char_is.o login.o \ | 16 | kernel_version.o last_char_is.o login.o \ |
17 | make_directory.o md5.o mode_string.o mtab_file.o \ | 17 | make_directory.o md5.o mode_string.o mtab_file.o \ |
18 | obscure.o parse_mode.o parse_number.o perror_msg.o \ | 18 | obscure.o parse_mode.o perror_msg.o \ |
19 | perror_msg_and_die.o get_console.o \ | 19 | perror_msg_and_die.o get_console.o \ |
20 | process_escape_sequence.o procps.o \ | 20 | process_escape_sequence.o procps.o \ |
21 | recursive_action.o remove_file.o \ | 21 | recursive_action.o remove_file.o \ |
@@ -23,7 +23,7 @@ lib-y:= \ | |||
23 | safe_strncpy.o setup_environment.o sha1.o simplify_path.o \ | 23 | safe_strncpy.o setup_environment.o sha1.o simplify_path.o \ |
24 | trim.o u_signal_names.o vdprintf.o verror_msg.o \ | 24 | trim.o u_signal_names.o vdprintf.o verror_msg.o \ |
25 | vherror_msg.o vperror_msg.o wfopen.o xconnect.o xgetcwd.o \ | 25 | vherror_msg.o vperror_msg.o wfopen.o xconnect.o xgetcwd.o \ |
26 | xgethostbyname.o xgethostbyname2.o xreadlink.o xgetlarg.o \ | 26 | xgethostbyname.o xgethostbyname2.o xreadlink.o \ |
27 | fclose_nonstdin.o fflush_stdout_and_exit.o \ | 27 | fclose_nonstdin.o fflush_stdout_and_exit.o \ |
28 | getopt32.o default_error_retval.o wfopen_input.o speed_table.o \ | 28 | getopt32.o default_error_retval.o wfopen_input.o speed_table.o \ |
29 | perror_nomsg_and_die.o perror_nomsg.o skip_whitespace.o bb_askpass.o \ | 29 | perror_nomsg_and_die.o perror_nomsg.o skip_whitespace.o bb_askpass.o \ |
@@ -55,7 +55,7 @@ lib-$(CONFIG_DEVFSD) += xregcomp.o | |||
55 | lib-y += messages.o | 55 | lib-y += messages.o |
56 | lib-y += xfuncs.o | 56 | lib-y += xfuncs.o |
57 | lib-y += printf.o | 57 | lib-y += printf.o |
58 | lib-y += xgetularg.o | 58 | lib-y += xatol.o |
59 | lib-y += safe_strtol.o | 59 | lib-y += safe_strtol.o |
60 | lib-y += bb_pwd.o | 60 | lib-y += bb_pwd.o |
61 | lib-y += llist.o | 61 | lib-y += llist.o |
diff --git a/libbb/loop.c b/libbb/loop.c index d22b39800..1b296d99b 100644 --- a/libbb/loop.c +++ b/libbb/loop.c | |||
@@ -48,11 +48,12 @@ char *query_loop(const char *device) | |||
48 | { | 48 | { |
49 | int fd; | 49 | int fd; |
50 | bb_loop_info loopinfo; | 50 | bb_loop_info loopinfo; |
51 | char *dev=0; | 51 | char *dev = 0; |
52 | 52 | ||
53 | if ((fd = open(device, O_RDONLY)) < 0) return 0; | 53 | fd = open(device, O_RDONLY); |
54 | if (fd < 0) return 0; | ||
54 | if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo)) | 55 | if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo)) |
55 | dev=xasprintf("%ld %s", (long) loopinfo.lo_offset, | 56 | dev = xasprintf("%ld %s", (long) loopinfo.lo_offset, |
56 | (char *)loopinfo.lo_file_name); | 57 | (char *)loopinfo.lo_file_name); |
57 | close(fd); | 58 | close(fd); |
58 | 59 | ||
@@ -64,8 +65,9 @@ int del_loop(const char *device) | |||
64 | { | 65 | { |
65 | int fd, rc; | 66 | int fd, rc; |
66 | 67 | ||
67 | if ((fd = open(device, O_RDONLY)) < 0) return 1; | 68 | fd = open(device, O_RDONLY); |
68 | rc=ioctl(fd, LOOP_CLR_FD, 0); | 69 | if (fd < 0) return 1; |
70 | rc = ioctl(fd, LOOP_CLR_FD, 0); | ||
69 | close(fd); | 71 | close(fd); |
70 | 72 | ||
71 | return rc; | 73 | return rc; |
@@ -77,7 +79,7 @@ int del_loop(const char *device) | |||
77 | search will re-use an existing loop device already bound to that | 79 | search will re-use an existing loop device already bound to that |
78 | file/offset if it finds one. | 80 | file/offset if it finds one. |
79 | */ | 81 | */ |
80 | int set_loop(char **device, const char *file, int offset) | 82 | int set_loop(char **device, const char *file, unsigned long long offset) |
81 | { | 83 | { |
82 | char dev[20], *try; | 84 | char dev[20], *try; |
83 | bb_loop_info loopinfo; | 85 | bb_loop_info loopinfo; |
@@ -85,34 +87,43 @@ int set_loop(char **device, const char *file, int offset) | |||
85 | int i, dfd, ffd, mode, rc=-1; | 87 | int i, dfd, ffd, mode, rc=-1; |
86 | 88 | ||
87 | /* Open the file. Barf if this doesn't work. */ | 89 | /* Open the file. Barf if this doesn't work. */ |
88 | if((ffd = open(file, mode=O_RDWR))<0 && (ffd = open(file,mode=O_RDONLY))<0) | 90 | mode = O_RDWR; |
89 | return -errno; | 91 | ffd = open(file, mode); |
92 | if (ffd < 0) { | ||
93 | mode = O_RDONLY; | ||
94 | ffd = open(file, mode); | ||
95 | if (ffd < 0) | ||
96 | return -errno; | ||
97 | } | ||
90 | 98 | ||
91 | /* Find a loop device. */ | 99 | /* Find a loop device. */ |
92 | try=*device ? : dev; | 100 | try = *device ? : dev; |
93 | for(i=0;rc;i++) { | 101 | for (i=0;rc;i++) { |
94 | sprintf(dev, LOOP_FORMAT, i); | 102 | sprintf(dev, LOOP_FORMAT, i); |
95 | 103 | ||
96 | /* Ran out of block devices, return failure. */ | 104 | /* Ran out of block devices, return failure. */ |
97 | if(stat(try, &statbuf) || !S_ISBLK(statbuf.st_mode)) { | 105 | if (stat(try, &statbuf) || !S_ISBLK(statbuf.st_mode)) { |
98 | rc=-ENOENT; | 106 | rc=-ENOENT; |
99 | break; | 107 | break; |
100 | } | 108 | } |
101 | /* Open the sucker and check its loopiness. */ | 109 | /* Open the sucker and check its loopiness. */ |
102 | if((dfd=open(try, mode))<0 && errno==EROFS) | 110 | dfd = open(try, mode); |
103 | dfd=open(try, mode = O_RDONLY); | 111 | if (dfd < 0 && errno == EROFS) { |
104 | if(dfd<0) goto try_again; | 112 | mode = O_RDONLY; |
113 | dfd = open(try, mode); | ||
114 | } | ||
115 | if (dfd < 0) goto try_again; | ||
105 | 116 | ||
106 | rc=ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo); | 117 | rc = ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo); |
107 | 118 | ||
108 | /* If device free, claim it. */ | 119 | /* If device free, claim it. */ |
109 | if(rc && errno==ENXIO) { | 120 | if (rc && errno == ENXIO) { |
110 | memset(&loopinfo, 0, sizeof(loopinfo)); | 121 | memset(&loopinfo, 0, sizeof(loopinfo)); |
111 | safe_strncpy((char *)loopinfo.lo_file_name, file, LO_NAME_SIZE); | 122 | safe_strncpy((char *)loopinfo.lo_file_name, file, LO_NAME_SIZE); |
112 | loopinfo.lo_offset = offset; | 123 | loopinfo.lo_offset = offset; |
113 | /* Associate free loop device with file. */ | 124 | /* Associate free loop device with file. */ |
114 | if(!ioctl(dfd, LOOP_SET_FD, ffd)) { | 125 | if (!ioctl(dfd, LOOP_SET_FD, ffd)) { |
115 | if (!ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc=0; | 126 | if (!ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc = 0; |
116 | else ioctl(dfd, LOOP_CLR_FD, 0); | 127 | else ioctl(dfd, LOOP_CLR_FD, 0); |
117 | } | 128 | } |
118 | 129 | ||
@@ -121,15 +132,16 @@ int set_loop(char **device, const char *file, int offset) | |||
121 | file isn't pretty either. In general, mounting the same file twice | 132 | file isn't pretty either. In general, mounting the same file twice |
122 | without using losetup manually is problematic.) | 133 | without using losetup manually is problematic.) |
123 | */ | 134 | */ |
124 | } else if(strcmp(file,(char *)loopinfo.lo_file_name) | 135 | } else if (strcmp(file,(char *)loopinfo.lo_file_name) |
125 | || offset!=loopinfo.lo_offset) rc=-1; | 136 | || offset!=loopinfo.lo_offset) rc = -1; |
126 | close(dfd); | 137 | close(dfd); |
127 | try_again: | 138 | try_again: |
128 | if(*device) break; | 139 | if (*device) break; |
129 | } | 140 | } |
130 | close(ffd); | 141 | close(ffd); |
131 | if(!rc) { | 142 | if (!rc) { |
132 | if(!*device) *device=strdup(dev); | 143 | if (!*device) *device = strdup(dev); |
133 | return mode==O_RDONLY ? 1 : 0; | 144 | return mode==O_RDONLY ? 1 : 0; |
134 | } else return rc; | 145 | } |
146 | return rc; | ||
135 | } | 147 | } |
diff --git a/libbb/parse_number.c b/libbb/parse_number.c deleted file mode 100644 index c7dafb7f0..000000000 --- a/libbb/parse_number.c +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * bb_xparse_number implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | |||
10 | #include <stdlib.h> | ||
11 | #include <string.h> | ||
12 | #include <limits.h> | ||
13 | #include <errno.h> | ||
14 | #include <assert.h> | ||
15 | #include "libbb.h" | ||
16 | |||
17 | unsigned long bb_xparse_number(const char *numstr, | ||
18 | const struct suffix_mult *suffixes) | ||
19 | { | ||
20 | unsigned long int r; | ||
21 | char *e; | ||
22 | int old_errno; | ||
23 | |||
24 | /* Since this is a lib function, we're not allowed to reset errno to 0. | ||
25 | * Doing so could break an app that is deferring checking of errno. | ||
26 | * So, save the old value so that we can restore it if successful. */ | ||
27 | old_errno = errno; | ||
28 | errno = 0; | ||
29 | r = strtoul(numstr, &e, 10); | ||
30 | |||
31 | if ((numstr != e) && !errno) { | ||
32 | errno = old_errno; /* Ok. So restore errno. */ | ||
33 | if (!*e) { | ||
34 | return r; | ||
35 | } | ||
36 | if (suffixes) { | ||
37 | assert(suffixes->suffix); /* No nul suffixes. */ | ||
38 | do { | ||
39 | if (strcmp(suffixes->suffix, e) == 0) { | ||
40 | if (ULONG_MAX / suffixes->mult < r) { /* Overflow! */ | ||
41 | break; | ||
42 | } | ||
43 | return r * suffixes->mult; | ||
44 | } | ||
45 | ++suffixes; | ||
46 | } while (suffixes->suffix); | ||
47 | } | ||
48 | } | ||
49 | bb_error_msg_and_die("invalid number '%s'", numstr); | ||
50 | } | ||
diff --git a/libbb/safe_strtol.c b/libbb/safe_strtol.c index 027fc1e62..a7f012fbc 100644 --- a/libbb/safe_strtol.c +++ b/libbb/safe_strtol.c | |||
@@ -7,21 +7,10 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdlib.h> | ||
11 | #include <errno.h> | ||
12 | #include <assert.h> | 10 | #include <assert.h> |
13 | #include "libbb.h" | 11 | #include "libbb.h" |
14 | 12 | ||
15 | int safe_strtoi(char *arg, int* value) | 13 | int safe_strtod(const char *arg, double* value) |
16 | { | ||
17 | int error; | ||
18 | long lvalue = *value; | ||
19 | error = safe_strtol(arg, &lvalue); | ||
20 | *value = (int) lvalue; | ||
21 | return error; | ||
22 | } | ||
23 | |||
24 | int safe_strtod(char *arg, double* value) | ||
25 | { | 14 | { |
26 | char *endptr; | 15 | char *endptr; |
27 | int errno_save = errno; | 16 | int errno_save = errno; |
@@ -29,69 +18,132 @@ int safe_strtod(char *arg, double* value) | |||
29 | assert(arg!=NULL); | 18 | assert(arg!=NULL); |
30 | errno = 0; | 19 | errno = 0; |
31 | *value = strtod(arg, &endptr); | 20 | *value = strtod(arg, &endptr); |
32 | if (errno != 0 || *endptr!='\0' || endptr==arg) { | 21 | if (errno != 0 || *endptr != '\0' || endptr == arg) { |
33 | return 1; | 22 | return 1; |
34 | } | 23 | } |
35 | errno = errno_save; | 24 | errno = errno_save; |
36 | return 0; | 25 | return 0; |
37 | } | 26 | } |
38 | 27 | ||
39 | int safe_strtol(char *arg, long* value) | 28 | int safe_strtoull(const char *arg, unsigned long long* value) |
40 | { | 29 | { |
41 | char *endptr; | 30 | char *endptr; |
42 | int errno_save = errno; | 31 | int errno_save = errno; |
43 | 32 | ||
44 | assert(arg!=NULL); | 33 | assert(arg!=NULL); |
34 | if (!isdigit(arg[0])) /* strtouXX takes minus signs w/o error! :( */ | ||
35 | return 1; | ||
45 | errno = 0; | 36 | errno = 0; |
46 | *value = strtol(arg, &endptr, 0); | 37 | *value = strtoull(arg, &endptr, 0); |
47 | if (errno != 0 || *endptr!='\0' || endptr==arg) { | 38 | if (errno != 0 || *endptr != '\0' || endptr == arg) { |
48 | return 1; | 39 | return 1; |
49 | } | 40 | } |
50 | errno = errno_save; | 41 | errno = errno_save; |
51 | return 0; | 42 | return 0; |
52 | } | 43 | } |
53 | 44 | ||
54 | int safe_strtoul(char *arg, unsigned long* value) | 45 | int safe_strtoll(const char *arg, long long* value) |
55 | { | 46 | { |
56 | char *endptr; | 47 | char *endptr; |
57 | int errno_save = errno; | 48 | int errno_save = errno; |
58 | 49 | ||
59 | assert(arg!=NULL); | 50 | assert(arg!=NULL); |
60 | errno = 0; | 51 | errno = 0; |
61 | *value = strtoul(arg, &endptr, 0); | 52 | *value = strtoll(arg, &endptr, 0); |
62 | if (errno != 0 || *endptr!='\0' || endptr==arg) { | 53 | if (errno != 0 || *endptr != '\0' || endptr == arg) { |
63 | return 1; | 54 | return 1; |
64 | } | 55 | } |
65 | errno = errno_save; | 56 | errno = errno_save; |
66 | return 0; | 57 | return 0; |
67 | } | 58 | } |
68 | 59 | ||
69 | int safe_strtoll(char *arg, long long* value) | 60 | int safe_strtoul(const char *arg, unsigned long* value) |
70 | { | 61 | { |
71 | char *endptr; | 62 | char *endptr; |
72 | int errno_save = errno; | 63 | int errno_save = errno; |
73 | 64 | ||
74 | assert(arg!=NULL); | 65 | assert(arg!=NULL); |
66 | if (!isdigit(arg[0])) /* strtouXX takes minus signs w/o error! :( */ | ||
67 | return 1; | ||
75 | errno = 0; | 68 | errno = 0; |
76 | *value = strtoll(arg, &endptr, 0); | 69 | *value = strtoul(arg, &endptr, 0); |
77 | if (errno != 0 || *endptr!='\0' || endptr==arg) { | 70 | if (errno != 0 || *endptr != '\0' || endptr == arg) { |
78 | return 1; | 71 | return 1; |
79 | } | 72 | } |
80 | errno = errno_save; | 73 | errno = errno_save; |
81 | return 0; | 74 | return 0; |
82 | } | 75 | } |
83 | 76 | ||
84 | int safe_strtoull(char *arg, unsigned long long* value) | 77 | int safe_strtol(const char *arg, long* value) |
85 | { | 78 | { |
86 | char *endptr; | 79 | char *endptr; |
87 | int errno_save = errno; | 80 | int errno_save = errno; |
88 | 81 | ||
89 | assert(arg!=NULL); | 82 | assert(arg!=NULL); |
90 | errno = 0; | 83 | errno = 0; |
91 | *value = strtoull(arg, &endptr, 0); | 84 | *value = strtol(arg, &endptr, 0); |
92 | if (errno != 0 || *endptr!='\0' || endptr==arg) { | 85 | if (errno != 0 || *endptr != '\0' || endptr == arg) { |
93 | return 1; | 86 | return 1; |
94 | } | 87 | } |
95 | errno = errno_save; | 88 | errno = errno_save; |
96 | return 0; | 89 | return 0; |
97 | } | 90 | } |
91 | |||
92 | /* TODO: This is what uclibc is doing. Try to do the same? */ | ||
93 | |||
94 | #if 0 | ||
95 | #if defined __HAVE_ELF__ | ||
96 | |||
97 | # define strong_alias(name, aliasname) _strong_alias(name, aliasname) | ||
98 | # define _strong_alias(name, aliasname) \ | ||
99 | extern __typeof (name) aliasname __attribute__ ((alias (#name))); | ||
100 | |||
101 | #else /* !defined __HAVE_ELF__ */ | ||
102 | |||
103 | # define strong_alias(name, aliasname) _strong_alias (name, aliasname) | ||
104 | # define _strong_alias(name, aliasname) \ | ||
105 | __asm__(".global " __C_SYMBOL_PREFIX__ #aliasname "\n" \ | ||
106 | ".set " __C_SYMBOL_PREFIX__ #aliasname "," __C_SYMBOL_PREFIX__ #name); | ||
107 | |||
108 | #endif | ||
109 | #endif | ||
110 | |||
111 | int safe_strtoi(const char *arg, int* value) | ||
112 | { | ||
113 | if (sizeof(long) == sizeof(int)) { | ||
114 | return safe_strtol(arg, (long*)value); | ||
115 | } else { | ||
116 | int error; | ||
117 | long lvalue = *value; | ||
118 | error = safe_strtol(arg, &lvalue); | ||
119 | if (lvalue < INT_MIN || lvalue > INT_MAX) | ||
120 | return 1; | ||
121 | *value = (int) lvalue; | ||
122 | return error; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | int safe_strtou(const char *arg, unsigned* value) | ||
127 | { | ||
128 | if (sizeof(unsigned long) == sizeof(unsigned)) { | ||
129 | return safe_strtoul(arg, (unsigned long*)value); | ||
130 | } else { | ||
131 | int error; | ||
132 | unsigned long lvalue = *value; | ||
133 | error = safe_strtoul(arg, &lvalue); | ||
134 | if (lvalue > UINT_MAX) | ||
135 | return 1; | ||
136 | *value = (unsigned) lvalue; | ||
137 | return error; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | int BUG_safe_strtou32_unimplemented(void); | ||
142 | int safe_strtou32(const char *arg, uint32_t* value) | ||
143 | { | ||
144 | if (sizeof(uint32_t) == sizeof(unsigned)) | ||
145 | return safe_strtou(arg, (unsigned*)value); | ||
146 | if (sizeof(uint32_t) == sizeof(unsigned long)) | ||
147 | return safe_strtoul(arg, (unsigned long*)value); | ||
148 | return BUG_safe_strtou32_unimplemented(); | ||
149 | } | ||
diff --git a/libbb/xatol.c b/libbb/xatol.c new file mode 100644 index 000000000..82250a7bb --- /dev/null +++ b/libbb/xatol.c | |||
@@ -0,0 +1,210 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * ascii-to-numbers implementations for busybox | ||
4 | * | ||
5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> | ||
6 | * | ||
7 | * Licensed under GPLv2, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | |||
10 | #include "libbb.h" | ||
11 | |||
12 | unsigned long long xatoull(const char *numstr) | ||
13 | { | ||
14 | unsigned long long r; | ||
15 | int old_errno; | ||
16 | char *e; | ||
17 | if ((*numstr == '-') || (isspace)(*numstr)) | ||
18 | bb_error_msg_and_die("invalid number '%s'", numstr); | ||
19 | old_errno = errno; | ||
20 | errno = 0; | ||
21 | r = strtoull(numstr, &e, 10); | ||
22 | if (errno || (numstr == e) || *e) | ||
23 | /* Error / no digits / illegal trailing chars */ | ||
24 | bb_error_msg_and_die("invalid number '%s'", numstr); | ||
25 | /* No error. So restore errno. */ | ||
26 | errno = old_errno; | ||
27 | return r; | ||
28 | } | ||
29 | |||
30 | unsigned long xstrtoul_range_sfx(const char *numstr, int base, | ||
31 | unsigned long lower, | ||
32 | unsigned long upper, | ||
33 | const struct suffix_mult *suffixes) | ||
34 | { | ||
35 | unsigned long r; | ||
36 | int old_errno; | ||
37 | char *e; | ||
38 | |||
39 | /* Disallow '-' and any leading whitespace. Speed isn't critical here | ||
40 | * since we're parsing commandline args. So make sure we get the | ||
41 | * actual isspace function rather than a lnumstrer macro implementaion. */ | ||
42 | if ((*numstr == '-') || (isspace)(*numstr)) | ||
43 | goto inval; | ||
44 | |||
45 | /* Since this is a lib function, we're not allowed to reset errno to 0. | ||
46 | * Doing so could break an app that is deferring checking of errno. | ||
47 | * So, save the old value so that we can restore it if successful. */ | ||
48 | old_errno = errno; | ||
49 | errno = 0; | ||
50 | r = strtoul(numstr, &e, base); | ||
51 | /* Do the initial validity check. Note: The standards do not | ||
52 | * guarantee that errno is set if no digits were found. So we | ||
53 | * must test for this explicitly. */ | ||
54 | if (errno || (numstr == e)) | ||
55 | goto inval; /* error / no digits / illegal trailing chars */ | ||
56 | |||
57 | errno = old_errno; /* Ok. So restore errno. */ | ||
58 | |||
59 | /* Do optional suffix parsing. Allow 'empty' suffix tables. | ||
60 | * Note that we also allow nul suffixes with associated multipliers, | ||
61 | * to allow for scaling of the numstr by some default multiplier. */ | ||
62 | if (suffixes) { | ||
63 | while (suffixes->suffix) { | ||
64 | if (strcmp(suffixes->suffix, e) == 0) { | ||
65 | if (ULONG_MAX / suffixes->mult < r) | ||
66 | goto range; /* overflow! */ | ||
67 | ++e; | ||
68 | r *= suffixes->mult; | ||
69 | break; | ||
70 | } | ||
71 | ++suffixes; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | /* Note: trailing space is an error. | ||
76 | It would be easy enough to allow though if desired. */ | ||
77 | if (*e) | ||
78 | goto inval; | ||
79 | /* Finally, check for range limits. */ | ||
80 | if (r >= lower && r <= upper) | ||
81 | return r; | ||
82 | range: | ||
83 | bb_error_msg_and_die("number %s is not in %lu..%lu range", | ||
84 | numstr, lower, upper); | ||
85 | inval: | ||
86 | bb_error_msg_and_die("invalid number '%s'", numstr); | ||
87 | } | ||
88 | |||
89 | unsigned long xstrtoul_range(const char *numstr, int base, | ||
90 | unsigned long lower, | ||
91 | unsigned long upper) | ||
92 | { | ||
93 | return xstrtoul_range_sfx(numstr, base, lower, upper, NULL); | ||
94 | } | ||
95 | |||
96 | unsigned long xstrtoul(const char *numstr, int base) | ||
97 | { | ||
98 | return xstrtoul_range_sfx(numstr, base, 0, ULONG_MAX, NULL); | ||
99 | } | ||
100 | |||
101 | unsigned long xatoul_range_sfx(const char *numstr, | ||
102 | unsigned long lower, | ||
103 | unsigned long upper, | ||
104 | const struct suffix_mult *suffixes) | ||
105 | { | ||
106 | return xstrtoul_range_sfx(numstr, 10, lower, upper, suffixes); | ||
107 | } | ||
108 | |||
109 | unsigned long xatoul_sfx(const char *numstr, | ||
110 | const struct suffix_mult *suffixes) | ||
111 | { | ||
112 | return xstrtoul_range_sfx(numstr, 10, 0, ULONG_MAX, suffixes); | ||
113 | } | ||
114 | |||
115 | unsigned long xatoul_range(const char *numstr, | ||
116 | unsigned long lower, | ||
117 | unsigned long upper) | ||
118 | { | ||
119 | return xstrtol_range_sfx(numstr, 10, lower, upper, NULL); | ||
120 | } | ||
121 | |||
122 | unsigned long xatoul(const char *numstr) | ||
123 | { | ||
124 | return xatoul_sfx(numstr, NULL); | ||
125 | } | ||
126 | |||
127 | /* Signed ones */ | ||
128 | |||
129 | long xstrtol_range_sfx(const char *numstr, int base, | ||
130 | long lower, | ||
131 | long upper, | ||
132 | const struct suffix_mult *suffixes) | ||
133 | { | ||
134 | unsigned long u = LONG_MAX; | ||
135 | long r; | ||
136 | const char *p = numstr; | ||
137 | |||
138 | if ((p[0] == '-') && (p[1] != '+')) { | ||
139 | ++p; | ||
140 | ++u; /* two's complement */ | ||
141 | } | ||
142 | |||
143 | r = xstrtoul_range_sfx(p, base, 0, u, suffixes); | ||
144 | |||
145 | if (*numstr == '-') { | ||
146 | r = -r; | ||
147 | } | ||
148 | |||
149 | if (r < lower || r > upper) { | ||
150 | bb_error_msg_and_die("number %s is not in %ld..%ld range", | ||
151 | numstr, lower, upper); | ||
152 | } | ||
153 | |||
154 | return r; | ||
155 | } | ||
156 | |||
157 | long xstrtol_range(const char *numstr, int base, long lower, long upper) | ||
158 | { | ||
159 | return xstrtol_range_sfx(numstr, base, lower, upper, NULL); | ||
160 | } | ||
161 | |||
162 | long xatol_range_sfx(const char *numstr, | ||
163 | long lower, | ||
164 | long upper, | ||
165 | const struct suffix_mult *suffixes) | ||
166 | { | ||
167 | return xstrtol_range_sfx(numstr, 10, lower, upper, suffixes); | ||
168 | } | ||
169 | |||
170 | long xatol_range(const char *numstr, long lower, long upper) | ||
171 | { | ||
172 | return xstrtol_range_sfx(numstr, 10, lower, upper, NULL); | ||
173 | } | ||
174 | |||
175 | long xatol_sfx(const char *numstr, const struct suffix_mult *suffixes) | ||
176 | { | ||
177 | return xstrtol_range_sfx(numstr, 10, LONG_MIN, LONG_MAX, suffixes); | ||
178 | } | ||
179 | |||
180 | long xatol(const char *numstr) | ||
181 | { | ||
182 | return xstrtol_range_sfx(numstr, 10, LONG_MIN, LONG_MAX, NULL); | ||
183 | } | ||
184 | |||
185 | /* Others */ | ||
186 | |||
187 | unsigned xatou(const char *numstr) | ||
188 | { | ||
189 | return xatoul_range(numstr, 0, UINT_MAX); | ||
190 | } | ||
191 | |||
192 | int xatoi(const char *numstr) | ||
193 | { | ||
194 | return xatol_range(numstr, INT_MIN, INT_MAX); | ||
195 | } | ||
196 | |||
197 | int xatoi_u(const char *numstr) | ||
198 | { | ||
199 | return xatoul_range(numstr, 0, INT_MAX); | ||
200 | } | ||
201 | |||
202 | uint32_t xatou32(const char *numstr) | ||
203 | { | ||
204 | return xatoul_range(numstr, 0, 0xffffffff); | ||
205 | } | ||
206 | |||
207 | uint16_t xatou16(const char *numstr) | ||
208 | { | ||
209 | return xatoul_range(numstr, 0, 0xffff); | ||
210 | } | ||
diff --git a/libbb/xgetlarg.c b/libbb/xgetlarg.c deleted file mode 100644 index 5b1e7b9d5..000000000 --- a/libbb/xgetlarg.c +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Copyright (C) 2003-2004 Erik Andersen <andersen@codepoet.org> | ||
4 | * | ||
5 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
6 | */ | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <getopt.h> | ||
11 | #include <errno.h> | ||
12 | #include <assert.h> | ||
13 | #include <ctype.h> | ||
14 | |||
15 | #include "libbb.h" | ||
16 | |||
17 | long bb_xgetlarg(const char *arg, int base, long lower, long upper) | ||
18 | { | ||
19 | long result; | ||
20 | char *endptr; | ||
21 | int errno_save = errno; | ||
22 | |||
23 | if (ENABLE_DEBUG && arg==NULL) | ||
24 | bb_error_msg_and_die("Null in xgetlarg."); | ||
25 | |||
26 | errno = 0; | ||
27 | result = strtol(arg, &endptr, base); | ||
28 | if (errno != 0 || *endptr!='\0' || endptr==arg || result < lower || result > upper) | ||
29 | bb_show_usage(); | ||
30 | errno = errno_save; | ||
31 | return result; | ||
32 | } | ||
diff --git a/libbb/xgetularg.c b/libbb/xgetularg.c deleted file mode 100644 index 17ba581f7..000000000 --- a/libbb/xgetularg.c +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * xgetularg* implementations for busybox | ||
4 | * | ||
5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | |||
10 | #include <stdlib.h> | ||
11 | #include <string.h> | ||
12 | #include <limits.h> | ||
13 | #include <ctype.h> | ||
14 | #include <errno.h> | ||
15 | #include <assert.h> | ||
16 | #include "libbb.h" | ||
17 | |||
18 | unsigned long bb_xgetularg_bnd_sfx(const char *arg, int base, | ||
19 | unsigned long lower, | ||
20 | unsigned long upper, | ||
21 | const struct suffix_mult *suffixes) | ||
22 | { | ||
23 | unsigned long r; | ||
24 | int old_errno; | ||
25 | char *e; | ||
26 | |||
27 | assert(arg); | ||
28 | |||
29 | /* Disallow '-' and any leading whitespace. Speed isn't critical here | ||
30 | * since we're parsing commandline args. So make sure we get the | ||
31 | * actual isspace function rather than a larger macro implementaion. */ | ||
32 | if ((*arg == '-') || (isspace)(*arg)) { | ||
33 | bb_show_usage(); | ||
34 | } | ||
35 | |||
36 | /* Since this is a lib function, we're not allowed to reset errno to 0. | ||
37 | * Doing so could break an app that is deferring checking of errno. | ||
38 | * So, save the old value so that we can restore it if successful. */ | ||
39 | old_errno = errno; | ||
40 | errno = 0; | ||
41 | r = strtoul(arg, &e, base); | ||
42 | /* Do the initial validity check. Note: The standards do not | ||
43 | * guarantee that errno is set if no digits were found. So we | ||
44 | * must test for this explicitly. */ | ||
45 | if (errno || (arg == e)) { /* error or no digits */ | ||
46 | bb_show_usage(); | ||
47 | } | ||
48 | errno = old_errno; /* Ok. So restore errno. */ | ||
49 | |||
50 | /* Do optional suffix parsing. Allow 'empty' suffix tables. | ||
51 | * Note that we also all nul suffixes with associated multipliers, | ||
52 | * to allow for scaling of the arg by some default multiplier. */ | ||
53 | |||
54 | if (suffixes) { | ||
55 | while (suffixes->suffix) { | ||
56 | if (strcmp(suffixes->suffix, e) == 0) { | ||
57 | if (ULONG_MAX / suffixes->mult < r) { /* Overflow! */ | ||
58 | bb_show_usage(); | ||
59 | } | ||
60 | ++e; | ||
61 | r *= suffixes->mult; | ||
62 | break; | ||
63 | } | ||
64 | ++suffixes; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | /* Finally, check for illegal trailing chars and range limits. */ | ||
69 | /* Note: although we allow leading space (via stroul), trailing space | ||
70 | * is an error. It would be easy enough to allow though if desired. */ | ||
71 | if (*e || (r < lower) || (r > upper)) { | ||
72 | bb_show_usage(); | ||
73 | } | ||
74 | |||
75 | return r; | ||
76 | } | ||
77 | |||
78 | long bb_xgetlarg_bnd_sfx(const char *arg, int base, | ||
79 | long lower, | ||
80 | long upper, | ||
81 | const struct suffix_mult *suffixes) | ||
82 | { | ||
83 | unsigned long u = LONG_MAX; | ||
84 | long r; | ||
85 | const char *p = arg; | ||
86 | |||
87 | if ((*p == '-') && (p[1] != '+')) { | ||
88 | ++p; | ||
89 | ++u; /* two's complement */ | ||
90 | } | ||
91 | |||
92 | r = bb_xgetularg_bnd_sfx(p, base, 0, u, suffixes); | ||
93 | |||
94 | if (*arg == '-') { | ||
95 | r = -r; | ||
96 | } | ||
97 | |||
98 | if ((r < lower) || (r > upper)) { | ||
99 | bb_show_usage(); | ||
100 | } | ||
101 | |||
102 | return r; | ||
103 | } | ||
104 | |||
105 | long bb_xgetlarg10_sfx(const char *arg, const struct suffix_mult *suffixes) | ||
106 | { | ||
107 | return bb_xgetlarg_bnd_sfx(arg, 10, LONG_MIN, LONG_MAX, suffixes); | ||
108 | } | ||
109 | |||
110 | unsigned long bb_xgetularg_bnd(const char *arg, int base, | ||
111 | unsigned long lower, | ||
112 | unsigned long upper) | ||
113 | { | ||
114 | return bb_xgetularg_bnd_sfx(arg, base, lower, upper, NULL); | ||
115 | } | ||
116 | |||
117 | unsigned long bb_xgetularg10_bnd(const char *arg, | ||
118 | unsigned long lower, | ||
119 | unsigned long upper) | ||
120 | { | ||
121 | return bb_xgetularg_bnd(arg, 10, lower, upper); | ||
122 | } | ||
123 | |||
124 | unsigned long bb_xgetularg10(const char *arg) | ||
125 | { | ||
126 | return bb_xgetularg10_bnd(arg, 0, ULONG_MAX); | ||
127 | } | ||
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c index 236dc1099..0172e6041 100644 --- a/loginutils/addgroup.c +++ b/loginutils/addgroup.c | |||
@@ -91,15 +91,14 @@ int addgroup_main(int argc, char **argv) | |||
91 | 91 | ||
92 | /* check for min, max and missing args and exit on error */ | 92 | /* check for min, max and missing args and exit on error */ |
93 | opt_complementary = "-1:?2:?"; | 93 | opt_complementary = "-1:?2:?"; |
94 | |||
95 | if (getopt32(argc, argv, "g:", &group)) { | 94 | if (getopt32(argc, argv, "g:", &group)) { |
96 | gid = bb_xgetlarg(group, 10, 0, LONG_MAX); | 95 | gid = xatoul_range(group, 0, (gid_t)ULONG_MAX); |
97 | } | 96 | } |
98 | /* move past the commandline options */ | 97 | /* move past the commandline options */ |
99 | argv += optind; | 98 | argv += optind; |
100 | 99 | ||
101 | /* need to be root */ | 100 | /* need to be root */ |
102 | if(geteuid()) { | 101 | if (geteuid()) { |
103 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); | 102 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
104 | } | 103 | } |
105 | 104 | ||
diff --git a/loginutils/getty.c b/loginutils/getty.c index 4b43684a2..d279dc3a4 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c | |||
@@ -113,7 +113,7 @@ extern void updwtmp(const char *filename, const struct utmp *ut); | |||
113 | 113 | ||
114 | struct options { | 114 | struct options { |
115 | int flags; /* toggle switches, see below */ | 115 | int flags; /* toggle switches, see below */ |
116 | int timeout; /* time-out period */ | 116 | unsigned timeout; /* time-out period */ |
117 | char *login; /* login program */ | 117 | char *login; /* login program */ |
118 | char *tty; /* name of tty */ | 118 | char *tty; /* name of tty */ |
119 | char *initstring; /* modem init string */ | 119 | char *initstring; /* modem init string */ |
@@ -226,11 +226,12 @@ FILE *dbf; | |||
226 | static int bcode(const char *s) | 226 | static int bcode(const char *s) |
227 | { | 227 | { |
228 | int r; | 228 | int r; |
229 | unsigned long value; | 229 | unsigned value; |
230 | if (safe_strtoul((char *)s, &value)) { | 230 | if (safe_strtou((char *)s, &value)) { |
231 | return -1; | 231 | return -1; |
232 | } | 232 | } |
233 | if ((r = tty_value_to_baud(value)) > 0) { | 233 | r = tty_value_to_baud(value); |
234 | if (r > 0) { | ||
234 | return r; | 235 | return r; |
235 | } | 236 | } |
236 | return 0; | 237 | return 0; |
@@ -280,8 +281,7 @@ static void parse_args(int argc, char **argv, struct options *op) | |||
280 | } | 281 | } |
281 | op->flags ^= F_ISSUE; /* revert flag show /etc/issue */ | 282 | op->flags ^= F_ISSUE; /* revert flag show /etc/issue */ |
282 | if(op->flags & F_TIMEOUT) { | 283 | if(op->flags & F_TIMEOUT) { |
283 | if ((op->timeout = atoi(ts)) <= 0) | 284 | op->timeout = xatoul_range(ts, 1, INT_MAX); |
284 | bb_error_msg_and_die("bad timeout value: %s", ts); | ||
285 | } | 285 | } |
286 | debug("after getopt loop\n"); | 286 | debug("after getopt loop\n"); |
287 | if (argc < optind + 2) /* check parameter count */ | 287 | if (argc < optind + 2) /* check parameter count */ |
@@ -495,7 +495,8 @@ static void auto_baud(struct termio *tp) | |||
495 | buf[nread] = '\0'; | 495 | buf[nread] = '\0'; |
496 | for (bp = buf; bp < buf + nread; bp++) { | 496 | for (bp = buf; bp < buf + nread; bp++) { |
497 | if (isascii(*bp) && isdigit(*bp)) { | 497 | if (isascii(*bp) && isdigit(*bp)) { |
498 | if ((speed = bcode(bp))) { | 498 | speed = bcode(bp); |
499 | if (speed) { | ||
499 | tp->c_cflag &= ~CBAUD; | 500 | tp->c_cflag &= ~CBAUD; |
500 | tp->c_cflag |= speed; | 501 | tp->c_cflag |= speed; |
501 | } | 502 | } |
@@ -881,7 +882,7 @@ int getty_main(int argc, char **argv) | |||
881 | 882 | ||
882 | /* Set the optional timer. */ | 883 | /* Set the optional timer. */ |
883 | if (options.timeout) | 884 | if (options.timeout) |
884 | (void) alarm((unsigned) options.timeout); | 885 | (void) alarm(options.timeout); |
885 | 886 | ||
886 | /* optionally wait for CR or LF before writing /etc/issue */ | 887 | /* optionally wait for CR or LF before writing /etc/issue */ |
887 | if (options.flags & F_WAITCRLF) { | 888 | if (options.flags & F_WAITCRLF) { |
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index 40eb5e9cf..679439544 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c | |||
@@ -46,10 +46,8 @@ int sulogin_main(int argc, char **argv) | |||
46 | logmode = LOGMODE_BOTH; | 46 | logmode = LOGMODE_BOTH; |
47 | openlog(applet_name, 0, LOG_AUTH); | 47 | openlog(applet_name, 0, LOG_AUTH); |
48 | 48 | ||
49 | if (getopt32 (argc, argv, "t:", &timeout_arg)) { | 49 | if (getopt32(argc, argv, "t:", &timeout_arg)) { |
50 | if (safe_strtoi(timeout_arg, &timeout)) { | 50 | timeout = xatoi_u(timeout_arg); |
51 | timeout = 0; | ||
52 | } | ||
53 | } | 51 | } |
54 | 52 | ||
55 | if (argv[optind]) { | 53 | if (argv[optind]) { |
diff --git a/loginutils/vlock.c b/loginutils/vlock.c index 02d1ea772..9ab097b77 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c | |||
@@ -55,7 +55,7 @@ int vlock_main(int argc, char **argv) | |||
55 | bb_show_usage(); | 55 | bb_show_usage(); |
56 | } | 56 | } |
57 | 57 | ||
58 | o_lock_all = getopt32 (argc, argv, "a"); | 58 | o_lock_all = getopt32(argc, argv, "a"); |
59 | 59 | ||
60 | if((pw = getpwuid(getuid())) == NULL) { | 60 | if((pw = getpwuid(getuid())) == NULL) { |
61 | bb_error_msg_and_die("Unknown uid %d", getuid()); | 61 | bb_error_msg_and_die("Unknown uid %d", getuid()); |
diff --git a/miscutils/adjtimex.c b/miscutils/adjtimex.c index 47af1a5d2..b35538a84 100644 --- a/miscutils/adjtimex.c +++ b/miscutils/adjtimex.c | |||
@@ -12,10 +12,6 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include "busybox.h" | 14 | #include "busybox.h" |
15 | #include <stdio.h> | ||
16 | #include <sys/types.h> | ||
17 | #include <stdlib.h> | ||
18 | #include <unistd.h> | ||
19 | #include <sys/timex.h> | 15 | #include <sys/timex.h> |
20 | 16 | ||
21 | static const struct {int bit; const char *name;} statlist[] = { | 17 | static const struct {int bit; const char *name;} statlist[] = { |
@@ -58,19 +54,19 @@ int adjtimex_main(int argc, char **argv) | |||
58 | &opt_o, &opt_f, &opt_p, &opt_t); | 54 | &opt_o, &opt_f, &opt_p, &opt_t); |
59 | //if (opt & 0x1) // -q | 55 | //if (opt & 0x1) // -q |
60 | if (opt & 0x2) { // -o | 56 | if (opt & 0x2) { // -o |
61 | txc.offset = atoi(opt_o); | 57 | txc.offset = xatoi(opt_o); |
62 | txc.modes |= ADJ_OFFSET_SINGLESHOT; | 58 | txc.modes |= ADJ_OFFSET_SINGLESHOT; |
63 | } | 59 | } |
64 | if (opt & 0x4) { // -f | 60 | if (opt & 0x4) { // -f |
65 | txc.freq = atoi(opt_f); | 61 | txc.freq = xatou(opt_f); |
66 | txc.modes |= ADJ_FREQUENCY; | 62 | txc.modes |= ADJ_FREQUENCY; |
67 | } | 63 | } |
68 | if (opt & 0x8) { // -p | 64 | if (opt & 0x8) { // -p |
69 | txc.constant = atoi(opt_p); | 65 | txc.constant = xatoi(opt_p); |
70 | txc.modes |= ADJ_TIMECONST; | 66 | txc.modes |= ADJ_TIMECONST; |
71 | } | 67 | } |
72 | if (opt & 0x10) { // -t | 68 | if (opt & 0x10) { // -t |
73 | txc.tick = atoi(opt_t); | 69 | txc.tick = xatoi(opt_t); |
74 | txc.modes |= ADJ_TICK; | 70 | txc.modes |= ADJ_TICK; |
75 | } | 71 | } |
76 | if (argc != optind) { /* no valid non-option parameters */ | 72 | if (argc != optind) { /* no valid non-option parameters */ |
diff --git a/miscutils/crond.c b/miscutils/crond.c index db0cc2c6b..623e8c359 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -65,10 +65,10 @@ typedef struct CronLine { | |||
65 | #define DaemonUid 0 | 65 | #define DaemonUid 0 |
66 | 66 | ||
67 | #if ENABLE_DEBUG_CROND_OPTION | 67 | #if ENABLE_DEBUG_CROND_OPTION |
68 | static short DebugOpt; | 68 | static unsigned DebugOpt; |
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | static short LogLevel = 8; | 71 | static unsigned LogLevel = 8; |
72 | static const char *LogFile; | 72 | static const char *LogFile; |
73 | static const char *CDir = CRONTABS; | 73 | static const char *CDir = CRONTABS; |
74 | 74 | ||
@@ -155,7 +155,7 @@ int crond_main(int ac, char **av) | |||
155 | #endif | 155 | #endif |
156 | ); | 156 | ); |
157 | if (opt & 1) { | 157 | if (opt & 1) { |
158 | LogLevel = atoi(lopt); | 158 | LogLevel = xatou(lopt); |
159 | } | 159 | } |
160 | if (opt & 2) { | 160 | if (opt & 2) { |
161 | if (*Lopt != 0) { | 161 | if (*Lopt != 0) { |
@@ -169,7 +169,7 @@ int crond_main(int ac, char **av) | |||
169 | } | 169 | } |
170 | #if ENABLE_DEBUG_CROND_OPTION | 170 | #if ENABLE_DEBUG_CROND_OPTION |
171 | if (opt & 64) { | 171 | if (opt & 64) { |
172 | DebugOpt = atoi(dopt); | 172 | DebugOpt = xatou(dopt); |
173 | LogLevel = 0; | 173 | LogLevel = 0; |
174 | } | 174 | } |
175 | #endif | 175 | #endif |
diff --git a/miscutils/dc.c b/miscutils/dc.c index 95cf0d0ad..8e7a2494c 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c | |||
@@ -171,7 +171,7 @@ static void stack_machine(const char *argument) | |||
171 | } | 171 | } |
172 | o++; | 172 | o++; |
173 | } | 173 | } |
174 | bb_error_msg_and_die("%s: syntax error.", argument); | 174 | bb_error_msg_and_die("%s: syntax error", argument); |
175 | } | 175 | } |
176 | 176 | ||
177 | /* return pointer to next token in buffer and set *buffer to one char | 177 | /* return pointer to next token in buffer and set *buffer to one char |
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 6c46f6a92..1c9a99e13 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
@@ -2063,7 +2063,7 @@ static void parse_opts(unsigned long *get, unsigned long *set, unsigned long *va | |||
2063 | } | 2063 | } |
2064 | if (optarg) { | 2064 | if (optarg) { |
2065 | *set = 1; | 2065 | *set = 1; |
2066 | *value = bb_xgetlarg(optarg, 10, min, max); | 2066 | *value = xatol_range(optarg, min, max); |
2067 | } | 2067 | } |
2068 | } | 2068 | } |
2069 | 2069 | ||
@@ -2154,8 +2154,8 @@ int hdparm_main(int argc, char **argv) | |||
2154 | #if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF | 2154 | #if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
2155 | if (c == 'R') { | 2155 | if (c == 'R') { |
2156 | parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX); | 2156 | parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX); |
2157 | hwif_ctrl = bb_xgetlarg((argv[optind]) ? argv[optind] : "", 10, 0, INT_MAX); | 2157 | hwif_ctrl = xatoi_u((argv[optind]) ? argv[optind] : ""); |
2158 | hwif_irq = bb_xgetlarg((argv[optind+1]) ? argv[optind+1] : "", 10, 0, INT_MAX); | 2158 | hwif_irq = xatoi_u((argv[optind+1]) ? argv[optind+1] : ""); |
2159 | /* Move past the 2 additional arguments */ | 2159 | /* Move past the 2 additional arguments */ |
2160 | argv += 2; | 2160 | argv += 2; |
2161 | argc -= 2; | 2161 | argc -= 2; |
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index 4619e4dd5..e27634add 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c | |||
@@ -21,10 +21,10 @@ int makedevs_main(int argc, char **argv) | |||
21 | 21 | ||
22 | basedev = argv[1]; | 22 | basedev = argv[1]; |
23 | type = argv[2]; | 23 | type = argv[2]; |
24 | Smajor = atoi(argv[3]); | 24 | Smajor = xatoi_u(argv[3]); |
25 | Sminor = atoi(argv[4]); | 25 | Sminor = xatoi_u(argv[4]); |
26 | S = atoi(argv[5]); | 26 | S = xatoi_u(argv[5]); |
27 | E = atoi(argv[6]); | 27 | E = xatoi_u(argv[6]); |
28 | nodname = argc == 8 ? basedev : buf; | 28 | nodname = argc == 8 ? basedev : buf; |
29 | 29 | ||
30 | mode = 0660; | 30 | mode = 0660; |
diff --git a/miscutils/mt.c b/miscutils/mt.c index f4a3be739..a2bb6be91 100644 --- a/miscutils/mt.c +++ b/miscutils/mt.c | |||
@@ -84,7 +84,7 @@ int mt_main(int argc, char **argv) | |||
84 | 84 | ||
85 | op.mt_op = code->value; | 85 | op.mt_op = code->value; |
86 | if (argc >= 3) | 86 | if (argc >= 3) |
87 | op.mt_count = atoi(argv[2]); | 87 | op.mt_count = xatoi_u(argv[2]); |
88 | else | 88 | else |
89 | op.mt_count = 1; /* One, not zero, right? */ | 89 | op.mt_count = 1; /* One, not zero, right? */ |
90 | 90 | ||
diff --git a/miscutils/strings.c b/miscutils/strings.c index 36bcf8b17..1ff41ad9c 100644 --- a/miscutils/strings.c +++ b/miscutils/strings.c | |||
@@ -34,7 +34,7 @@ int strings_main(int argc, char **argv) | |||
34 | argc -= optind; | 34 | argc -= optind; |
35 | argv += optind; | 35 | argv += optind; |
36 | 36 | ||
37 | n = bb_xgetlarg(n_arg, 10, 1, INT_MAX); | 37 | n = xatoul_range(n_arg, 1, INT_MAX); |
38 | string = xzalloc(n + 1); | 38 | string = xzalloc(n + 1); |
39 | n--; | 39 | n--; |
40 | 40 | ||
@@ -45,7 +45,8 @@ int strings_main(int argc, char **argv) | |||
45 | } | 45 | } |
46 | 46 | ||
47 | do { | 47 | do { |
48 | if ((file = bb_wfopen(*argv, "r"))) { | 48 | file = bb_wfopen(*argv, "r"); |
49 | if (file) { | ||
49 | PIPE: | 50 | PIPE: |
50 | count = 0; | 51 | count = 0; |
51 | do { | 52 | do { |
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index ae51aba7b..e342c13f3 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c | |||
@@ -26,13 +26,13 @@ static void watchdog_shutdown(int ATTRIBUTE_UNUSED unused) | |||
26 | int watchdog_main(int argc, char **argv) | 26 | int watchdog_main(int argc, char **argv) |
27 | { | 27 | { |
28 | unsigned opts; | 28 | unsigned opts; |
29 | unsigned long timer_duration = 30; /* Userspace timer duration, in seconds */ | 29 | unsigned timer_duration = 30; /* Userspace timer duration, in seconds */ |
30 | char *t_arg; | 30 | char *t_arg; |
31 | 31 | ||
32 | opts = getopt32(argc, argv, "Ft:", &t_arg); | 32 | opts = getopt32(argc, argv, "Ft:", &t_arg); |
33 | 33 | ||
34 | if (opts & OPT_TIMER) | 34 | if (opts & OPT_TIMER) |
35 | timer_duration = bb_xgetlarg(t_arg, 10, 0, INT_MAX); | 35 | timer_duration = xatou(t_arg); |
36 | 36 | ||
37 | /* We're only interested in the watchdog device .. */ | 37 | /* We're only interested in the watchdog device .. */ |
38 | if (optind < argc - 1 || argc == 1) | 38 | if (optind < argc - 1 || argc == 1) |
diff --git a/modutils/insmod.c b/modutils/insmod.c index 348feed8d..cef47ff45 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
@@ -2652,7 +2652,7 @@ static int new_is_module_checksummed(struct obj_file *f) | |||
2652 | { | 2652 | { |
2653 | const char *p = get_modinfo_value(f, "using_checksums"); | 2653 | const char *p = get_modinfo_value(f, "using_checksums"); |
2654 | if (p) | 2654 | if (p) |
2655 | return atoi(p); | 2655 | return xatoi(p); |
2656 | else | 2656 | else |
2657 | return 0; | 2657 | return 0; |
2658 | } | 2658 | } |
diff --git a/networking/arping.c b/networking/arping.c index 1ff6f90be..b9605985c 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -41,8 +41,8 @@ enum cfg_e { | |||
41 | static int cfg; | 41 | static int cfg; |
42 | 42 | ||
43 | static int s; | 43 | static int s; |
44 | static int count = -1; | 44 | static unsigned count = UINT_MAX; |
45 | static int timeout; | 45 | static unsigned timeout; |
46 | static int sent; | 46 | static int sent; |
47 | static int brd_sent; | 47 | static int brd_sent; |
48 | static int received; | 48 | static int received; |
@@ -276,9 +276,9 @@ int arping_main(int argc, char **argv) | |||
276 | &_count, &_timeout, &device, &source); | 276 | &_count, &_timeout, &device, &source); |
277 | cfg |= opt & 0x3f; /* set respective flags */ | 277 | cfg |= opt & 0x3f; /* set respective flags */ |
278 | if (opt & 0x40) /* -c: count */ | 278 | if (opt & 0x40) /* -c: count */ |
279 | count = atoi(_count); | 279 | count = xatou(_count); |
280 | if (opt & 0x80) /* -w: timeout */ | 280 | if (opt & 0x80) /* -w: timeout */ |
281 | timeout = atoi(_timeout); | 281 | timeout = xatoul_range(_timeout, 0, INT_MAX/2000); |
282 | if (opt & 0x100) { /* -i: interface */ | 282 | if (opt & 0x100) { /* -i: interface */ |
283 | if (strlen(device) > IF_NAMESIZE) { | 283 | if (strlen(device) > IF_NAMESIZE) { |
284 | bb_error_msg_and_die("interface name '%s' is too long", | 284 | bb_error_msg_and_die("interface name '%s' is too long", |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 492854153..902528f93 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -42,15 +42,15 @@ static int ftpcmd(const char *s1, const char *s2, FILE *stream, char *buf) | |||
42 | char *buf_ptr; | 42 | char *buf_ptr; |
43 | 43 | ||
44 | if (fgets(buf, 510, stream) == NULL) { | 44 | if (fgets(buf, 510, stream) == NULL) { |
45 | bb_perror_msg_and_die("fgets()"); | 45 | bb_perror_msg_and_die("fgets"); |
46 | } | 46 | } |
47 | buf_ptr = strstr(buf, "\r\n"); | 47 | buf_ptr = strstr(buf, "\r\n"); |
48 | if (buf_ptr) { | 48 | if (buf_ptr) { |
49 | *buf_ptr = '\0'; | 49 | *buf_ptr = '\0'; |
50 | } | 50 | } |
51 | } while (! isdigit(buf[0]) || buf[3] != ' '); | 51 | } while (!isdigit(buf[0]) || buf[3] != ' '); |
52 | 52 | ||
53 | return atoi(buf); | 53 | return xatou(buf); |
54 | } | 54 | } |
55 | 55 | ||
56 | static int xconnect_ftpdata(ftp_host_info_t *server, const char *buf) | 56 | static int xconnect_ftpdata(ftp_host_info_t *server, const char *buf) |
@@ -60,14 +60,14 @@ static int xconnect_ftpdata(ftp_host_info_t *server, const char *buf) | |||
60 | 60 | ||
61 | buf_ptr = strrchr(buf, ','); | 61 | buf_ptr = strrchr(buf, ','); |
62 | *buf_ptr = '\0'; | 62 | *buf_ptr = '\0'; |
63 | port_num = atoi(buf_ptr + 1); | 63 | port_num = xatoul_range(buf_ptr + 1, 0, 255); |
64 | 64 | ||
65 | buf_ptr = strrchr(buf, ','); | 65 | buf_ptr = strrchr(buf, ','); |
66 | *buf_ptr = '\0'; | 66 | *buf_ptr = '\0'; |
67 | port_num += atoi(buf_ptr + 1) * 256; | 67 | port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256; |
68 | 68 | ||
69 | server->s_in->sin_port=htons(port_num); | 69 | server->s_in->sin_port = htons(port_num); |
70 | return(xconnect(server->s_in)); | 70 | return xconnect(server->s_in); |
71 | } | 71 | } |
72 | 72 | ||
73 | static FILE *ftp_login(ftp_host_info_t *server) | 73 | static FILE *ftp_login(ftp_host_info_t *server) |
diff --git a/networking/httpd.c b/networking/httpd.c index 0e471ba58..f3fe49cae 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1951,7 +1951,7 @@ int httpd_main(int argc, char *argv[]) | |||
1951 | #endif | 1951 | #endif |
1952 | #if ENABLE_FEATURE_HTTPD_WITHOUT_INETD | 1952 | #if ENABLE_FEATURE_HTTPD_WITHOUT_INETD |
1953 | if (opt & OPT_PORT) | 1953 | if (opt & OPT_PORT) |
1954 | config->port = bb_xgetlarg(s_port, 10, 1, 0xffff); | 1954 | config->port = xatou16(s_port); |
1955 | #if ENABLE_FEATURE_HTTPD_SETUID | 1955 | #if ENABLE_FEATURE_HTTPD_SETUID |
1956 | if (opt & OPT_SETUID) { | 1956 | if (opt & OPT_SETUID) { |
1957 | char *e; | 1957 | char *e; |
diff --git a/networking/ifconfig.c b/networking/ifconfig.c index 4d346c47f..59b6f0acc 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c | |||
@@ -379,7 +379,8 @@ int ifconfig_main(int argc, char **argv) | |||
379 | 379 | ||
380 | safe_strncpy(host, *argv, (sizeof host)); | 380 | safe_strncpy(host, *argv, (sizeof host)); |
381 | #ifdef CONFIG_FEATURE_IPV6 | 381 | #ifdef CONFIG_FEATURE_IPV6 |
382 | if ((prefix = strchr(host, '/'))) { | 382 | prefix = strchr(host, '/'); |
383 | if (prefix) { | ||
383 | if (safe_strtoi(prefix + 1, &prefix_len) || | 384 | if (safe_strtoi(prefix + 1, &prefix_len) || |
384 | (prefix_len < 0) || (prefix_len > 128)) | 385 | (prefix_len < 0) || (prefix_len > 128)) |
385 | { | 386 | { |
diff --git a/networking/inetd.c b/networking/inetd.c index e22115a5c..966425385 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -149,8 +149,6 @@ | |||
149 | #define _PATH_INETDPID "/var/run/inetd.pid" | 149 | #define _PATH_INETDPID "/var/run/inetd.pid" |
150 | 150 | ||
151 | 151 | ||
152 | #define TOOMANY 0 /* don't start more than TOOMANY */ | ||
153 | |||
154 | #define CNT_INTVL 60 /* servers in CNT_INTVL sec. */ | 152 | #define CNT_INTVL 60 /* servers in CNT_INTVL sec. */ |
155 | #define RETRYTIME (60*10) /* retry after bind or server fail */ | 153 | #define RETRYTIME (60*10) /* retry after bind or server fail */ |
156 | 154 | ||
@@ -297,7 +295,7 @@ static const struct builtin builtins[] = { | |||
297 | static int global_queuelen = 128; | 295 | static int global_queuelen = 128; |
298 | static int nsock, maxsock; | 296 | static int nsock, maxsock; |
299 | static fd_set allsock; | 297 | static fd_set allsock; |
300 | static int toomany = TOOMANY; | 298 | static int toomany; |
301 | static int timingout; | 299 | static int timingout; |
302 | static struct servent *sp; | 300 | static struct servent *sp; |
303 | static uid_t uid; | 301 | static uid_t uid; |
@@ -588,10 +586,10 @@ static servtab_t *getconfigent(void) | |||
588 | sep = new_servtab(); | 586 | sep = new_servtab(); |
589 | 587 | ||
590 | /* memset(sep, 0, sizeof *sep); */ | 588 | /* memset(sep, 0, sizeof *sep); */ |
591 | more: | 589 | more: |
592 | /* freeconfig(sep); */ | 590 | /* freeconfig(sep); */ |
593 | 591 | ||
594 | while ((cp = nextline()) && *cp == '#'); | 592 | while ((cp = nextline()) && *cp == '#') /* skip comment line */; |
595 | if (cp == NULL) { | 593 | if (cp == NULL) { |
596 | /* free(sep); */ | 594 | /* free(sep); */ |
597 | return NULL; | 595 | return NULL; |
@@ -680,7 +678,7 @@ more: | |||
680 | } else if (*ccp != '\0') | 678 | } else if (*ccp != '\0') |
681 | goto badafterall; | 679 | goto badafterall; |
682 | #else | 680 | #else |
683 | bb_error_msg("%s: rpc services not supported", sep->se_service); | 681 | bb_error_msg("%s: rpc services not supported", sep->se_service); |
684 | #endif | 682 | #endif |
685 | } | 683 | } |
686 | } | 684 | } |
@@ -692,7 +690,7 @@ more: | |||
692 | char *s = strchr(arg, '.'); | 690 | char *s = strchr(arg, '.'); |
693 | if (s) { | 691 | if (s) { |
694 | *s++ = '\0'; | 692 | *s++ = '\0'; |
695 | sep->se_max = atoi(s); | 693 | sep->se_max = xatoi(s); |
696 | } else | 694 | } else |
697 | sep->se_max = toomany; | 695 | sep->se_max = toomany; |
698 | } | 696 | } |
@@ -928,7 +926,7 @@ static void config(int sig ATTRIBUTE_UNUSED) | |||
928 | */ | 926 | */ |
929 | if ( | 927 | if ( |
930 | #ifdef INETD_FEATURE_ENABLED | 928 | #ifdef INETD_FEATURE_ENABLED |
931 | cp->se_bi == 0 && | 929 | cp->se_bi == 0 && |
932 | #endif | 930 | #endif |
933 | (sep->se_wait == 1 || cp->se_wait == 0)) | 931 | (sep->se_wait == 1 || cp->se_wait == 0)) |
934 | sep->se_wait = cp->se_wait; | 932 | sep->se_wait = cp->se_wait; |
@@ -974,7 +972,7 @@ static void config(int sig ATTRIBUTE_UNUSED) | |||
974 | #ifdef CONFIG_FEATURE_INETD_RPC | 972 | #ifdef CONFIG_FEATURE_INETD_RPC |
975 | if (isrpcservice(sep)) { | 973 | if (isrpcservice(sep)) { |
976 | struct rpcent *rp; | 974 | struct rpcent *rp; |
977 | 975 | // FIXME: atoi_or_else(str, 0) would be handy here | |
978 | sep->se_rpcprog = atoi(sep->se_service); | 976 | sep->se_rpcprog = atoi(sep->se_service); |
979 | if (sep->se_rpcprog == 0) { | 977 | if (sep->se_rpcprog == 0) { |
980 | rp = getrpcbyname(sep->se_service); | 978 | rp = getrpcbyname(sep->se_service); |
@@ -990,9 +988,9 @@ static void config(int sig ATTRIBUTE_UNUSED) | |||
990 | register_rpc(sep); | 988 | register_rpc(sep); |
991 | } else | 989 | } else |
992 | #endif | 990 | #endif |
993 | { | 991 | { |
994 | u_short port = htons(atoi(sep->se_service)); | 992 | u_short port = htons(atoi(sep->se_service)); |
995 | 993 | // FIXME: atoi_or_else(str, 0) would be handy here | |
996 | if (!port) { | 994 | if (!port) { |
997 | /*XXX*/ strncpy(protoname, sep->se_proto, sizeof(protoname)); | 995 | /*XXX*/ strncpy(protoname, sep->se_proto, sizeof(protoname)); |
998 | if (isdigit(protoname[strlen(protoname) - 1])) | 996 | if (isdigit(protoname[strlen(protoname) - 1])) |
@@ -1255,13 +1253,7 @@ inetd_main(int argc, char *argv[]) | |||
1255 | 1253 | ||
1256 | opt = getopt32(argc, argv, "R:f", &stoomany); | 1254 | opt = getopt32(argc, argv, "R:f", &stoomany); |
1257 | if(opt & 1) { | 1255 | if(opt & 1) { |
1258 | char *e; | 1256 | toomany = xatoi_u(stoomany); |
1259 | |||
1260 | toomany = strtoul(stoomany, &e, 0); | ||
1261 | if (!(toomany >= 0 && *e == '\0')) { | ||
1262 | toomany = TOOMANY; | ||
1263 | bb_perror_msg("-R %s: bad value for service invocation rate", stoomany); | ||
1264 | } | ||
1265 | } | 1257 | } |
1266 | argc -= optind; | 1258 | argc -= optind; |
1267 | argv += optind; | 1259 | argv += optind; |
@@ -1317,7 +1309,6 @@ inetd_main(int argc, char *argv[]) | |||
1317 | sigaddset(&sa.sa_mask, SIGHUP); | 1309 | sigaddset(&sa.sa_mask, SIGHUP); |
1318 | sa.sa_handler = retry; | 1310 | sa.sa_handler = retry; |
1319 | sigaction(SIGALRM, &sa, NULL); | 1311 | sigaction(SIGALRM, &sa, NULL); |
1320 | /* doconfig(); */ | ||
1321 | config(SIGHUP); | 1312 | config(SIGHUP); |
1322 | sa.sa_handler = config; | 1313 | sa.sa_handler = config; |
1323 | sigaction(SIGHUP, &sa, NULL); | 1314 | sigaction(SIGHUP, &sa, NULL); |
diff --git a/networking/interface.c b/networking/interface.c index c3cc7c0bc..8e2498d27 100644 --- a/networking/interface.c +++ b/networking/interface.c | |||
@@ -363,7 +363,7 @@ static int nstrcmp(const char *a, const char *b) | |||
363 | } | 363 | } |
364 | 364 | ||
365 | if (isdigit(*a) && isdigit(*b)) { | 365 | if (isdigit(*a) && isdigit(*b)) { |
366 | return atoi(a_ptr) > atoi(b_ptr) ? 1 : -1; | 366 | return xatoul(a_ptr) > xatoul(b_ptr) ? 1 : -1; |
367 | } | 367 | } |
368 | return *a - *b; | 368 | return *a - *b; |
369 | } | 369 | } |
diff --git a/networking/ipcalc.c b/networking/ipcalc.c index 576dfc853..909373cbb 100644 --- a/networking/ipcalc.c +++ b/networking/ipcalc.c | |||
@@ -18,8 +18,6 @@ | |||
18 | #include <sys/socket.h> | 18 | #include <sys/socket.h> |
19 | #include <arpa/inet.h> | 19 | #include <arpa/inet.h> |
20 | 20 | ||
21 | #define IPCALC_MSG(CMD,ALTCMD) if (mode & SILENT) {ALTCMD;} else {CMD;} | ||
22 | |||
23 | #define CLASS_A_NETMASK ntohl(0xFF000000) | 21 | #define CLASS_A_NETMASK ntohl(0xFF000000) |
24 | #define CLASS_B_NETMASK ntohl(0xFFFF0000) | 22 | #define CLASS_B_NETMASK ntohl(0xFFFF0000) |
25 | #define CLASS_C_NETMASK ntohl(0xFFFFFF00) | 23 | #define CLASS_C_NETMASK ntohl(0xFFFFFF00) |
@@ -56,6 +54,7 @@ static int get_prefix(unsigned long netmask) | |||
56 | int get_prefix(unsigned long netmask); | 54 | int get_prefix(unsigned long netmask); |
57 | #endif | 55 | #endif |
58 | 56 | ||
57 | |||
59 | #define NETMASK 0x01 | 58 | #define NETMASK 0x01 |
60 | #define BROADCAST 0x02 | 59 | #define BROADCAST 0x02 |
61 | #define NETWORK 0x04 | 60 | #define NETWORK 0x04 |
@@ -78,12 +77,9 @@ int get_prefix(unsigned long netmask); | |||
78 | #else | 77 | #else |
79 | #define long_options 0 | 78 | #define long_options 0 |
80 | #endif | 79 | #endif |
81 | |||
82 | |||
83 | |||
84 | int ipcalc_main(int argc, char **argv) | 80 | int ipcalc_main(int argc, char **argv) |
85 | { | 81 | { |
86 | unsigned long mode; | 82 | unsigned opt; |
87 | int have_netmask = 0; | 83 | int have_netmask = 0; |
88 | in_addr_t netmask, broadcast, network, ipaddr; | 84 | in_addr_t netmask, broadcast, network, ipaddr; |
89 | struct in_addr a; | 85 | struct in_addr a; |
@@ -92,17 +88,18 @@ int ipcalc_main(int argc, char **argv) | |||
92 | if (ENABLE_FEATURE_IPCALC_LONG_OPTIONS) | 88 | if (ENABLE_FEATURE_IPCALC_LONG_OPTIONS) |
93 | applet_long_options = long_options; | 89 | applet_long_options = long_options; |
94 | 90 | ||
95 | mode = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs")); | 91 | opt = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs")); |
96 | |||
97 | argc -= optind; | 92 | argc -= optind; |
98 | argv += optind; | 93 | argv += optind; |
99 | if (mode & (BROADCAST | NETWORK | NETPREFIX)) { | 94 | if (opt & (BROADCAST | NETWORK | NETPREFIX)) { |
100 | if (argc > 2 || argc <= 0) | 95 | if (argc > 2 || argc <= 0) |
101 | bb_show_usage(); | 96 | bb_show_usage(); |
102 | } else { | 97 | } else { |
103 | if (argc != 1) | 98 | if (argc != 1) |
104 | bb_show_usage(); | 99 | bb_show_usage(); |
105 | } | 100 | } |
101 | if (opt & SILENT) | ||
102 | logmode = LOGMODE_NONE; /* Suppress error_msg() output */ | ||
106 | 103 | ||
107 | ipstr = argv[0]; | 104 | ipstr = argv[0]; |
108 | if (ENABLE_FEATURE_IPCALC_FANCY) { | 105 | if (ENABLE_FEATURE_IPCALC_FANCY) { |
@@ -111,17 +108,13 @@ int ipcalc_main(int argc, char **argv) | |||
111 | 108 | ||
112 | prefixstr = ipstr; | 109 | prefixstr = ipstr; |
113 | 110 | ||
114 | while(*prefixstr) { | 111 | while (*prefixstr) { |
115 | if (*prefixstr == '/') { | 112 | if (*prefixstr == '/') { |
116 | *prefixstr = (char)0; | 113 | *prefixstr = (char)0; |
117 | prefixstr++; | 114 | prefixstr++; |
118 | if (*prefixstr) { | 115 | if (*prefixstr) { |
119 | unsigned int msk; | 116 | unsigned msk; |
120 | 117 | netprefix = xatoul_range(prefixstr, 0, 32); | |
121 | if (safe_strtoul(prefixstr, &netprefix) || netprefix > 32) { | ||
122 | IPCALC_MSG(bb_error_msg_and_die("bad IP prefix: %s", prefixstr), | ||
123 | exit(EXIT_FAILURE)); | ||
124 | } | ||
125 | netmask = 0; | 118 | netmask = 0; |
126 | msk = 0x80000000; | 119 | msk = 0x80000000; |
127 | while (netprefix > 0) { | 120 | while (netprefix > 0) { |
@@ -142,21 +135,18 @@ int ipcalc_main(int argc, char **argv) | |||
142 | ipaddr = inet_aton(ipstr, &a); | 135 | ipaddr = inet_aton(ipstr, &a); |
143 | 136 | ||
144 | if (ipaddr == 0) { | 137 | if (ipaddr == 0) { |
145 | IPCALC_MSG(bb_error_msg_and_die("bad IP address: %s", argv[0]), | 138 | bb_error_msg_and_die("bad IP address: %s", argv[0]); |
146 | exit(EXIT_FAILURE)); | ||
147 | } | 139 | } |
148 | ipaddr = a.s_addr; | 140 | ipaddr = a.s_addr; |
149 | 141 | ||
150 | if (argc == 2) { | 142 | if (argc == 2) { |
151 | if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) { | 143 | if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) { |
152 | IPCALC_MSG(bb_error_msg_and_die("Use prefix or netmask, not both"), | 144 | bb_error_msg_and_die("use prefix or netmask, not both"); |
153 | exit(EXIT_FAILURE)); | ||
154 | } | 145 | } |
155 | 146 | ||
156 | netmask = inet_aton(argv[1], &a); | 147 | netmask = inet_aton(argv[1], &a); |
157 | if (netmask == 0) { | 148 | if (netmask == 0) { |
158 | IPCALC_MSG(bb_error_msg_and_die("bad netmask: %s", argv[1]), | 149 | bb_error_msg_and_die("bad netmask: %s", argv[1]); |
159 | exit(EXIT_FAILURE)); | ||
160 | } | 150 | } |
161 | netmask = a.s_addr; | 151 | netmask = a.s_addr; |
162 | } else { | 152 | } else { |
@@ -166,34 +156,32 @@ int ipcalc_main(int argc, char **argv) | |||
166 | netmask = get_netmask(ipaddr); | 156 | netmask = get_netmask(ipaddr); |
167 | } | 157 | } |
168 | 158 | ||
169 | if (mode & NETMASK) { | 159 | if (opt & NETMASK) { |
170 | printf("NETMASK=%s\n", inet_ntoa((*(struct in_addr *) &netmask))); | 160 | printf("NETMASK=%s\n", inet_ntoa((*(struct in_addr *) &netmask))); |
171 | } | 161 | } |
172 | 162 | ||
173 | if (mode & BROADCAST) { | 163 | if (opt & BROADCAST) { |
174 | broadcast = (ipaddr & netmask) | ~netmask; | 164 | broadcast = (ipaddr & netmask) | ~netmask; |
175 | printf("BROADCAST=%s\n", inet_ntoa((*(struct in_addr *) &broadcast))); | 165 | printf("BROADCAST=%s\n", inet_ntoa((*(struct in_addr *) &broadcast))); |
176 | } | 166 | } |
177 | 167 | ||
178 | if (mode & NETWORK) { | 168 | if (opt & NETWORK) { |
179 | network = ipaddr & netmask; | 169 | network = ipaddr & netmask; |
180 | printf("NETWORK=%s\n", inet_ntoa((*(struct in_addr *) &network))); | 170 | printf("NETWORK=%s\n", inet_ntoa((*(struct in_addr *) &network))); |
181 | } | 171 | } |
182 | 172 | ||
183 | if (ENABLE_FEATURE_IPCALC_FANCY) { | 173 | if (ENABLE_FEATURE_IPCALC_FANCY) { |
184 | if (mode & NETPREFIX) { | 174 | if (opt & NETPREFIX) { |
185 | printf("PREFIX=%i\n", get_prefix(netmask)); | 175 | printf("PREFIX=%i\n", get_prefix(netmask)); |
186 | } | 176 | } |
187 | 177 | ||
188 | if (mode & HOSTNAME) { | 178 | if (opt & HOSTNAME) { |
189 | struct hostent *hostinfo; | 179 | struct hostent *hostinfo; |
190 | int x; | 180 | int x; |
191 | 181 | ||
192 | hostinfo = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET); | 182 | hostinfo = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET); |
193 | if (!hostinfo) { | 183 | if (!hostinfo) { |
194 | IPCALC_MSG(bb_herror_msg_and_die( | 184 | bb_herror_msg_and_die("cannot find hostname for %s", argv[0]); |
195 | "cannot find hostname for %s", argv[0]),); | ||
196 | exit(EXIT_FAILURE); | ||
197 | } | 185 | } |
198 | for (x = 0; hostinfo->h_name[x]; x++) { | 186 | for (x = 0; hostinfo->h_name[x]; x++) { |
199 | hostinfo->h_name[x] = tolower(hostinfo->h_name[x]); | 187 | hostinfo->h_name[x] = tolower(hostinfo->h_name[x]); |
diff --git a/networking/nc.c b/networking/nc.c index f8b3fb2dd..bde5e6600 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -11,13 +11,15 @@ | |||
11 | 11 | ||
12 | static void timeout(int signum) | 12 | static void timeout(int signum) |
13 | { | 13 | { |
14 | bb_error_msg_and_die("Timed out"); | 14 | bb_error_msg_and_die("timed out"); |
15 | } | 15 | } |
16 | 16 | ||
17 | int nc_main(int argc, char **argv) | 17 | int nc_main(int argc, char **argv) |
18 | { | 18 | { |
19 | int do_listen = 0, lport = 0, delay = 0, wsecs = 0, execflag = 0, opt, | 19 | int sfd = 0, cfd; |
20 | sfd = 0, cfd; | 20 | unsigned opt; |
21 | unsigned lport = 0, wsecs = 0, delay = 0; | ||
22 | unsigned do_listen = 0, execflag = 0; | ||
21 | struct sockaddr_in address; | 23 | struct sockaddr_in address; |
22 | struct hostent *hostinfo; | 24 | struct hostent *hostinfo; |
23 | fd_set readfds, testfds; | 25 | fd_set readfds, testfds; |
@@ -30,8 +32,8 @@ int nc_main(int argc, char **argv) | |||
30 | if (ENABLE_NC_SERVER && opt=='l') do_listen++; | 32 | if (ENABLE_NC_SERVER && opt=='l') do_listen++; |
31 | else if (ENABLE_NC_SERVER && opt=='p') | 33 | else if (ENABLE_NC_SERVER && opt=='p') |
32 | lport = bb_lookup_port(optarg, "tcp", 0); | 34 | lport = bb_lookup_port(optarg, "tcp", 0); |
33 | else if (ENABLE_NC_EXTRA && opt=='w') wsecs = atoi(optarg); | 35 | else if (ENABLE_NC_EXTRA && opt=='w') wsecs = xatou(optarg); |
34 | else if (ENABLE_NC_EXTRA && opt=='i') delay = atoi(optarg); | 36 | else if (ENABLE_NC_EXTRA && opt=='i') delay = xatou(optarg); |
35 | else if (ENABLE_NC_EXTRA && opt=='f') infile = optarg; | 37 | else if (ENABLE_NC_EXTRA && opt=='f') infile = optarg; |
36 | else if (ENABLE_NC_EXTRA && opt=='e' && optind!=argc) { | 38 | else if (ENABLE_NC_EXTRA && opt=='e' && optind!=argc) { |
37 | execflag++; | 39 | execflag++; |
@@ -40,11 +42,10 @@ int nc_main(int argc, char **argv) | |||
40 | } | 42 | } |
41 | } | 43 | } |
42 | 44 | ||
43 | |||
44 | // For listen or file we need zero arguments, dialout is 2. | 45 | // For listen or file we need zero arguments, dialout is 2. |
45 | // For exec we need at least one more argument at the end, more ok | 46 | // For exec we need at least one more argument at the end, more ok |
46 | 47 | ||
47 | opt = (do_listen || infile) ? 0 : 2 + execflag; | 48 | opt = (do_listen || infile) ? 0 : 2 + execflag; |
48 | if (execflag ? argc-optind < opt : argc-optind!=opt || | 49 | if (execflag ? argc-optind < opt : argc-optind!=opt || |
49 | (infile && do_listen)) | 50 | (infile && do_listen)) |
50 | bb_show_usage(); | 51 | bb_show_usage(); |
@@ -66,7 +67,6 @@ int nc_main(int argc, char **argv) | |||
66 | 67 | ||
67 | if (lport != 0) { | 68 | if (lport != 0) { |
68 | address.sin_port = lport; | 69 | address.sin_port = lport; |
69 | |||
70 | xbind(sfd, (struct sockaddr *) &address, sizeof(address)); | 70 | xbind(sfd, (struct sockaddr *) &address, sizeof(address)); |
71 | } | 71 | } |
72 | 72 | ||
@@ -83,7 +83,8 @@ int nc_main(int argc, char **argv) | |||
83 | fdprintf(2, "%d\n", SWAP_BE16(address.sin_port)); | 83 | fdprintf(2, "%d\n", SWAP_BE16(address.sin_port)); |
84 | } | 84 | } |
85 | repeatyness: | 85 | repeatyness: |
86 | if ((cfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0) | 86 | cfd = accept(sfd, (struct sockaddr *) &address, &addrlen); |
87 | if (cfd < 0) | ||
87 | bb_perror_msg_and_die("accept"); | 88 | bb_perror_msg_and_die("accept"); |
88 | 89 | ||
89 | if (!execflag) close(sfd); | 90 | if (!execflag) close(sfd); |
@@ -116,10 +117,11 @@ repeatyness: | |||
116 | 117 | ||
117 | // With more than one -l, repeatedly act as server. | 118 | // With more than one -l, repeatedly act as server. |
118 | 119 | ||
119 | if (do_listen>1 && vfork()) { | 120 | if (do_listen > 1 && vfork()) { |
120 | // This is a bit weird as cleanup goes, since we wind up with no | 121 | // This is a bit weird as cleanup goes, since we wind up with no |
121 | // stdin/stdout/stderr. But it's small and shouldn't hurt anything. | 122 | // stdin/stdout/stderr. But it's small and shouldn't hurt anything. |
122 | // We check for cfd == 0 above. | 123 | // We check for cfd == 0 above. |
124 | logmode = LOGMODE_NONE; | ||
123 | close(0); | 125 | close(0); |
124 | close(1); | 126 | close(1); |
125 | close(2); | 127 | close(2); |
diff --git a/networking/ping.c b/networking/ping.c index a81472f96..8ca8be9b9 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -157,9 +157,9 @@ int ping_main(int argc, char **argv) | |||
157 | static struct sockaddr_in pingaddr; | 157 | static struct sockaddr_in pingaddr; |
158 | static struct sockaddr_in sourceaddr; | 158 | static struct sockaddr_in sourceaddr; |
159 | static int pingsock = -1; | 159 | static int pingsock = -1; |
160 | static int datalen; /* intentionally uninitialized to work around gcc bug */ | 160 | static unsigned datalen; /* intentionally uninitialized to work around gcc bug */ |
161 | 161 | ||
162 | static long ntransmitted, nreceived, nrepeats, pingcount; | 162 | static unsigned long ntransmitted, nreceived, nrepeats, pingcount; |
163 | static int myid, options; | 163 | static int myid, options; |
164 | static unsigned long tmin = ULONG_MAX, tmax, tsum; | 164 | static unsigned long tmin = ULONG_MAX, tmax, tsum; |
165 | static char rcvd_tbl[MAX_DUP_CHK / 8]; | 165 | static char rcvd_tbl[MAX_DUP_CHK / 8]; |
@@ -179,12 +179,12 @@ static void pingstats(int junk) | |||
179 | signal(SIGINT, SIG_IGN); | 179 | signal(SIGINT, SIG_IGN); |
180 | 180 | ||
181 | printf("\n--- %s ping statistics ---\n", hostent->h_name); | 181 | printf("\n--- %s ping statistics ---\n", hostent->h_name); |
182 | printf("%ld packets transmitted, ", ntransmitted); | 182 | printf("%lu packets transmitted, ", ntransmitted); |
183 | printf("%ld packets received, ", nreceived); | 183 | printf("%lu packets received, ", nreceived); |
184 | if (nrepeats) | 184 | if (nrepeats) |
185 | printf("%ld duplicates, ", nrepeats); | 185 | printf("%lu duplicates, ", nrepeats); |
186 | if (ntransmitted) | 186 | if (ntransmitted) |
187 | printf("%ld%% packet loss\n", | 187 | printf("%lu%% packet loss\n", |
188 | (ntransmitted - nreceived) * 100 / ntransmitted); | 188 | (ntransmitted - nreceived) * 100 / ntransmitted); |
189 | if (nreceived) | 189 | if (nreceived) |
190 | printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n", | 190 | printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n", |
@@ -427,13 +427,13 @@ int ping_main(int argc, char **argv) | |||
427 | if (--argc <= 0) | 427 | if (--argc <= 0) |
428 | bb_show_usage(); | 428 | bb_show_usage(); |
429 | argv++; | 429 | argv++; |
430 | pingcount = atoi(*argv); | 430 | pingcount = xatoul(*argv); |
431 | break; | 431 | break; |
432 | case 's': | 432 | case 's': |
433 | if (--argc <= 0) | 433 | if (--argc <= 0) |
434 | bb_show_usage(); | 434 | bb_show_usage(); |
435 | argv++; | 435 | argv++; |
436 | datalen = atoi(*argv); | 436 | datalen = xatou16(*argv); |
437 | break; | 437 | break; |
438 | case 'I': | 438 | case 'I': |
439 | if (--argc <= 0) | 439 | if (--argc <= 0) |
diff --git a/networking/ping6.c b/networking/ping6.c index 6079c40d9..0d6a739bf 100644 --- a/networking/ping6.c +++ b/networking/ping6.c | |||
@@ -145,10 +145,10 @@ int ping6_main(int argc, char **argv) | |||
145 | /* full(er) version */ | 145 | /* full(er) version */ |
146 | static struct sockaddr_in6 pingaddr; | 146 | static struct sockaddr_in6 pingaddr; |
147 | static int pingsock = -1; | 147 | static int pingsock = -1; |
148 | static int datalen; /* intentionally uninitialized to work around gcc bug */ | 148 | static unsigned datalen; /* intentionally uninitialized to work around gcc bug */ |
149 | static int if_index; | 149 | static int if_index; |
150 | 150 | ||
151 | static long ntransmitted, nreceived, nrepeats, pingcount; | 151 | static unsigned long ntransmitted, nreceived, nrepeats, pingcount; |
152 | static int myid, options; | 152 | static int myid, options; |
153 | static unsigned long tmin = ULONG_MAX, tmax, tsum; | 153 | static unsigned long tmin = ULONG_MAX, tmax, tsum; |
154 | static char rcvd_tbl[MAX_DUP_CHK / 8]; | 154 | static char rcvd_tbl[MAX_DUP_CHK / 8]; |
@@ -168,12 +168,12 @@ static void pingstats(int junk) | |||
168 | signal(SIGINT, SIG_IGN); | 168 | signal(SIGINT, SIG_IGN); |
169 | 169 | ||
170 | printf("\n--- %s ping statistics ---\n", hostent->h_name); | 170 | printf("\n--- %s ping statistics ---\n", hostent->h_name); |
171 | printf("%ld packets transmitted, ", ntransmitted); | 171 | printf("%lu packets transmitted, ", ntransmitted); |
172 | printf("%ld packets received, ", nreceived); | 172 | printf("%lu packets received, ", nreceived); |
173 | if (nrepeats) | 173 | if (nrepeats) |
174 | printf("%ld duplicates, ", nrepeats); | 174 | printf("%lu duplicates, ", nrepeats); |
175 | if (ntransmitted) | 175 | if (ntransmitted) |
176 | printf("%ld%% packet loss\n", | 176 | printf("%lu%% packet loss\n", |
177 | (ntransmitted - nreceived) * 100 / ntransmitted); | 177 | (ntransmitted - nreceived) * 100 / ntransmitted); |
178 | if (nreceived) | 178 | if (nreceived) |
179 | printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n", | 179 | printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n", |
@@ -439,13 +439,13 @@ int ping6_main(int argc, char **argv) | |||
439 | if (--argc <= 0) | 439 | if (--argc <= 0) |
440 | bb_show_usage(); | 440 | bb_show_usage(); |
441 | argv++; | 441 | argv++; |
442 | pingcount = atoi(*argv); | 442 | pingcount = xatoul(*argv); |
443 | break; | 443 | break; |
444 | case 's': | 444 | case 's': |
445 | if (--argc <= 0) | 445 | if (--argc <= 0) |
446 | bb_show_usage(); | 446 | bb_show_usage(); |
447 | argv++; | 447 | argv++; |
448 | datalen = atoi(*argv); | 448 | datalen = xatou16(*argv); |
449 | break; | 449 | break; |
450 | case 'I': | 450 | case 'I': |
451 | if (--argc <= 0) | 451 | if (--argc <= 0) |
diff --git a/networking/route.c b/networking/route.c index 2e6e017b6..65b40fcd6 100644 --- a/networking/route.c +++ b/networking/route.c | |||
@@ -178,7 +178,7 @@ static void INET_setroute(int action, char **args) | |||
178 | if(prefix) { | 178 | if(prefix) { |
179 | int prefix_len; | 179 | int prefix_len; |
180 | 180 | ||
181 | prefix_len = bb_xgetularg10_bnd(prefix+1, 0, 32); | 181 | prefix_len = xatoul_range(prefix+1, 0, 32); |
182 | mask_in_addr(rt) = htonl( ~ (0xffffffffUL >> prefix_len)); | 182 | mask_in_addr(rt) = htonl( ~ (0xffffffffUL >> prefix_len)); |
183 | *prefix = '\0'; | 183 | *prefix = '\0'; |
184 | #if HAVE_NEW_ADDRT | 184 | #if HAVE_NEW_ADDRT |
@@ -218,7 +218,7 @@ static void INET_setroute(int action, char **args) | |||
218 | 218 | ||
219 | #if HAVE_NEW_ADDRT | 219 | #if HAVE_NEW_ADDRT |
220 | if (k == KW_IPVx_METRIC) { | 220 | if (k == KW_IPVx_METRIC) { |
221 | rt.rt_metric = bb_xgetularg10(args_m1) + 1; | 221 | rt.rt_metric = xatoul(args_m1) + 1; |
222 | continue; | 222 | continue; |
223 | } | 223 | } |
224 | #endif | 224 | #endif |
@@ -259,20 +259,20 @@ static void INET_setroute(int action, char **args) | |||
259 | 259 | ||
260 | if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */ | 260 | if (k == KW_IPVx_MSS) { /* Check valid MSS bounds. */ |
261 | rt.rt_flags |= RTF_MSS; | 261 | rt.rt_flags |= RTF_MSS; |
262 | rt.rt_mss = bb_xgetularg10_bnd(args_m1, 64, 32768); | 262 | rt.rt_mss = xatoul_range(args_m1, 64, 32768); |
263 | continue; | 263 | continue; |
264 | } | 264 | } |
265 | 265 | ||
266 | if (k == KW_IPVx_WINDOW) { /* Check valid window bounds. */ | 266 | if (k == KW_IPVx_WINDOW) { /* Check valid window bounds. */ |
267 | rt.rt_flags |= RTF_WINDOW; | 267 | rt.rt_flags |= RTF_WINDOW; |
268 | rt.rt_window = bb_xgetularg10_bnd(args_m1, 128, INT_MAX); | 268 | rt.rt_window = xatoul_range(args_m1, 128, INT_MAX); |
269 | continue; | 269 | continue; |
270 | } | 270 | } |
271 | 271 | ||
272 | #ifdef RTF_IRTT | 272 | #ifdef RTF_IRTT |
273 | if (k == KW_IPVx_IRTT) { | 273 | if (k == KW_IPVx_IRTT) { |
274 | rt.rt_flags |= RTF_IRTT; | 274 | rt.rt_flags |= RTF_IRTT; |
275 | rt.rt_irtt = bb_xgetularg10(args_m1); | 275 | rt.rt_irtt = xatoul(args_m1); |
276 | rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */ | 276 | rt.rt_irtt *= (sysconf(_SC_CLK_TCK) / 100); /* FIXME */ |
277 | #if 0 /* FIXME: do we need to check anything of this? */ | 277 | #if 0 /* FIXME: do we need to check anything of this? */ |
278 | if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { | 278 | if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { |
@@ -353,7 +353,7 @@ static void INET6_setroute(int action, char **args) | |||
353 | char *cp; | 353 | char *cp; |
354 | if ((cp = strchr(target, '/'))) { /* Yes... const to non is ok. */ | 354 | if ((cp = strchr(target, '/'))) { /* Yes... const to non is ok. */ |
355 | *cp = 0; | 355 | *cp = 0; |
356 | prefix_len = bb_xgetularg10_bnd(cp+1, 0, 128); | 356 | prefix_len = xatoul_range(cp+1, 0, 128); |
357 | } else { | 357 | } else { |
358 | prefix_len = 128; | 358 | prefix_len = 128; |
359 | } | 359 | } |
@@ -384,7 +384,7 @@ static void INET6_setroute(int action, char **args) | |||
384 | } | 384 | } |
385 | 385 | ||
386 | if (k == KW_IPVx_METRIC) { | 386 | if (k == KW_IPVx_METRIC) { |
387 | rt.rtmsg_metric = bb_xgetularg10(args_m1); | 387 | rt.rtmsg_metric = xatoul(args_m1); |
388 | continue; | 388 | continue; |
389 | } | 389 | } |
390 | 390 | ||
diff --git a/networking/telnetd.c b/networking/telnetd.c index 1c4dede39..c6789e19c 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -369,7 +369,7 @@ telnetd_main(int argc, char **argv) | |||
369 | sockaddr_type sa; | 369 | sockaddr_type sa; |
370 | int master_fd; | 370 | int master_fd; |
371 | int on = 1; | 371 | int on = 1; |
372 | int portnbr = 23; | 372 | unsigned portnbr = 23; |
373 | struct in_addr bind_addr = { .s_addr = 0x0 }; | 373 | struct in_addr bind_addr = { .s_addr = 0x0 }; |
374 | char *opt_portnbr, *opt_bindaddr; | 374 | char *opt_portnbr, *opt_bindaddr; |
375 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ | 375 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ |
@@ -393,7 +393,7 @@ telnetd_main(int argc, char **argv) | |||
393 | //if (opt & 1) // -f | 393 | //if (opt & 1) // -f |
394 | //if (opt & 2) // -l | 394 | //if (opt & 2) // -l |
395 | #ifndef CONFIG_FEATURE_TELNETD_INETD | 395 | #ifndef CONFIG_FEATURE_TELNETD_INETD |
396 | if (opt & 4) portnbr = atoi(opt_portnbr); // -p | 396 | if (opt & 4) portnbr = xatou16(opt_portnbr); // -p |
397 | if (opt & 8) // -b | 397 | if (opt & 8) // -b |
398 | if (inet_aton(opt_bindaddr, &bind_addr) == 0) bb_show_usage(); | 398 | if (inet_aton(opt_bindaddr, &bind_addr) == 0) bb_show_usage(); |
399 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ | 399 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ |
diff --git a/networking/tftp.c b/networking/tftp.c index bfe94aca2..6213d6622 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -373,7 +373,7 @@ static int tftp(const int cmd, const struct hostent *host, | |||
373 | res = tftp_option_get(&buf[2], len - 2, OPTION_BLOCKSIZE); | 373 | res = tftp_option_get(&buf[2], len - 2, OPTION_BLOCKSIZE); |
374 | 374 | ||
375 | if (res) { | 375 | if (res) { |
376 | int blksize = atoi(res); | 376 | int blksize = xatoi_u(res); |
377 | 377 | ||
378 | if (tftp_blocksize_check(blksize, tftp_bufsize - 4)) { | 378 | if (tftp_blocksize_check(blksize, tftp_bufsize - 4)) { |
379 | 379 | ||
@@ -516,7 +516,7 @@ int tftp_main(int argc, char **argv) | |||
516 | 516 | ||
517 | #ifdef CONFIG_FEATURE_TFTP_BLOCKSIZE | 517 | #ifdef CONFIG_FEATURE_TFTP_BLOCKSIZE |
518 | if (sblocksize) { | 518 | if (sblocksize) { |
519 | blocksize = atoi(sblocksize); | 519 | blocksize = xatoi_u(sblocksize); |
520 | if (!tftp_blocksize_check(blocksize, 0)) { | 520 | if (!tftp_blocksize_check(blocksize, 0)) { |
521 | return EXIT_FAILURE; | 521 | return EXIT_FAILURE; |
522 | } | 522 | } |
diff --git a/networking/traceroute.c b/networking/traceroute.c index 4af523625..84ce8ae69 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -416,7 +416,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp) | |||
416 | ++al; | 416 | ++al; |
417 | ++nipaddr; | 417 | ++nipaddr; |
418 | } | 418 | } |
419 | if(nipaddr == 0) | 419 | if (nipaddr == 0) |
420 | bb_error_msg_and_die ("Can't find any network interfaces"); | 420 | bb_error_msg_and_die ("Can't find any network interfaces"); |
421 | (void)close(fd); | 421 | (void)close(fd); |
422 | 422 | ||
@@ -494,34 +494,6 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) | |||
494 | 494 | ||
495 | */ | 495 | */ |
496 | 496 | ||
497 | /* String to value with optional min and max. Handles decimal and hex. */ | ||
498 | static int | ||
499 | str2val(const char *str, const char *what, int mi, int ma) | ||
500 | { | ||
501 | const char *cp; | ||
502 | int val; | ||
503 | char *ep; | ||
504 | |||
505 | if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { | ||
506 | cp = str + 2; | ||
507 | val = (int)strtol(cp, &ep, 16); | ||
508 | } else | ||
509 | val = (int)strtol(str, &ep, 10); | ||
510 | if (*ep != '\0') { | ||
511 | bb_error_msg_and_die("\"%s\" bad value for %s", str, what); | ||
512 | } | ||
513 | if (val < mi && mi >= 0) { | ||
514 | if (mi == 0) | ||
515 | bb_error_msg_and_die("%s must be >= %d", what, mi); | ||
516 | else | ||
517 | bb_error_msg_and_die("%s must be > %d", what, mi - 1); | ||
518 | } | ||
519 | if (val > ma && ma >= 0) | ||
520 | bb_error_msg_and_die("%s must be <= %d", what, ma); | ||
521 | return val; | ||
522 | } | ||
523 | |||
524 | |||
525 | /* | 497 | /* |
526 | * Subtract 2 timeval structs: out = out - in. | 498 | * Subtract 2 timeval structs: out = out - in. |
527 | * Out is assumed to be >= in. | 499 | * Out is assumed to be >= in. |
@@ -828,7 +800,7 @@ inetname(struct sockaddr_in *from) | |||
828 | char name[257]; | 800 | char name[257]; |
829 | 801 | ||
830 | if (!nflag && from->sin_addr.s_addr != INADDR_ANY) { | 802 | if (!nflag && from->sin_addr.s_addr != INADDR_ANY) { |
831 | if(INET_rresolve(name, sizeof(name), from, 0x4000, 0xffffffff) >= 0) | 803 | if (INET_rresolve(name, sizeof(name), from, 0x4000, 0xffffffff) >= 0) |
832 | n = name; | 804 | n = name; |
833 | } | 805 | } |
834 | ina = inet_ntoa(from->sin_addr); | 806 | ina = inet_ntoa(from->sin_addr); |
@@ -974,7 +946,7 @@ traceroute_main(int argc, char *argv[]) | |||
974 | #endif | 946 | #endif |
975 | ); | 947 | ); |
976 | 948 | ||
977 | if(op & USAGE_OP_DONT_FRAGMNT) | 949 | if (op & USAGE_OP_DONT_FRAGMNT) |
978 | off = IP_DF; | 950 | off = IP_DF; |
979 | #ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP | 951 | #ifdef CONFIG_FEATURE_TRACEROUTE_USE_ICMP |
980 | useicmp = op & USAGE_OP_USE_ICMP; | 952 | useicmp = op & USAGE_OP_USE_ICMP; |
@@ -983,34 +955,34 @@ traceroute_main(int argc, char *argv[]) | |||
983 | #ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE | 955 | #ifdef CONFIG_FEATURE_TRACEROUTE_VERBOSE |
984 | verbose = op & USAGE_OP_VERBOSE; | 956 | verbose = op & USAGE_OP_VERBOSE; |
985 | #endif | 957 | #endif |
986 | if(op & USAGE_OP_IP_CHKSUM) { | 958 | if (op & USAGE_OP_IP_CHKSUM) { |
987 | doipcksum = 0; | 959 | doipcksum = 0; |
988 | bb_error_msg("Warning: ip checksums disabled"); | 960 | bb_error_msg("warning: ip checksums disabled"); |
989 | } | 961 | } |
990 | if (tos_str) | 962 | if (tos_str) |
991 | tos = str2val(tos_str, "tos", 0, 255); | 963 | tos = xatoul_range(tos_str, 0, 255); |
992 | if(max_ttl_str) | 964 | if (max_ttl_str) |
993 | max_ttl = str2val(max_ttl_str, "max ttl", 1, 255); | 965 | max_ttl = xatoul_range(max_ttl_str, 1, 255); |
994 | if(port_str) | 966 | if (port_str) |
995 | port = (u_short)str2val(port_str, "port", 1, (1 << 16) - 1); | 967 | port = xatou16(port_str); |
996 | if(nprobes_str) | 968 | if (nprobes_str) |
997 | nprobes = str2val(nprobes_str, "nprobes", 1, -1); | 969 | nprobes = xatoul_range(nprobes_str, 1, INT_MAX); |
998 | if(source) { | 970 | if (source) { |
999 | /* | 971 | /* |
1000 | * set the ip source address of the outbound | 972 | * set the ip source address of the outbound |
1001 | * probe (e.g., on a multi-homed host). | 973 | * probe (e.g., on a multi-homed host). |
1002 | */ | 974 | */ |
1003 | if (getuid()) bb_error_msg_and_die("-s %s: permission denied", source); | 975 | if (getuid()) bb_error_msg_and_die("-s %s: permission denied", source); |
1004 | } | 976 | } |
1005 | if(waittime_str) | 977 | if (waittime_str) |
1006 | waittime = str2val(waittime_str, "wait time", 2, 24 * 60 * 60); | 978 | waittime = xatoul_range(waittime_str, 2, 24 * 60 * 60); |
1007 | if(pausemsecs_str) | 979 | if (pausemsecs_str) |
1008 | pausemsecs = str2val(pausemsecs_str, "pause msecs", 0, 60 * 60 * 1000); | 980 | pausemsecs = xatoul_range(pausemsecs_str, 0, 60 * 60 * 1000); |
1009 | if(first_ttl_str) | 981 | if (first_ttl_str) |
1010 | first_ttl = str2val(first_ttl_str, "first ttl", 1, 255); | 982 | first_ttl = xatoul_range(first_ttl_str, 1, 255); |
1011 | 983 | ||
1012 | #ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE | 984 | #ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE |
1013 | if(sourse_route_list) { | 985 | if (sourse_route_list) { |
1014 | llist_t *l_sr; | 986 | llist_t *l_sr; |
1015 | 987 | ||
1016 | for(l_sr = sourse_route_list; l_sr; ) { | 988 | for(l_sr = sourse_route_list; l_sr; ) { |
@@ -1046,8 +1018,7 @@ traceroute_main(int argc, char *argv[]) | |||
1046 | switch (argc - optind) { | 1018 | switch (argc - optind) { |
1047 | 1019 | ||
1048 | case 2: | 1020 | case 2: |
1049 | packlen = str2val(argv[optind + 1], | 1021 | packlen = xatoul_range(argv[optind + 1], minpacket, maxpacket); |
1050 | "packet length", minpacket, maxpacket); | ||
1051 | /* Fall through */ | 1022 | /* Fall through */ |
1052 | 1023 | ||
1053 | case 1: | 1024 | case 1: |
@@ -1055,8 +1026,7 @@ traceroute_main(int argc, char *argv[]) | |||
1055 | hi = gethostinfo(hostname); | 1026 | hi = gethostinfo(hostname); |
1056 | setsin(to, hi->addrs[0]); | 1027 | setsin(to, hi->addrs[0]); |
1057 | if (hi->n > 1) | 1028 | if (hi->n > 1) |
1058 | bb_error_msg( | 1029 | bb_error_msg("warning: %s has multiple addresses; using %s", |
1059 | "Warning: %s has multiple addresses; using %s", | ||
1060 | hostname, inet_ntoa(to->sin_addr)); | 1030 | hostname, inet_ntoa(to->sin_addr)); |
1061 | hostname = hi->name; | 1031 | hostname = hi->name; |
1062 | hi->name = NULL; | 1032 | hi->name = NULL; |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 9ab6aee8c..f2cf82f05 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -262,10 +262,10 @@ int udhcpc_main(int argc, char *argv[]) | |||
262 | client_config.script = optarg; | 262 | client_config.script = optarg; |
263 | break; | 263 | break; |
264 | case 'T': | 264 | case 'T': |
265 | client_config.timeout = atoi(optarg); | 265 | client_config.timeout = xatoi_u(optarg); |
266 | break; | 266 | break; |
267 | case 't': | 267 | case 't': |
268 | client_config.retries = atoi(optarg); | 268 | client_config.retries = xatoi_u(optarg); |
269 | break; | 269 | break; |
270 | case 'v': | 270 | case 'v': |
271 | printf("version %s\n\n", BB_VER); | 271 | printf("version %s\n\n", BB_VER); |
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index d9dfb8965..52d383869 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
@@ -35,7 +35,8 @@ static int read_ip(const char *line, void *arg) | |||
35 | int retval = 1; | 35 | int retval = 1; |
36 | 36 | ||
37 | if (!inet_aton(line, addr)) { | 37 | if (!inet_aton(line, addr)) { |
38 | if ((host = gethostbyname(line))) | 38 | host = gethostbyname(line); |
39 | if (host) | ||
39 | addr->s_addr = *((unsigned long *) host->h_addr_list[0]); | 40 | addr->s_addr = *((unsigned long *) host->h_addr_list[0]); |
40 | else retval = 0; | 41 | else retval = 0; |
41 | } | 42 | } |
@@ -72,10 +73,7 @@ static int read_str(const char *line, void *arg) | |||
72 | 73 | ||
73 | static int read_u32(const char *line, void *arg) | 74 | static int read_u32(const char *line, void *arg) |
74 | { | 75 | { |
75 | uint32_t *dest = arg; | 76 | return safe_strtou32(line, (uint32_t*)arg) == 0; |
76 | char *endptr; | ||
77 | *dest = strtoul(line, &endptr, 0); | ||
78 | return endptr[0] == '\0'; | ||
79 | } | 77 | } |
80 | 78 | ||
81 | 79 | ||
diff --git a/networking/vconfig.c b/networking/vconfig.c index 6c808eb2f..003c1a8f7 100644 --- a/networking/vconfig.c +++ b/networking/vconfig.c | |||
@@ -144,14 +144,14 @@ int vconfig_main(int argc, char **argv) | |||
144 | * doing so wouldn't save that much space and would also make maintainence | 144 | * doing so wouldn't save that much space and would also make maintainence |
145 | * more of a pain. */ | 145 | * more of a pain. */ |
146 | if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ | 146 | if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ |
147 | ifr.u.flag = bb_xgetularg10_bnd(p, 0, 1); | 147 | ifr.u.flag = xatoul_range(p, 0, 1); |
148 | /* DM: in order to set reorder header, qos must be set */ | 148 | /* DM: in order to set reorder header, qos must be set */ |
149 | ifr.vlan_qos = bb_xgetularg10_bnd(argv[3], 0, 7); | 149 | ifr.vlan_qos = xatoul_range(argv[3], 0, 7); |
150 | } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ | 150 | } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ |
151 | ifr.u.VID = bb_xgetularg10_bnd(p, 0, VLAN_GROUP_ARRAY_LEN-1); | 151 | ifr.u.VID = xatoul_range(p, 0, VLAN_GROUP_ARRAY_LEN-1); |
152 | } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ | 152 | } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ |
153 | ifr.u.skb_priority = bb_xgetularg10_bnd(p, 0, ULONG_MAX); | 153 | ifr.u.skb_priority = xatou(p); |
154 | ifr.vlan_qos = bb_xgetularg10_bnd(argv[3], 0, 7); | 154 | ifr.vlan_qos = xatoul_range(argv[3], 0, 7); |
155 | } | 155 | } |
156 | } | 156 | } |
157 | 157 | ||
diff --git a/networking/wget.c b/networking/wget.c index eda0bb87c..e7b19f2ef 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -297,7 +297,7 @@ read_response: | |||
297 | s = buf; | 297 | s = buf; |
298 | while (*s != '\0' && !isspace(*s)) ++s; | 298 | while (*s != '\0' && !isspace(*s)) ++s; |
299 | while (isspace(*s)) ++s; | 299 | while (isspace(*s)) ++s; |
300 | switch (status = atoi(s)) { | 300 | switch (status = xatoi(s)) { |
301 | case 0: | 301 | case 0: |
302 | case 100: | 302 | case 100: |
303 | while (gethdr(buf, sizeof(buf), sfp, &n) != NULL) | 303 | while (gethdr(buf, sizeof(buf), sfp, &n) != NULL) |
@@ -406,9 +406,9 @@ read_response: | |||
406 | bb_error_msg_and_die("PASV: %s", buf+4); | 406 | bb_error_msg_and_die("PASV: %s", buf+4); |
407 | s = strrchr(buf, ','); | 407 | s = strrchr(buf, ','); |
408 | *s = 0; | 408 | *s = 0; |
409 | port = atoi(s+1); | 409 | port = xatol_range(s+1, 0, 255); |
410 | s = strrchr(buf, ','); | 410 | s = strrchr(buf, ','); |
411 | port += atoi(s+1) * 256; | 411 | port += xatol_range(s+1, 0, 255) * 256; |
412 | s_in.sin_port = htons(port); | 412 | s_in.sin_port = htons(port); |
413 | dfp = open_socket(&s_in); | 413 | dfp = open_socket(&s_in); |
414 | 414 | ||
@@ -562,7 +562,7 @@ static void parse_url(char *src_url, struct host_info *h) | |||
562 | cp = strchr(pp, ':'); | 562 | cp = strchr(pp, ':'); |
563 | if (cp != NULL) { | 563 | if (cp != NULL) { |
564 | *cp++ = '\0'; | 564 | *cp++ = '\0'; |
565 | h->port = htons(atoi(cp)); | 565 | h->port = htons(xatou16(cp)); |
566 | } | 566 | } |
567 | } | 567 | } |
568 | 568 | ||
@@ -646,7 +646,7 @@ static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf) | |||
646 | } | 646 | } |
647 | } while (!isdigit(buf[0]) || buf[3] != ' '); | 647 | } while (!isdigit(buf[0]) || buf[3] != ' '); |
648 | 648 | ||
649 | return atoi(buf); | 649 | return xatoi(buf); |
650 | } | 650 | } |
651 | 651 | ||
652 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 652 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR |
diff --git a/procps/kill.c b/procps/kill.c index 2408a70ca..b29f61b58 100644 --- a/procps/kill.c +++ b/procps/kill.c | |||
@@ -47,7 +47,7 @@ int kill_main(int argc, char **argv) | |||
47 | } else { /* -l <sig list> */ | 47 | } else { /* -l <sig list> */ |
48 | while ((arg = *++argv)!=NULL) { | 48 | while ((arg = *++argv)!=NULL) { |
49 | if (isdigit(arg[0])) { | 49 | if (isdigit(arg[0])) { |
50 | signo = atoi(arg); | 50 | signo = xatoi_u(arg); |
51 | name = get_signame(signo); | 51 | name = get_signame(signo); |
52 | } else { | 52 | } else { |
53 | signo = get_signum(arg); | 53 | signo = get_signum(arg); |
@@ -140,7 +140,7 @@ do_it_now: | |||
140 | while (arg) { | 140 | while (arg) { |
141 | if (!isdigit(arg[0]) && arg[0]!='-') | 141 | if (!isdigit(arg[0]) && arg[0]!='-') |
142 | bb_error_msg_and_die("bad pid '%s'", arg); | 142 | bb_error_msg_and_die("bad pid '%s'", arg); |
143 | pid = strtol(arg, NULL, 0); | 143 | pid = xatou(arg); |
144 | /* FIXME: better overflow check? */ | 144 | /* FIXME: better overflow check? */ |
145 | if (kill(pid, signo)!=0) { | 145 | if (kill(pid, signo)!=0) { |
146 | bb_perror_msg("cannot kill pid %ld", (long)pid); | 146 | bb_perror_msg("cannot kill pid %ld", (long)pid); |
diff --git a/procps/pidof.c b/procps/pidof.c index e6c954843..62c590fd8 100644 --- a/procps/pidof.c +++ b/procps/pidof.c | |||
@@ -14,7 +14,7 @@ | |||
14 | #define SINGLE (1<<0) | 14 | #define SINGLE (1<<0) |
15 | #else | 15 | #else |
16 | #define _SINGLE_COMPL(a) | 16 | #define _SINGLE_COMPL(a) |
17 | #define SINGLE (0) | 17 | #define SINGLE 0 |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | #if ENABLE_FEATURE_PIDOF_OMIT | 20 | #if ENABLE_FEATURE_PIDOF_OMIT |
@@ -56,7 +56,7 @@ int pidof_main(int argc, char **argv) | |||
56 | /* are we asked to exclude the parent's process ID? */ | 56 | /* are we asked to exclude the parent's process ID? */ |
57 | if (!strncmp(omits_p->data, "%PPID", 5)) { | 57 | if (!strncmp(omits_p->data, "%PPID", 5)) { |
58 | llist_pop(&omits_p); | 58 | llist_pop(&omits_p); |
59 | snprintf(getppid_str, sizeof(getppid_str), "%d", getppid()); | 59 | snprintf(getppid_str, sizeof(getppid_str), "%ld", (long)getppid()); |
60 | llist_add_to(&omits_p, getppid_str); | 60 | llist_add_to(&omits_p, getppid_str); |
61 | } | 61 | } |
62 | omits_p = omits_p->link; | 62 | omits_p = omits_p->link; |
@@ -64,19 +64,19 @@ int pidof_main(int argc, char **argv) | |||
64 | } | 64 | } |
65 | #endif | 65 | #endif |
66 | /* Looks like everything is set to go. */ | 66 | /* Looks like everything is set to go. */ |
67 | while(optind < argc) { | 67 | while (optind < argc) { |
68 | long *pidList; | 68 | long *pidList; |
69 | long *pl; | 69 | long *pl; |
70 | 70 | ||
71 | /* reverse the pidlist like GNU pidof does. */ | 71 | /* reverse the pidlist like GNU pidof does. */ |
72 | pidList = pidlist_reverse(find_pid_by_name(argv[optind])); | 72 | pidList = pidlist_reverse(find_pid_by_name(argv[optind])); |
73 | for(pl = pidList; *pl > 0; pl++) { | 73 | for (pl = pidList; *pl > 0; pl++) { |
74 | #if ENABLE_FEATURE_PIDOF_OMIT | 74 | #if ENABLE_FEATURE_PIDOF_OMIT |
75 | unsigned omitted = 0; | 75 | unsigned omitted = 0; |
76 | if (opt & OMIT) { | 76 | if (opt & OMIT) { |
77 | llist_t *omits_p = omits; | 77 | llist_t *omits_p = omits; |
78 | while (omits_p) | 78 | while (omits_p) |
79 | if (strtol(omits_p->data, NULL, 10) == *pl) { | 79 | if (xatoul(omits_p->data) == *pl) { |
80 | omitted = 1; break; | 80 | omitted = 1; break; |
81 | } else | 81 | } else |
82 | omits_p = omits_p->link; | 82 | omits_p = omits_p->link; |
diff --git a/procps/renice.c b/procps/renice.c index 53dc57855..a91328f53 100644 --- a/procps/renice.c +++ b/procps/renice.c | |||
@@ -53,13 +53,13 @@ static inline int int_add_no_wrap(int a, int b) | |||
53 | 53 | ||
54 | int renice_main(int argc, char **argv) | 54 | int renice_main(int argc, char **argv) |
55 | { | 55 | { |
56 | static const char Xetpriority_msg[] = "%d : %cetpriority"; | 56 | static const char Xetpriority_msg[] = "%d: %cetpriority"; |
57 | 57 | ||
58 | int retval = EXIT_SUCCESS; | 58 | int retval = EXIT_SUCCESS; |
59 | int which = PRIO_PROCESS; /* Default 'which' value. */ | 59 | int which = PRIO_PROCESS; /* Default 'which' value. */ |
60 | int use_relative = 0; | 60 | int use_relative = 0; |
61 | int adjustment, new_priority; | 61 | int adjustment, new_priority; |
62 | id_t who; | 62 | unsigned who; |
63 | 63 | ||
64 | ++argv; | 64 | ++argv; |
65 | 65 | ||
@@ -74,15 +74,15 @@ int renice_main(int argc, char **argv) | |||
74 | } | 74 | } |
75 | 75 | ||
76 | /* Get the priority adjustment (absolute or relative). */ | 76 | /* Get the priority adjustment (absolute or relative). */ |
77 | adjustment = bb_xgetlarg(*argv, 10, INT_MIN, INT_MAX); | 77 | adjustment = xatoi(*argv); |
78 | 78 | ||
79 | while (*++argv) { | 79 | while (*++argv) { |
80 | /* Check for a mode switch. */ | 80 | /* Check for a mode switch. */ |
81 | if ((argv[0][0] == '-') && argv[0][1] && !argv[0][2]) { | 81 | if ((argv[0][0] == '-') && argv[0][1] && !argv[0][2]) { |
82 | static const char opts[] | 82 | static const char opts[] |
83 | = { 'p', 'g', 'u', 0, PRIO_PROCESS, PRIO_PGRP, PRIO_USER }; | 83 | = { 'p', 'g', 'u', 0, PRIO_PROCESS, PRIO_PGRP, PRIO_USER }; |
84 | const char *p; | 84 | const char *p = strchr(opts, argv[0][1]); |
85 | if ((p = strchr(opts, argv[0][1]))) { | 85 | if (p) { |
86 | which = p[4]; | 86 | which = p[4]; |
87 | continue; | 87 | continue; |
88 | } | 88 | } |
@@ -91,16 +91,14 @@ int renice_main(int argc, char **argv) | |||
91 | /* Process an ID arg. */ | 91 | /* Process an ID arg. */ |
92 | if (which == PRIO_USER) { | 92 | if (which == PRIO_USER) { |
93 | struct passwd *p; | 93 | struct passwd *p; |
94 | if (!(p = getpwnam(*argv))) { | 94 | p = getpwnam(*argv); |
95 | if (!p) { | ||
95 | bb_error_msg("unknown user: %s", *argv); | 96 | bb_error_msg("unknown user: %s", *argv); |
96 | goto HAD_ERROR; | 97 | goto HAD_ERROR; |
97 | } | 98 | } |
98 | who = p->pw_uid; | 99 | who = p->pw_uid; |
99 | } else { | 100 | } else { |
100 | char *e; | 101 | if (safe_strtou(*argv, &who)) { |
101 | errno = 0; | ||
102 | who = strtoul(*argv, &e, 10); | ||
103 | if (*e || (*argv == e) || errno) { | ||
104 | bb_error_msg("bad value: %s", *argv); | 102 | bb_error_msg("bad value: %s", *argv); |
105 | goto HAD_ERROR; | 103 | goto HAD_ERROR; |
106 | } | 104 | } |
diff --git a/procps/top.c b/procps/top.c index be1c45faa..14a3870a1 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -384,8 +384,8 @@ static void sig_catcher(int sig ATTRIBUTE_UNUSED) | |||
384 | int top_main(int argc, char **argv) | 384 | int top_main(int argc, char **argv) |
385 | { | 385 | { |
386 | int count, lines, col; | 386 | int count, lines, col; |
387 | int interval = 5; /* default update rate is 5 seconds */ | 387 | unsigned interval = 5; /* default update rate is 5 seconds */ |
388 | int iterations = -1; /* 2^32 iterations by default :) */ | 388 | unsigned iterations = UINT_MAX; /* 2^32 iterations by default :) */ |
389 | char *sinterval, *siterations; | 389 | char *sinterval, *siterations; |
390 | #ifdef CONFIG_FEATURE_USE_TERMIOS | 390 | #ifdef CONFIG_FEATURE_USE_TERMIOS |
391 | struct termios new_settings; | 391 | struct termios new_settings; |
@@ -399,8 +399,8 @@ int top_main(int argc, char **argv) | |||
399 | opt_complementary = "-"; | 399 | opt_complementary = "-"; |
400 | getopt32(argc, argv, "d:n:b", | 400 | getopt32(argc, argv, "d:n:b", |
401 | &sinterval, &siterations); | 401 | &sinterval, &siterations); |
402 | if (option_mask32 & 0x1) interval = atoi(sinterval); // -d | 402 | if (option_mask32 & 0x1) interval = xatou(sinterval); // -d |
403 | if (option_mask32 & 0x2) iterations = atoi(siterations); // -n | 403 | if (option_mask32 & 0x2) iterations = xatou(siterations); // -n |
404 | //if (option_mask32 & 0x4) // -b | 404 | //if (option_mask32 & 0x4) // -b |
405 | 405 | ||
406 | /* change to /proc */ | 406 | /* change to /proc */ |
diff --git a/runit/chpst.c b/runit/chpst.c index 4c44e3c0c..5f30b8815 100644 --- a/runit/chpst.c +++ b/runit/chpst.c | |||
@@ -22,7 +22,7 @@ static long limitf = -2; | |||
22 | static long limitc = -2; | 22 | static long limitc = -2; |
23 | static long limitr = -2; | 23 | static long limitr = -2; |
24 | static long limitt = -2; | 24 | static long limitt = -2; |
25 | static long nicelvl; | 25 | static int nicelvl; |
26 | static const char *root; | 26 | static const char *root; |
27 | 27 | ||
28 | static void suidgid(char *user) | 28 | static void suidgid(char *user) |
@@ -229,16 +229,16 @@ int chpst_main(int argc, char **argv) | |||
229 | // if (option_mask32 & 0x1) // -u | 229 | // if (option_mask32 & 0x1) // -u |
230 | // if (option_mask32 & 0x2) // -U | 230 | // if (option_mask32 & 0x2) // -U |
231 | // if (option_mask32 & 0x4) // -e | 231 | // if (option_mask32 & 0x4) // -e |
232 | if (option_mask32 & 0x8) limits = limitl = limita = limitd = bb_xgetularg10(m); // -m | 232 | if (option_mask32 & 0x8) limits = limitl = limita = limitd = xatoul(m); // -m |
233 | if (option_mask32 & 0x10) limitd = bb_xgetularg10(d); // -d | 233 | if (option_mask32 & 0x10) limitd = xatoul(d); // -d |
234 | if (option_mask32 & 0x20) limito = bb_xgetularg10(o); // -o | 234 | if (option_mask32 & 0x20) limito = xatoul(o); // -o |
235 | if (option_mask32 & 0x40) limitp = bb_xgetularg10(p); // -p | 235 | if (option_mask32 & 0x40) limitp = xatoul(p); // -p |
236 | if (option_mask32 & 0x80) limitf = bb_xgetularg10(f); // -f | 236 | if (option_mask32 & 0x80) limitf = xatoul(f); // -f |
237 | if (option_mask32 & 0x100) limitc = bb_xgetularg10(c); // -c | 237 | if (option_mask32 & 0x100) limitc = xatoul(c); // -c |
238 | if (option_mask32 & 0x200) limitr = bb_xgetularg10(r); // -r | 238 | if (option_mask32 & 0x200) limitr = xatoul(r); // -r |
239 | if (option_mask32 & 0x400) limitt = bb_xgetularg10(t); // -t | 239 | if (option_mask32 & 0x400) limitt = xatoul(t); // -t |
240 | // if (option_mask32 & 0x800) // -/ | 240 | // if (option_mask32 & 0x800) // -/ |
241 | if (option_mask32 & 0x1000) nicelvl = bb_xgetlarg_bnd_sfx(n, 10, -20, 20, NULL); // -n | 241 | if (option_mask32 & 0x1000) nicelvl = xatoi(n); // -n |
242 | // The below consts should match #defines at top! | 242 | // The below consts should match #defines at top! |
243 | //if (option_mask32 & 0x2000) OPT_verbose = 1; // -v | 243 | //if (option_mask32 & 0x2000) OPT_verbose = 1; // -v |
244 | //if (option_mask32 & 0x4000) OPT_pgrp = 1; // -P | 244 | //if (option_mask32 & 0x4000) OPT_pgrp = 1; // -P |
@@ -312,17 +312,17 @@ static void softlimit(int argc, char **argv) | |||
312 | char *a,*c,*d,*f,*l,*m,*o,*p,*r,*s,*t; | 312 | char *a,*c,*d,*f,*l,*m,*o,*p,*r,*s,*t; |
313 | getopt32(argc, argv, "a:c:d:f:l:m:o:p:r:s:t:", | 313 | getopt32(argc, argv, "a:c:d:f:l:m:o:p:r:s:t:", |
314 | &a,&c,&d,&f,&l,&m,&o,&p,&r,&s,&t); | 314 | &a,&c,&d,&f,&l,&m,&o,&p,&r,&s,&t); |
315 | if (option_mask32 & 0x001) limita = bb_xgetularg10(a); // -a | 315 | if (option_mask32 & 0x001) limita = xatoul(a); // -a |
316 | if (option_mask32 & 0x002) limitc = bb_xgetularg10(c); // -c | 316 | if (option_mask32 & 0x002) limitc = xatoul(c); // -c |
317 | if (option_mask32 & 0x004) limitd = bb_xgetularg10(d); // -d | 317 | if (option_mask32 & 0x004) limitd = xatoul(d); // -d |
318 | if (option_mask32 & 0x008) limitf = bb_xgetularg10(f); // -f | 318 | if (option_mask32 & 0x008) limitf = xatoul(f); // -f |
319 | if (option_mask32 & 0x010) limitl = bb_xgetularg10(l); // -l | 319 | if (option_mask32 & 0x010) limitl = xatoul(l); // -l |
320 | if (option_mask32 & 0x020) limits = limitl = limita = limitd = bb_xgetularg10(m); // -m | 320 | if (option_mask32 & 0x020) limits = limitl = limita = limitd = xatoul(m); // -m |
321 | if (option_mask32 & 0x040) limito = bb_xgetularg10(o); // -o | 321 | if (option_mask32 & 0x040) limito = xatoul(o); // -o |
322 | if (option_mask32 & 0x080) limitp = bb_xgetularg10(p); // -p | 322 | if (option_mask32 & 0x080) limitp = xatoul(p); // -p |
323 | if (option_mask32 & 0x100) limitr = bb_xgetularg10(r); // -r | 323 | if (option_mask32 & 0x100) limitr = xatoul(r); // -r |
324 | if (option_mask32 & 0x200) limits = bb_xgetularg10(s); // -s | 324 | if (option_mask32 & 0x200) limits = xatoul(s); // -s |
325 | if (option_mask32 & 0x400) limitt = bb_xgetularg10(t); // -t | 325 | if (option_mask32 & 0x400) limitt = xatoul(t); // -t |
326 | argv += optind; | 326 | argv += optind; |
327 | if (!argv[0]) bb_show_usage(); | 327 | if (!argv[0]) bb_show_usage(); |
328 | slimit(); | 328 | slimit(); |
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index e629bec5d..f735d9fc1 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -43,7 +43,6 @@ int klogd_main(int argc, char **argv) | |||
43 | int i, n, lastc; | 43 | int i, n, lastc; |
44 | char *start; | 44 | char *start; |
45 | 45 | ||
46 | |||
47 | { | 46 | { |
48 | unsigned opt; | 47 | unsigned opt; |
49 | 48 | ||
@@ -52,7 +51,7 @@ int klogd_main(int argc, char **argv) | |||
52 | 51 | ||
53 | if (opt & OPT_LEVEL) { | 52 | if (opt & OPT_LEVEL) { |
54 | /* Valid levels are between 1 and 8 */ | 53 | /* Valid levels are between 1 and 8 */ |
55 | console_log_level = bb_xgetlarg(start, 10, 1, 8); | 54 | console_log_level = xatoul_range(start, 1, 8); |
56 | } | 55 | } |
57 | 56 | ||
58 | if (!(opt & OPT_FOREGROUND)) { | 57 | if (!(opt & OPT_FOREGROUND)) { |
diff --git a/sysklogd/logger.c b/sysklogd/logger.c index 15a4bfb82..8901bd79f 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c | |||
@@ -48,14 +48,14 @@ static int decode(char *name, CODE * codetab) | |||
48 | CODE *c; | 48 | CODE *c; |
49 | 49 | ||
50 | if (isdigit(*name)) | 50 | if (isdigit(*name)) |
51 | return (atoi(name)); | 51 | return atoi(name); |
52 | for (c = codetab; c->c_name; c++) { | 52 | for (c = codetab; c->c_name; c++) { |
53 | if (!strcasecmp(name, c->c_name)) { | 53 | if (!strcasecmp(name, c->c_name)) { |
54 | return (c->c_val); | 54 | return c->c_val; |
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | return (-1); | 58 | return -1; |
59 | } | 59 | } |
60 | 60 | ||
61 | /* Decode a symbolic name to a numeric value | 61 | /* Decode a symbolic name to a numeric value |
@@ -177,6 +177,3 @@ int logger_main(int argc, char **argv) | |||
177 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 177 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
178 | * SUCH DAMAGE. | 178 | * SUCH DAMAGE. |
179 | */ | 179 | */ |
180 | |||
181 | |||
182 | |||
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 254d7e73c..9e030bd63 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -575,20 +575,20 @@ int syslogd_main(int argc, char **argv) | |||
575 | 575 | ||
576 | /* do normal option parsing */ | 576 | /* do normal option parsing */ |
577 | getopt32(argc, argv, OPTION_STR, OPTION_PARAM); | 577 | getopt32(argc, argv, OPTION_STR, OPTION_PARAM); |
578 | if (option_mask32 & OPT_mark) MarkInterval = atoi(opt_m) * 60; // -m | 578 | if (option_mask32 & OPT_mark) MarkInterval = xatoul_range(opt_m, 0, INT_MAX/60) * 60; // -m |
579 | //if (option_mask32 & OPT_nofork) // -n | 579 | //if (option_mask32 & OPT_nofork) // -n |
580 | //if (option_mask32 & OPT_outfile) // -O | 580 | //if (option_mask32 & OPT_outfile) // -O |
581 | if (option_mask32 & OPT_loglevel) { // -l | 581 | if (option_mask32 & OPT_loglevel) { // -l |
582 | logLevel = atoi(opt_l); | 582 | logLevel = xatoi_u(opt_l); |
583 | /* Valid levels are between 1 and 8 */ | 583 | /* Valid levels are between 1 and 8 */ |
584 | if (logLevel < 1 || logLevel > 8) | 584 | if (logLevel < 1 || logLevel > 8) |
585 | bb_show_usage(); | 585 | bb_show_usage(); |
586 | } | 586 | } |
587 | //if (option_mask32 & OPT_small) // -S | 587 | //if (option_mask32 & OPT_small) // -S |
588 | #if ENABLE_FEATURE_ROTATE_LOGFILE | 588 | #if ENABLE_FEATURE_ROTATE_LOGFILE |
589 | if (option_mask32 & OPT_filesize) logFileSize = atoi(opt_s) * 1024; // -s | 589 | if (option_mask32 & OPT_filesize) logFileSize = xatoul_range(opt_s, 0, INT_MAX/1024) * 1024; // -s |
590 | if (option_mask32 & OPT_rotatecnt) { // -b | 590 | if (option_mask32 & OPT_rotatecnt) { // -b |
591 | logFileRotate = atoi(opt_b); | 591 | logFileRotate = xatoi_u(opt_b); |
592 | if (logFileRotate > 99) logFileRotate = 99; | 592 | if (logFileRotate > 99) logFileRotate = 99; |
593 | } | 593 | } |
594 | #endif | 594 | #endif |
@@ -598,7 +598,7 @@ int syslogd_main(int argc, char **argv) | |||
598 | char *host = xstrdup(opt_R); | 598 | char *host = xstrdup(opt_R); |
599 | p = strchr(host, ':'); | 599 | p = strchr(host, ':'); |
600 | if (p) { | 600 | if (p) { |
601 | port = atoi(p + 1); | 601 | port = xatou16(p + 1); |
602 | *p = '\0'; | 602 | *p = '\0'; |
603 | } | 603 | } |
604 | remoteaddr.sin_family = AF_INET; | 604 | remoteaddr.sin_family = AF_INET; |
@@ -612,9 +612,7 @@ int syslogd_main(int argc, char **argv) | |||
612 | #if ENABLE_FEATURE_IPC_SYSLOG | 612 | #if ENABLE_FEATURE_IPC_SYSLOG |
613 | if (option_mask32 & OPT_circularlog) { // -C | 613 | if (option_mask32 & OPT_circularlog) { // -C |
614 | if (opt_C) { | 614 | if (opt_C) { |
615 | int buf_size = atoi(opt_C); | 615 | shm_size = xatoul_range(opt_C, 4, INT_MAX/1024) * 1024; |
616 | if (buf_size >= 4) | ||
617 | shm_size = buf_size * 1024; | ||
618 | } | 616 | } |
619 | } | 617 | } |
620 | #endif | 618 | #endif |
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c index 277415a2d..658cddc38 100644 --- a/util-linux/dmesg.c +++ b/util-linux/dmesg.c | |||
@@ -19,13 +19,13 @@ int dmesg_main(int argc, char *argv[]) | |||
19 | int flags = getopt32(argc, argv, "cs:n:", &size, &level); | 19 | int flags = getopt32(argc, argv, "cs:n:", &size, &level); |
20 | 20 | ||
21 | if (flags & 4) { | 21 | if (flags & 4) { |
22 | if (klogctl(8, NULL, bb_xgetlarg(level, 10, 0, 10))) | 22 | if (klogctl(8, NULL, xatoul_range(level, 0, 10))) |
23 | bb_perror_msg_and_die("klogctl"); | 23 | bb_perror_msg_and_die("klogctl"); |
24 | } else { | 24 | } else { |
25 | int len; | 25 | int len; |
26 | char *buf; | 26 | char *buf; |
27 | 27 | ||
28 | len = (flags & 2) ? bb_xgetlarg(size, 10, 2, INT_MAX) : 16384; | 28 | len = (flags & 2) ? xatoul_range(size, 2, INT_MAX) : 16384; |
29 | buf = xmalloc(len); | 29 | buf = xmalloc(len); |
30 | if (0 > (len = klogctl(3 + (flags & 1), buf, len))) | 30 | if (0 > (len = klogctl(3 + (flags & 1), buf, len))) |
31 | bb_perror_msg_and_die("klogctl"); | 31 | bb_perror_msg_and_die("klogctl"); |
diff --git a/util-linux/fbset.c b/util-linux/fbset.c index bc8ec1806..1aa0a0ac1 100644 --- a/util-linux/fbset.c +++ b/util-linux/fbset.c | |||
@@ -338,20 +338,20 @@ int fbset_main(int argc, char **argv) | |||
338 | modefile = argv[1]; | 338 | modefile = argv[1]; |
339 | break; | 339 | break; |
340 | case CMD_GEOMETRY: | 340 | case CMD_GEOMETRY: |
341 | varset.xres = strtoul(argv[1], 0, 0); | 341 | varset.xres = xatou32(argv[1]); |
342 | varset.yres = strtoul(argv[2], 0, 0); | 342 | varset.yres = xatou32(argv[2]); |
343 | varset.xres_virtual = strtoul(argv[3], 0, 0); | 343 | varset.xres_virtual = xatou32(argv[3]); |
344 | varset.yres_virtual = strtoul(argv[4], 0, 0); | 344 | varset.yres_virtual = xatou32(argv[4]); |
345 | varset.bits_per_pixel = strtoul(argv[5], 0, 0); | 345 | varset.bits_per_pixel = xatou32(argv[5]); |
346 | break; | 346 | break; |
347 | case CMD_TIMING: | 347 | case CMD_TIMING: |
348 | varset.pixclock = strtoul(argv[1], 0, 0); | 348 | varset.pixclock = xatou32(argv[1]); |
349 | varset.left_margin = strtoul(argv[2], 0, 0); | 349 | varset.left_margin = xatou32(argv[2]); |
350 | varset.right_margin = strtoul(argv[3], 0, 0); | 350 | varset.right_margin = xatou32(argv[3]); |
351 | varset.upper_margin = strtoul(argv[4], 0, 0); | 351 | varset.upper_margin = xatou32(argv[4]); |
352 | varset.lower_margin = strtoul(argv[5], 0, 0); | 352 | varset.lower_margin = xatou32(argv[5]); |
353 | varset.hsync_len = strtoul(argv[6], 0, 0); | 353 | varset.hsync_len = xatou32(argv[6]); |
354 | varset.vsync_len = strtoul(argv[7], 0, 0); | 354 | varset.vsync_len = xatou32(argv[7]); |
355 | break; | 355 | break; |
356 | case CMD_ALL: | 356 | case CMD_ALL: |
357 | g_options |= OPT_ALL; | 357 | g_options |= OPT_ALL; |
@@ -361,13 +361,13 @@ int fbset_main(int argc, char **argv) | |||
361 | break; | 361 | break; |
362 | #ifdef CONFIG_FEATURE_FBSET_FANCY | 362 | #ifdef CONFIG_FEATURE_FBSET_FANCY |
363 | case CMD_XRES: | 363 | case CMD_XRES: |
364 | varset.xres = strtoul(argv[1], 0, 0); | 364 | varset.xres = xatou32(argv[1]); |
365 | break; | 365 | break; |
366 | case CMD_YRES: | 366 | case CMD_YRES: |
367 | varset.yres = strtoul(argv[1], 0, 0); | 367 | varset.yres = xatou32(argv[1]); |
368 | break; | 368 | break; |
369 | case CMD_DEPTH: | 369 | case CMD_DEPTH: |
370 | varset.bits_per_pixel = strtoul(argv[1], 0, 0); | 370 | varset.bits_per_pixel = xatou32(argv[1]); |
371 | break; | 371 | break; |
372 | #endif | 372 | #endif |
373 | } | 373 | } |
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 85acaa4aa..3bf78ee04 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -1222,8 +1222,7 @@ edit_int(int def, char *mesg) | |||
1222 | printf(" (%d): ", def); | 1222 | printf(" (%d): ", def); |
1223 | if (!read_line()) | 1223 | if (!read_line()) |
1224 | return def; | 1224 | return def; |
1225 | } | 1225 | } while (!isdigit(*line_ptr)); |
1226 | while (!isdigit(*line_ptr)); /* FIXME: ?!! */ | ||
1227 | return atoi(line_ptr); | 1226 | return atoi(line_ptr); |
1228 | } | 1227 | } |
1229 | 1228 | ||
@@ -5664,14 +5663,14 @@ int fdisk_main(int argc, char **argv) | |||
5664 | #ifdef CONFIG_FEATURE_FDISK_BLKSIZE | 5663 | #ifdef CONFIG_FEATURE_FDISK_BLKSIZE |
5665 | "s" | 5664 | "s" |
5666 | #endif | 5665 | #endif |
5667 | )) != -1) { | 5666 | )) != -1) { |
5668 | switch (c) { | 5667 | switch (c) { |
5669 | case 'b': | 5668 | case 'b': |
5670 | /* Ugly: this sector size is really per device, | 5669 | /* Ugly: this sector size is really per device, |
5671 | so cannot be combined with multiple disks, | 5670 | so cannot be combined with multiple disks, |
5672 | and te same goes for the C/H/S options. | 5671 | and te same goes for the C/H/S options. |
5673 | */ | 5672 | */ |
5674 | sector_size = atoi(optarg); | 5673 | sector_size = xatoi_u(optarg); |
5675 | if (sector_size != 512 && sector_size != 1024 && | 5674 | if (sector_size != 512 && sector_size != 1024 && |
5676 | sector_size != 2048) | 5675 | sector_size != 2048) |
5677 | bb_show_usage(); | 5676 | bb_show_usage(); |
@@ -5679,15 +5678,15 @@ int fdisk_main(int argc, char **argv) | |||
5679 | user_set_sector_size = 1; | 5678 | user_set_sector_size = 1; |
5680 | break; | 5679 | break; |
5681 | case 'C': | 5680 | case 'C': |
5682 | user_cylinders = atoi(optarg); | 5681 | user_cylinders = xatoi_u(optarg); |
5683 | break; | 5682 | break; |
5684 | case 'H': | 5683 | case 'H': |
5685 | user_heads = atoi(optarg); | 5684 | user_heads = xatoi_u(optarg); |
5686 | if (user_heads <= 0 || user_heads >= 256) | 5685 | if (user_heads <= 0 || user_heads >= 256) |
5687 | user_heads = 0; | 5686 | user_heads = 0; |
5688 | break; | 5687 | break; |
5689 | case 'S': | 5688 | case 'S': |
5690 | user_sectors = atoi(optarg); | 5689 | user_sectors = xatoi_u(optarg); |
5691 | if (user_sectors <= 0 || user_sectors >= 64) | 5690 | if (user_sectors <= 0 || user_sectors >= 64) |
5692 | user_sectors = 0; | 5691 | user_sectors = 0; |
5693 | break; | 5692 | break; |
diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c index e038005f5..03b222dd0 100644 --- a/util-linux/hexdump.c +++ b/util-linux/hexdump.c | |||
@@ -79,10 +79,10 @@ int hexdump_main(int argc, char **argv) | |||
79 | bb_dump_addfile(optarg); | 79 | bb_dump_addfile(optarg); |
80 | } /* else */ | 80 | } /* else */ |
81 | if (ch == 'n') { | 81 | if (ch == 'n') { |
82 | bb_dump_length = bb_xgetularg10_bnd(optarg, 0, INT_MAX); | 82 | bb_dump_length = xatoi_u(optarg); |
83 | } /* else */ | 83 | } /* else */ |
84 | if (ch == 's') { | 84 | if (ch == 's') { |
85 | bb_dump_skip = bb_xgetularg_bnd_sfx(optarg, 10, 0, LONG_MAX, suffixes); | 85 | bb_dump_skip = xatoul_range_sfx(optarg, 0, LONG_MAX, suffixes); |
86 | } /* else */ | 86 | } /* else */ |
87 | if (ch == 'v') { | 87 | if (ch == 'v') { |
88 | bb_dump_vflag = ALL; | 88 | bb_dump_vflag = ALL; |
diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c index 5e58e81da..ba81ea97c 100644 --- a/util-linux/ipcs.c +++ b/util-linux/ipcs.c | |||
@@ -581,7 +581,7 @@ int ipcs_main(int argc, char **argv) | |||
581 | 581 | ||
582 | opt = getopt32(argc, argv, "i:aqsmtcplu", &opt_i); | 582 | opt = getopt32(argc, argv, "i:aqsmtcplu", &opt_i); |
583 | if (opt & 0x1) { // -i | 583 | if (opt & 0x1) { // -i |
584 | id = atoi(opt_i); | 584 | id = xatoi(opt_i); |
585 | flags |= flag_print; | 585 | flags |= flag_print; |
586 | } | 586 | } |
587 | if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a | 587 | if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a |
diff --git a/util-linux/losetup.c b/util-linux/losetup.c index 8882ee4da..c7eb85a91 100644 --- a/util-linux/losetup.c +++ b/util-linux/losetup.c | |||
@@ -16,7 +16,7 @@ int losetup_main(int argc, char **argv) | |||
16 | { | 16 | { |
17 | unsigned opt; | 17 | unsigned opt; |
18 | char *opt_o; | 18 | char *opt_o; |
19 | int offset = 0; | 19 | unsigned long long offset = 0; |
20 | 20 | ||
21 | opt = getopt32(argc, argv, "do:", &opt_o); | 21 | opt = getopt32(argc, argv, "do:", &opt_o); |
22 | argc -= optind; | 22 | argc -= optind; |
@@ -35,7 +35,7 @@ int losetup_main(int argc, char **argv) | |||
35 | } | 35 | } |
36 | 36 | ||
37 | if (opt == 0x2) // -o | 37 | if (opt == 0x2) // -o |
38 | offset = bb_xparse_number(opt_o, NULL); | 38 | offset = xatoull(opt_o); |
39 | 39 | ||
40 | /* -o or no option */ | 40 | /* -o or no option */ |
41 | 41 | ||
diff --git a/util-linux/mount.c b/util-linux/mount.c index 141517ba0..531fb4520 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -856,7 +856,7 @@ static int nfsmount(struct mntent *mp, int vfsflags, char *filteropts) | |||
856 | for (opt = strtok(filteropts, ","); opt; opt = strtok(NULL, ",")) { | 856 | for (opt = strtok(filteropts, ","); opt; opt = strtok(NULL, ",")) { |
857 | char *opteq = strchr(opt, '='); | 857 | char *opteq = strchr(opt, '='); |
858 | if (opteq) { | 858 | if (opteq) { |
859 | int val = atoi(opteq + 1); | 859 | int val = xatoi_u(opteq + 1); |
860 | *opteq = '\0'; | 860 | *opteq = '\0'; |
861 | if (!strcmp(opt, "rsize")) | 861 | if (!strcmp(opt, "rsize")) |
862 | data.rsize = val; | 862 | data.rsize = val; |
diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index ff70bf79b..b368067ef 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c | |||
@@ -38,8 +38,8 @@ | |||
38 | #define S_LEN 128 | 38 | #define S_LEN 128 |
39 | 39 | ||
40 | /* These are the defaults */ | 40 | /* These are the defaults */ |
41 | static const char defaultmap[]="/boot/System.map"; | 41 | static const char defaultmap[] = "/boot/System.map"; |
42 | static const char defaultpro[]="/proc/profile"; | 42 | static const char defaultpro[] = "/proc/profile"; |
43 | 43 | ||
44 | int readprofile_main(int argc, char **argv) | 44 | int readprofile_main(int argc, char **argv) |
45 | { | 45 | { |
@@ -78,7 +78,7 @@ int readprofile_main(int argc, char **argv) | |||
78 | * not sizeof(int), the multiplier is not changed | 78 | * not sizeof(int), the multiplier is not changed |
79 | */ | 79 | */ |
80 | if (mult) { | 80 | if (mult) { |
81 | multiplier = strtoul(mult, 0, 10); | 81 | multiplier = xatoi_u(mult); |
82 | to_write = sizeof(int); | 82 | to_write = sizeof(int); |
83 | } else { | 83 | } else { |
84 | multiplier = 0; | 84 | multiplier = 0; |