Skip to content

Commit 0c5c33b

Browse files
util/strbuf: remove unused cli infrastructure imports
The ndctl cli interface is built around an imported perf cli infrastructure which was originally from git. [1] A recent static analysis scan exposed an integer overflow issue in strbuf_read() and although that is fixable, the function is not used in ndctl. Further examination revealed additional unused functionality in the string buffer handling import and a subset of that has already been obsoleted from the perf cli. In the interest of not maintaining unused code, remove the unused code in util/strbuf.h,c. Ndctl, including cxl-cli and daxctl, are mature cli's so it seems ok to let this functionality go after ~10 years. In the interest of not touching what is not causing an issue, the entirety of the original import was not reviewed at this time. [1] 9167739 ("ndctl: import cli infrastructure from perf") Reviewed-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alison Schofield <[email protected]>
1 parent cb21d22 commit 0c5c33b

File tree

2 files changed

+0
-58
lines changed

2 files changed

+0
-58
lines changed

util/strbuf.c

-51
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,6 @@ void strbuf_grow(struct strbuf *sb, size_t extra)
6060
ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc);
6161
}
6262

63-
static void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
64-
const void *data, size_t dlen)
65-
{
66-
if (pos + len < pos)
67-
die("you want to use way too much memory");
68-
if (pos > sb->len)
69-
die("`pos' is too far after the end of the buffer");
70-
if (pos + len > sb->len)
71-
die("`pos + len' is too far after the end of the buffer");
72-
73-
if (dlen >= len)
74-
strbuf_grow(sb, dlen - len);
75-
memmove(sb->buf + pos + dlen,
76-
sb->buf + pos + len,
77-
sb->len - pos - len);
78-
memcpy(sb->buf + pos, data, dlen);
79-
strbuf_setlen(sb, sb->len + dlen - len);
80-
}
81-
82-
void strbuf_remove(struct strbuf *sb, size_t pos, size_t len)
83-
{
84-
strbuf_splice(sb, pos, len, NULL, 0);
85-
}
86-
8763
void strbuf_add(struct strbuf *sb, const void *data, size_t len)
8864
{
8965
strbuf_grow(sb, len);
@@ -114,30 +90,3 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
11490
}
11591
strbuf_setlen(sb, sb->len + len);
11692
}
117-
118-
ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint)
119-
{
120-
size_t oldlen = sb->len;
121-
size_t oldalloc = sb->alloc;
122-
123-
strbuf_grow(sb, hint ? hint : 8192);
124-
for (;;) {
125-
ssize_t cnt;
126-
127-
cnt = read(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
128-
if (cnt < 0) {
129-
if (oldalloc == 0)
130-
strbuf_release(sb);
131-
else
132-
strbuf_setlen(sb, oldlen);
133-
return -1;
134-
}
135-
if (!cnt)
136-
break;
137-
sb->len += cnt;
138-
strbuf_grow(sb, 8192);
139-
}
140-
141-
sb->buf[sb->len] = '\0';
142-
return sb->len - oldlen;
143-
}

util/strbuf.h

-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ struct strbuf {
5656
#define STRBUF_INIT { 0, 0, strbuf_slopbuf }
5757

5858
/*----- strbuf life cycle -----*/
59-
extern void strbuf_init(struct strbuf *buf, ssize_t hint);
6059
extern void strbuf_release(struct strbuf *);
6160
extern char *strbuf_detach(struct strbuf *, size_t *);
6261

@@ -81,9 +80,6 @@ static inline void strbuf_addch(struct strbuf *sb, int c) {
8180
sb->buf[sb->len++] = c;
8281
sb->buf[sb->len] = '\0';
8382
}
84-
85-
extern void strbuf_remove(struct strbuf *, size_t pos, size_t len);
86-
8783
extern void strbuf_add(struct strbuf *, const void *, size_t);
8884
static inline void strbuf_addstr(struct strbuf *sb, const char *s) {
8985
strbuf_add(sb, s, strlen(s));
@@ -92,7 +88,4 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s) {
9288
__attribute__((format(printf,2,3)))
9389
extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
9490

95-
/* XXX: if read fails, any partial read is undone */
96-
extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint);
97-
9891
#endif /* __NDCTL_STRBUF_H */

0 commit comments

Comments
 (0)