util/strbuf: remove unused cli infrastructure imports
[email protected]
maintainerPATCH 1/1 util/strbuf: remove unused cli infrastructure imports
From: Alison Schofield <[email protected]>
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 sysbuf_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 14 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] 91677390f9e6 ("ndctl: import cli infrastructure from perf")
--- util/strbuf.c | 51 --------------------------------------------------- util/strbuf.h | 7 ------- 2 files changed, 58 deletions(-)
util/strbuf.c +0 -51
@@ -60,30 +60,6 @@ void strbuf_grow(struct strbuf *sb, size_t extra)ALLOC_GROW (sb->buf, sb->len + extra +1 , sb->alloc); } -static void strbuf_splice (struct strbuf *sb,size_t pos,size_t len, -const void *data,size_t dlen) -{ -if (pos + len < pos) -die ("you want to use way too much memory" ); -if (pos > sb->len) -die ("`pos' is too far after the end of the buffer" ); -if (pos + len > sb->len) -die ("`pos + len' is too far after the end of the buffer" ); - -if (dlen >= len) -strbuf_grow (sb, dlen - len); -memmove (sb->buf + pos + dlen, - sb->buf + pos + len, - sb->len - pos - len); -memcpy (sb->buf + pos, data, dlen); -strbuf_setlen (sb, sb->len + dlen - len); -} - -void strbuf_remove (struct strbuf *sb,size_t pos,size_t len) -{ -strbuf_splice (sb, pos, len,NULL ,0 ); -} -void strbuf_add (struct strbuf *sb,const void *data,size_t len) {strbuf_grow (sb, len);
@@ -114,30 +90,3 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...) }strbuf_setlen (sb, sb->len + len); } - -ssize_t strbuf_read (struct strbuf *sb,int fd,ssize_t hint) -{ -size_t oldlen = sb->len; -size_t oldalloc = sb->alloc; - -strbuf_grow (sb, hint ? hint :8192 ); -for (;;) { -ssize_t cnt; - - cnt =read (fd, sb->buf + sb->len, sb->alloc - sb->len -1 ); -if (cnt <0 ) { -if (oldalloc ==0 ) -strbuf_release (sb); -else -strbuf_setlen (sb, oldlen); -return -1 ; - } -if (!cnt) -break ; - sb->len += cnt; -strbuf_grow (sb,8192 ); - } - - sb->buf[sb->len] ='\0' ; -return sb->len - oldlen; -}
util/strbuf.h +0 -7
@@ -56,7 +56,6 @@ struct strbuf {#define STRBUF_INIT { 0, 0, strbuf_slopbuf }/*----- strbuf life cycle -----*/ -extern void strbuf_init (struct strbuf *buf,ssize_t hint);extern void strbuf_release (struct strbuf *);extern char *strbuf_detach (struct strbuf *,size_t *);
@@ -81,9 +80,6 @@ static inline void strbuf_addch(struct strbuf *sb, int c) { sb->buf[sb->len++] = c; sb->buf[sb->len] ='\0' ; } - -extern void strbuf_remove (struct strbuf *,size_t pos,size_t len); -extern void strbuf_add (struct strbuf *,const void *,size_t );static inline void strbuf_addstr (struct strbuf *sb,const char *s) {strbuf_add (sb, s,strlen (s));
@@ -92,7 +88,4 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s) { __attribute__((format (printf,2 ,3 )))extern void strbuf_addf (struct strbuf *sb,const char *fmt, ...); -/* XXX: if read fails, any partial read is undone */ -extern ssize_t strbuf_read (struct strbuf *,int fd,ssize_t hint); -#endif /* __NDCTL_STRBUF_H */
base-commit: a3d56f0ca5679b7c78090c1a8b0b9f1f9901e5e0
Signature · 1 line
2.37.3
Alison Schofield
maintainerQuoted 7 lines · On Tue, Feb 11, 2025 at 07:40:18PM -0800, [email protected] wrote:
From: Alison Schofield <[email protected]>
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
sysbuf_read()and although that is fixable, the function is not used
^^^
strbuf_read()
Quoted 18 lines
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 14 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]
91677390f9e6("ndctl: import cli infrastructure from perf")Signed-off-by Alison Schofield <[email protected]>--- util/strbuf.c | 51 --------------------------------------------------- util/strbuf.h | 7 ------- 2 files changed, 58 deletions(-)
snip
Quoted 15 lines · On 2/11/25 8:40 PM, [email protected] wrote:
From: Alison Schofield <[email protected]>
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
sysbuf_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 14 years.
Quoted 6 lines
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]
91677390f9e6("ndctl: import cli infrastructure from perf")Signed-off-by Alison Schofield <[email protected]>
Quoted 103 lines
--- util/strbuf.c | 51 --------------------------------------------------- util/strbuf.h | 7 ------- 2 files changed, 58 deletions(-)util/strbuf.c +0
-51@@ -60,30 +60,6 @@ void strbuf_grow(struct strbuf *sb, size_t extra)ALLOC_GROW (sb->buf, sb->len + extra +1 , sb->alloc); } -static void strbuf_splice (struct strbuf *sb,size_t pos,size_t len, -const void *data,size_t dlen) -{ -if (pos + len < pos) -die ("you want to use way too much memory" ); -if (pos > sb->len) -die ("`pos' is too far after the end of the buffer" ); -if (pos + len > sb->len) -die ("`pos + len' is too far after the end of the buffer" ); - -if (dlen >= len) -strbuf_grow (sb, dlen - len); -memmove (sb->buf + pos + dlen, - sb->buf + pos + len, - sb->len - pos - len); -memcpy (sb->buf + pos, data, dlen); -strbuf_setlen (sb, sb->len + dlen - len); -} - -void strbuf_remove (struct strbuf *sb,size_t pos,size_t len) -{ -strbuf_splice (sb, pos, len,NULL ,0 ); -} -void strbuf_add (struct strbuf *sb,const void *data,size_t len) {strbuf_grow (sb, len);@@ -114,30 +90,3 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...) }strbuf_setlen (sb, sb->len + len); } - -ssize_t strbuf_read (struct strbuf *sb,int fd,ssize_t hint) -{ -size_t oldlen = sb->len; -size_t oldalloc = sb->alloc; - -strbuf_grow (sb, hint ? hint :8192 ); -for (;;) { -ssize_t cnt; - - cnt =read (fd, sb->buf + sb->len, sb->alloc - sb->len -1 ); -if (cnt <0 ) { -if (oldalloc ==0 ) -strbuf_release (sb); -else -strbuf_setlen (sb, oldlen); -return -1 ; - } -if (!cnt) -break ; - sb->len += cnt; -strbuf_grow (sb,8192 ); - } - - sb->buf[sb->len] ='\0' ; -return sb->len - oldlen; -}util/strbuf.h +0
-7@@ -56,7 +56,6 @@ struct strbuf {#define STRBUF_INIT { 0, 0, strbuf_slopbuf }/*----- strbuf life cycle -----*/ -extern void strbuf_init (struct strbuf *buf,ssize_t hint);extern void strbuf_release (struct strbuf *);extern char *strbuf_detach (struct strbuf *,size_t *);@@ -81,9 +80,6 @@ static inline void strbuf_addch(struct strbuf *sb, int c) { sb->buf[sb->len++] = c; sb->buf[sb->len] ='\0' ; } - -extern void strbuf_remove (struct strbuf *,size_t pos,size_t len); -extern void strbuf_add (struct strbuf *,const void *,size_t );static inline void strbuf_addstr (struct strbuf *sb,const char *s) {strbuf_add (sb, s,strlen (s));@@ -92,7 +88,4 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s) { __attribute__((format (printf,2 ,3 )))extern void strbuf_addf (struct strbuf *sb,const char *fmt, ...); -/* XXX: if read fails, any partial read is undone */ -extern ssize_t strbuf_read (struct strbuf *,int fd,ssize_t hint); -#endif /* __NDCTL_STRBUF_H */ base-commit:
a3d56f0ca5679b7c78090c1a8b0b9f1f9901e5e0