← Commit list

1ecee6178

Denys Vlasenko
Denys Vlasenko
2026-02-24
SUCCESS Duration: 145s

Subject

netstat: fix breakage due to last commit

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
gcc -Wp,-MD,applets/.usage.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer      -Iinclude -Iinclude -o applets/usage applets/usage.c

Build Log

(log yok)

Commit Diff GitHub →

include/libbb.h+1 -1
@@ -911,7 +911,7 @@ char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa) FAST_FUNC RETU
/* inet_[ap]ton on steroids */
char* xmalloc_sockaddr2dotted(const struct sockaddr *sa) FAST_FUNC RETURNS_MALLOC;
char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa) FAST_FUNC RETURNS_MALLOC;
-// NB: unlike getservbyport, port paramenter is NOT in network order
+// NB: unlike getservbyport, port parameter is NOT in network order
#define getservbyport dont_use_getservbyport_uses_global_buffer
char* bb_get_servname_by_port(char **p_etc_services, int port, const char *type) FAST_FUNC RETURNS_MALLOC;
// "old" (ipv4 only) API
libbb/bb_get_servname_by_port.c+16 -6
@@ -9,6 +9,12 @@
//kbuild:lib-$(CONFIG_PSCAN) += bb_get_servname_by_port.o
#include "libbb.h"
+//Rationale for exising:
+//#define getservbyport dont_use_getservbyport_uses_global_buffer
+//(for example: -280 bytes on musl, x86-32)
+//TODO:
+//avoid getservbyname() as well
+
char* FAST_FUNC bb_get_servname_by_port(char **p_etc_services, int port, const char *type)
{
char *sp;
@@ -22,23 +28,27 @@ char* FAST_FUNC bb_get_servname_by_port(char **p_etc_services, int port, const c
*p_etc_services = sp;
}
while (*sp) {
- const char *portstr, *sp_end;
+ const char *pnstr, *sp_end;
char *end;
- unsigned portnum;
+ unsigned n;
sp = skip_whitespace(sp);
if (*sp == '#')
goto next;
sp_end = skip_non_whitespace(sp);
- portstr = skip_whitespace(sp_end);
- portnum = bb_strtou(portstr, &end, 10);
- if (portnum != port || *end != '/')
+ pnstr = skip_whitespace(sp_end);
+ n = bb_strtou(pnstr, &end, 10);
+ if (n != port || *end != '/')
goto next;
if (type) {
end++;
end = is_prefixed_with(end, type);
- if (!end || !(isspace(*end) || *end == '\0'))
+ if (!end
+ || !(isspace(*end) || *end == '\0'
+ || *end == '#') // glibc treats "http 80/tcp#COMMENT" as valid
+ ) {
goto next;
+ }
}
return auto_string(xstrndup(sp, sp_end - sp));
next:
networking/netstat.c+2 -2
@@ -176,7 +176,7 @@ struct globals {
smallint prg_cache_loaded;
struct prg_node *prg_hash[PRG_HASH_SIZE];
#endif
- char **p_etc_services;
+ char *p_etc_services;
#if ENABLE_FEATURE_NETSTAT_PRG
const char *progname_banner;
#endif
@@ -382,7 +382,7 @@ static const char *get_sname(int port, const char *proto, int numeric)
if (port == 0)
return "*";
if (!numeric) {
- const char *se = bb_get_servname_by_port(G.p_etc_services, port, proto);
+ const char *se = bb_get_servname_by_port(&G.p_etc_services, port, proto);
if (se)
return se;
}