Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
net-tools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
net-tools
Commits
a753a904
Commit
a753a904
authored
Aug 30, 2013
by
Bernd Eckenfels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/util.c: introduxe xstrdup which catches NULL and use it in all places
parent
e8510bc4
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
19 additions
and
9 deletions
+19
-9
lib/af.c
lib/af.c
+1
-2
lib/inet.c
lib/inet.c
+3
-3
lib/nstrcmp.c
lib/nstrcmp.c
+2
-2
lib/proc.c
lib/proc.c
+2
-1
lib/util.c
lib/util.c
+9
-0
lib/util.h
lib/util.h
+1
-0
netstat.c
netstat.c
+1
-1
No files found.
lib/af.c
View file @
a753a904
...
@@ -208,8 +208,7 @@ void aftrans_def(char *tool, char *argv0, char *dflt)
...
@@ -208,8 +208,7 @@ void aftrans_def(char *tool, char *argv0, char *dflt)
else
else
tmp
++
;
tmp
++
;
if
(
!
(
buf
=
strdup
(
tmp
)))
buf
=
xstrdup
(
tmp
);
return
;
if
(
strlen
(
tool
)
>=
strlen
(
tmp
))
{
if
(
strlen
(
tool
)
>=
strlen
(
tmp
))
{
free
(
buf
);
free
(
buf
);
...
...
lib/inet.c
View file @
a753a904
...
@@ -224,7 +224,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
...
@@ -224,7 +224,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
pn
->
addr
=
*
sin
;
pn
->
addr
=
*
sin
;
pn
->
next
=
INET_nn
;
pn
->
next
=
INET_nn
;
pn
->
host
=
host
;
pn
->
host
=
host
;
pn
->
name
=
strdup
(
name
);
pn
->
name
=
x
strdup
(
name
);
INET_nn
=
pn
;
INET_nn
=
pn
;
return
(
0
);
return
(
0
);
...
@@ -395,7 +395,7 @@ static int read_services(void)
...
@@ -395,7 +395,7 @@ static int read_services(void)
while
((
se
=
getservent
()))
{
while
((
se
=
getservent
()))
{
/* Allocate a service entry. */
/* Allocate a service entry. */
item
=
(
struct
service
*
)
xmalloc
(
sizeof
(
struct
service
));
item
=
(
struct
service
*
)
xmalloc
(
sizeof
(
struct
service
));
item
->
name
=
strdup
(
se
->
s_name
);
item
->
name
=
x
strdup
(
se
->
s_name
);
item
->
number
=
se
->
s_port
;
item
->
number
=
se
->
s_port
;
/* Fill it in. */
/* Fill it in. */
...
@@ -415,7 +415,7 @@ static int read_services(void)
...
@@ -415,7 +415,7 @@ static int read_services(void)
while
((
pe
=
getprotoent
()))
{
while
((
pe
=
getprotoent
()))
{
/* Allocate a service entry. */
/* Allocate a service entry. */
item
=
(
struct
service
*
)
xmalloc
(
sizeof
(
struct
service
));
item
=
(
struct
service
*
)
xmalloc
(
sizeof
(
struct
service
));
item
->
name
=
strdup
(
pe
->
p_name
);
item
->
name
=
x
strdup
(
pe
->
p_name
);
item
->
number
=
htons
(
pe
->
p_proto
);
item
->
number
=
htons
(
pe
->
p_proto
);
add2list
(
&
raw_name
,
item
);
add2list
(
&
raw_name
,
item
);
}
}
...
...
lib/nstrcmp.c
View file @
a753a904
...
@@ -45,8 +45,8 @@ int rindex_nondigit(char *name)
...
@@ -45,8 +45,8 @@ int rindex_nondigit(char *name)
/* like strcmp(), but knows about numbers and ':' alias suffix */
/* like strcmp(), but knows about numbers and ':' alias suffix */
int
nstrcmp
(
const
char
*
ap
,
const
char
*
bp
)
int
nstrcmp
(
const
char
*
ap
,
const
char
*
bp
)
{
{
char
*
a
=
(
char
*
)
strdup
(
ap
);
char
*
a
=
x
strdup
(
ap
);
char
*
b
=
(
char
*
)
strdup
(
bp
);
char
*
b
=
x
strdup
(
bp
);
char
*
an
,
*
bn
;
char
*
an
,
*
bn
;
int
av
=
0
,
bv
=
0
;
int
av
=
0
,
bv
=
0
;
char
*
aalias
=
cutalias
(
a
);
char
*
aalias
=
cutalias
(
a
);
...
...
lib/proc.c
View file @
a753a904
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <ctype.h>
#include <ctype.h>
#include <unistd.h>
#include <unistd.h>
#include "util.h"
/* Caller must free return string. */
/* Caller must free return string. */
...
@@ -48,7 +49,7 @@ char *proc_gen_fmt(char *name, int more, FILE * fh,...)
...
@@ -48,7 +49,7 @@ char *proc_gen_fmt(char *name, int more, FILE * fh,...)
name
,
title
);
name
,
title
);
return
NULL
;
return
NULL
;
}
}
return
strdup
(
format
);
return
x
strdup
(
format
);
}
}
/*
/*
...
...
lib/util.c
View file @
a753a904
...
@@ -22,6 +22,15 @@ void *xmalloc(size_t sz)
...
@@ -22,6 +22,15 @@ void *xmalloc(size_t sz)
return
p
;
return
p
;
}
}
/* Like strdup, but oom() instead of NULL */
char
*
xstrdup
(
char
*
s
)
{
char
*
d
=
strdup
(
s
);
if
(
!
d
)
oom
();
return
d
;
}
void
*
xrealloc
(
void
*
oldp
,
size_t
sz
)
void
*
xrealloc
(
void
*
oldp
,
size_t
sz
)
{
{
void
*
p
=
realloc
(
oldp
,
sz
);
void
*
p
=
realloc
(
oldp
,
sz
);
...
...
lib/util.h
View file @
a753a904
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
void
*
xmalloc
(
size_t
sz
);
void
*
xmalloc
(
size_t
sz
);
void
*
xrealloc
(
void
*
p
,
size_t
sz
);
void
*
xrealloc
(
void
*
p
,
size_t
sz
);
char
*
xstrdup
(
char
*
src
);
#define new(p) ((p) = xmalloc(sizeof(*(p))))
#define new(p) ((p) = xmalloc(sizeof(*(p))))
...
...
netstat.c
View file @
a753a904
...
@@ -475,7 +475,7 @@ static void prg_cache_load(void)
...
@@ -475,7 +475,7 @@ static void prg_cache_load(void)
snprintf
(
finbuf
,
sizeof
(
finbuf
),
"%s/%s"
,
direproc
->
d_name
,
cmdlp
);
snprintf
(
finbuf
,
sizeof
(
finbuf
),
"%s/%s"
,
direproc
->
d_name
,
cmdlp
);
#if HAVE_SELINUX
#if HAVE_SELINUX
if
(
getpidcon
(
atoi
(
direproc
->
d_name
),
&
scon
)
==
-
1
)
{
if
(
getpidcon
(
atoi
(
direproc
->
d_name
),
&
scon
)
==
-
1
)
{
scon
=
strdup
(
"-"
);
scon
=
x
strdup
(
"-"
);
}
}
prg_cache_add
(
inode
,
finbuf
,
scon
);
prg_cache_add
(
inode
,
finbuf
,
scon
);
freecon
(
scon
);
freecon
(
scon
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment