Skip to content

Commit cbcc027

Browse files
committed
dd: exit when bs/ibs/obs/cbs isn't positive
1 parent 8e05053 commit cbcc027

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/uu/dd/src/parseargs.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ impl Parser {
182182
// conv=block,unblock,ascii
183183
// conv=block conv=unblock conv=ascii
184184
let block = if let Some(cbs) = self.cbs {
185+
// GNU dd exits when cbs is not positive.
186+
if cbs <= 0 {
187+
return Err(ParseError::InvalidNumber(cbs.to_string()));
188+
}
189+
185190
match conversion {
186191
Some(Conversion::Ascii) => Some(Block::Unblock(cbs)),
187192
Some(_) => Some(Block::Block(cbs)),
@@ -231,6 +236,13 @@ impl Parser {
231236
Some(bs) => (bs, bs),
232237
};
233238

239+
// GNU dd exits when bs, ibs or obs are not positive.
240+
for bs in [ibs, obs] {
241+
if bs <= 0 {
242+
return Err(ParseError::InvalidNumber(bs.to_string()));
243+
}
244+
}
245+
234246
// Whether to buffer partial output blocks until they are completed.
235247
//
236248
// From the GNU `dd` documentation for the `bs=BYTES` option:

0 commit comments

Comments
 (0)