Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nx-libs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dimbor
nx-libs
Commits
6e98e35c
Commit
6e98e35c
authored
Dec 28, 2017
by
Ulrich Sibiller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nxcomp: drop strncpy in favour of snprintf
with very few exceptions which require careful thinking ;-)
parent
9e8bd2e1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
44 deletions
+33
-44
Auth.cpp
nxcomp/src/Auth.cpp
+4
-10
Children.cpp
nxcomp/src/Children.cpp
+9
-10
Loop.cpp
nxcomp/src/Loop.cpp
+20
-24
No files found.
nxcomp/src/Auth.cpp
View file @
6e98e35c
...
...
@@ -212,16 +212,14 @@ int Auth::getCookie()
if
(
environment
!=
NULL
&&
*
environment
!=
'\0'
)
{
s
trncpy
(
file_
,
environment
,
DEFAULT_STRING_LIMIT
-
1
);
s
nprintf
(
file_
,
DEFAULT_STRING_LIMIT
,
"%s"
,
environment
);
}
else
{
snprintf
(
file_
,
DEFAULT_STRING_LIMIT
-
1
,
"%s/.Xauthority"
,
snprintf
(
file_
,
DEFAULT_STRING_LIMIT
,
"%s/.Xauthority"
,
control
->
HomePath
);
}
*
(
file_
+
DEFAULT_STRING_LIMIT
-
1
)
=
'\0'
;
#ifdef TEST
*
logofs
<<
"Auth: Using X authorization file '"
<<
file_
<<
"'.
\n
"
<<
logofs_flush
;
...
...
@@ -242,18 +240,14 @@ int Auth::getCookie()
#if defined(__CYGWIN32__)
snprintf
(
command
,
DEFAULT_STRING_LIMIT
-
1
,
snprintf
(
command
,
DEFAULT_STRING_LIMIT
,
"%s/bin/nxauth"
,
control
->
SystemPath
);
*
(
command
+
DEFAULT_STRING_LIMIT
-
1
)
=
'\0'
;
#elif defined(__APPLE__)
snprintf
(
command
,
DEFAULT_STRING_LIMIT
-
1
,
snprintf
(
command
,
DEFAULT_STRING_LIMIT
,
"%s/nxauth"
,
control
->
SystemPath
);
*
(
command
+
DEFAULT_STRING_LIMIT
-
1
)
=
'\0'
;
#else
strcpy
(
command
,
"xauth"
);
...
...
nxcomp/src/Children.cpp
View file @
6e98e35c
...
...
@@ -275,12 +275,14 @@ int NXTransDialog(const char *caption, const char *message,
#ifdef __APPLE__
// FIXME: missing length limitation!
strcat
(
newPath
,
"/Applications/NX Client for OSX.app/Contents/MacOS:"
);
#endif
#ifdef __CYGWIN32__
// FIXME: missing length limitation!
strcat
(
newPath
,
".:"
);
#endif
...
...
@@ -289,9 +291,8 @@ int NXTransDialog(const char *caption, const char *message,
char
*
oldPath
=
getenv
(
"PATH"
);
strncpy
(
newPath
+
newLength
,
oldPath
,
DEFAULT_STRING_LIMIT
-
newLength
-
1
);
newPath
[
DEFAULT_STRING_LIMIT
-
1
]
=
'\0'
;
// FIXME: check if strncat would be better here
snprintf
(
newPath
+
newLength
,
DEFAULT_STRING_LIMIT
-
newLength
,
"%s"
,
oldPath
);
#ifdef WARNING
*
logofs
<<
"NXTransDialog: WARNING! Trying with path '"
...
...
@@ -427,17 +428,13 @@ int NXTransClient(const char* display)
#ifdef __sun
snprintf
(
newDisplay
,
DISPLAY_LENGTH_LIMIT
-
1
,
"DISPLAY=%s"
,
display
);
newDisplay
[
DISPLAY_LENGTH_LIMIT
-
1
]
=
'\0'
;
snprintf
(
newDisplay
,
DISPLAY_LENGTH_LIMIT
,
"DISPLAY=%s"
,
display
);
putenv
(
newDisplay
);
#else
strncpy
(
newDisplay
,
display
,
DISPLAY_LENGTH_LIMIT
-
1
);
newDisplay
[
DISPLAY_LENGTH_LIMIT
-
1
]
=
'\0'
;
snprintf
(
newDisplay
,
DISPLAY_LENGTH_LIMIT
,
"%s"
,
display
);
setenv
(
"DISPLAY"
,
newDisplay
,
1
);
...
...
@@ -467,6 +464,7 @@ int NXTransClient(const char* display)
if
(
i
==
0
)
{
// FIXME: code dpulication: this whole block is duplicated in NXTransDialog
strcpy
(
command
,
"nxclient"
);
char
newPath
[
DEFAULT_STRING_LIMIT
];
...
...
@@ -489,7 +487,8 @@ int NXTransClient(const char* display)
char
*
oldPath
=
getenv
(
"PATH"
);
strncpy
(
newPath
+
newLength
,
oldPath
,
DEFAULT_STRING_LIMIT
-
newLength
-
1
);
// FIXME: check if strncat would be better here
snprintf
(
newPath
+
newLength
,
DEFAULT_STRING_LIMIT
-
newLength
,
"%s"
,
oldPath
);
newPath
[
DEFAULT_STRING_LIMIT
-
1
]
=
'\0'
;
...
...
nxcomp/src/Loop.cpp
View file @
6e98e35c
...
...
@@ -4044,7 +4044,7 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
if
(
useLaunchdSocket
==
1
)
{
s
trncpy
(
unixSocketName
,
displayHost
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
unixSocketName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
displayHost
);
}
#endif
...
...
@@ -7923,11 +7923,11 @@ int ParseEnvironmentOptions(const char *env, int force)
if
(
strcasecmp
(
name
,
"options"
)
==
0
)
{
s
trncpy
(
fileOptions
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
fileOptions
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"display"
)
==
0
)
{
s
trncpy
(
displayHost
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
displayHost
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"link"
)
==
0
)
{
...
...
@@ -7983,7 +7983,7 @@ int ParseEnvironmentOptions(const char *env, int force)
}
else
{
s
trncpy
(
sessionType
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
sessionType
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
}
...
...
@@ -8036,7 +8036,7 @@ int ParseEnvironmentOptions(const char *env, int force)
return
-
1
;
}
s
trncpy
(
acceptHost
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
acceptHost
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"connect"
)
==
0
)
{
...
...
@@ -8074,7 +8074,7 @@ int ParseEnvironmentOptions(const char *env, int force)
}
else
if
(
strcasecmp
(
name
,
"session"
)
==
0
)
{
s
trncpy
(
sessionFileName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
sessionFileName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"errors"
)
==
0
)
{
...
...
@@ -8085,27 +8085,27 @@ int ParseEnvironmentOptions(const char *env, int force)
// the same name.
//
s
trncpy
(
errorsFileName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
errorsFileName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"root"
)
==
0
)
{
s
trncpy
(
rootDir
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
rootDir
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"id"
)
==
0
)
{
s
trncpy
(
sessionId
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
sessionId
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"stats"
)
==
0
)
{
control
->
EnableStatistics
=
1
;
s
trncpy
(
statsFileName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
statsFileName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"cookie"
)
==
0
)
{
LowercaseArg
(
"local"
,
name
,
value
);
s
trncpy
(
authCookie
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
authCookie
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"nodelay"
)
==
0
)
{
...
...
@@ -8334,7 +8334,7 @@ int ParseEnvironmentOptions(const char *env, int force)
}
else
if
(
strcasecmp
(
name
,
"font"
)
==
0
)
{
s
trncpy
(
fontPort
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
fontPort
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"slave"
)
==
0
)
{
...
...
@@ -8439,7 +8439,7 @@ int ParseEnvironmentOptions(const char *env, int force)
}
else
if
(
strcasecmp
(
name
,
"product"
)
==
0
)
{
s
trncpy
(
productName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
productName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
else
if
(
strcasecmp
(
name
,
"rootless"
)
==
0
||
strcasecmp
(
name
,
"geometry"
)
==
0
||
...
...
@@ -8529,7 +8529,7 @@ int ParseEnvironmentOptions(const char *env, int force)
if
(
*
optionsFileName
==
'\0'
)
{
s
trncpy
(
optionsFileName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
optionsFileName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
nxinfo
<<
"Loop: Assuming name of options file '"
<<
optionsFileName
<<
"'.
\n
"
...
...
@@ -9249,7 +9249,7 @@ int ParseRemoteOptions(char *opts)
}
else
{
s
trncpy
(
sessionType
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
sessionType
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
...
...
@@ -12719,6 +12719,7 @@ int ParseHostOption(const char *opt, char *host, long &port)
char
newHost
[
DEFAULT_STRING_LENGTH
]
=
{
0
};
// opt cannot be longer than DEFAULT_STRING_LENGTH, this is checked above
strncpy
(
newHost
,
opt
,
strlen
(
opt
)
-
strlen
(
separator
));
*
(
newHost
+
strlen
(
opt
)
-
strlen
(
separator
))
=
'\0'
;
...
...
@@ -13491,10 +13492,8 @@ int ParseArg(const char *type, const char *name, const char *value)
char
*
string
=
new
char
[
strlen
(
value
)];
strncpy
(
string
,
value
,
strlen
(
value
)
-
1
);
*
(
string
+
(
strlen
(
value
)
-
1
))
=
'\0'
;
// copy value but cut off the last character
snprintf
(
string
,
strlen
(
value
),
"%s"
,
value
);
nxinfo
<<
"Loop: Parsing integer option '"
<<
name
<<
"' from string '"
<<
string
<<
"' with base set to "
;
...
...
@@ -13512,18 +13511,15 @@ int ParseArg(const char *type, const char *name, const char *value)
nxinfo_append
<<
".
\n
"
<<
std
::
flush
;
double
result
=
atof
(
string
)
*
base
;
delete
[]
string
;
if
(
result
<
0
||
result
>
(((
unsigned
)
-
1
)
>>
1
))
{
delete
[]
string
;
return
-
1
;
}
delete
[]
string
;
nxinfo
<<
"Loop: Integer option parsed to '"
<<
(
int
)
result
<<
"'.
\n
"
<<
std
::
flush
;
...
...
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