Skip to content

Commit c1b7735

Browse files
committed
Merge branch 'code/hygiene'
* code/hygiene: hygiene, make xstrndup() act sanitising chore, let coverity know we've done our best hygiene, try and check string so i'ts untainted when passed to __strdt_special() hygiene, check ASCII range of special
2 parents bbdab58 + aa94f7e commit c1b7735

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/dt-io.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ serror(const char *fmt, ...)
7171

7272
#include "strpdt-special.c"
7373

74-
static inline __attribute__((const, pure)) size_t
75-
min_z(size_t z1, size_t z2)
76-
{
77-
return z1 <= z2 ? z1 : z2;
78-
}
79-
74+
/* coverity[-tainted_data_sink: arg-0] */
8075
dt_strpdt_special_t
8176
dt_io_strpdt_special(const char *str)
8277
{
8378
const struct dt_strpdt_special_s *res;
84-
size_t len = min_z(strlen(str), 16U);
79+
size_t len = strlen(str) & 0xfU;
8580

81+
for (size_t i = 0U; i < len; i++) {
82+
if (UNLIKELY((signed char)str[i] < ' ')) {
83+
return STRPDT_UNK;
84+
}
85+
}
8686
if (UNLIKELY((res = __strpdt_special(str, len)) != NULL)) {
8787
return res->e;
8888
}

test/clitosis.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*** clitosis.c -- command-line-interface tester on shell input syntax
22
*
3-
* Copyright (C) 2013-2020 Sebastian Freundt
3+
* Copyright (C) 2013-2021 Sebastian Freundt
44
*
55
* Author: Sebastian Freundt <freundt@ga-group.nl>
66
*
@@ -318,6 +318,7 @@ xmemmem(const char *hay, const size_t hayz, const char *ndl, const size_t ndlz)
318318
return NULL;
319319
}
320320

321+
/* coverity[-tainted_data_sink: arg-0] */
321322
static char*
322323
xstrndup(const char *s, size_t z)
323324
{

0 commit comments

Comments
 (0)