[Lldb-commits] [lldb] r320242 - Change uses of strncpy in debugserver to strlcpy
Jason Molenda via lldb-commits
lldb-commits at lists.llvm.org
Fri Dec 8 19:37:09 PST 2017
Author: jmolenda
Date: Fri Dec 8 19:37:09 2017
New Revision: 320242
URL: http://llvm.org/viewvc/llvm-project?rev=320242&view=rev
Log:
Change uses of strncpy in debugserver to strlcpy
for better safety.
<rdar://problem/32906923>
Modified:
lldb/trunk/tools/debugserver/source/DNB.cpp
lldb/trunk/tools/debugserver/source/DNBRegisterInfo.cpp
lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp
lldb/trunk/tools/debugserver/source/RNBRemote.cpp
lldb/trunk/tools/debugserver/source/debugserver.cpp
Modified: lldb/trunk/tools/debugserver/source/DNB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.cpp?rev=320242&r1=320241&r2=320242&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNB.cpp (original)
+++ lldb/trunk/tools/debugserver/source/DNB.cpp Fri Dec 8 19:37:09 2017
@@ -368,7 +368,7 @@ nub_process_t DNBProcessLaunch(
if (launch_err.Fail()) {
const char *launch_err_str = launch_err.AsString();
if (launch_err_str) {
- strncpy(err_str, launch_err_str, err_len - 1);
+ strlcpy(err_str, launch_err_str, err_len - 1);
err_str[err_len - 1] =
'\0'; // Make sure the error string is terminated
}
@@ -1698,7 +1698,7 @@ nub_bool_t DNBResolveExecutablePath(cons
if (realpath(path, max_path)) {
// Found the path relatively...
- ::strncpy(resolved_path, max_path, resolved_path_size);
+ ::strlcpy(resolved_path, max_path, resolved_path_size);
return strlen(resolved_path) + 1 < resolved_path_size;
} else {
// Not a relative path, check the PATH environment variable if the
@@ -1722,7 +1722,7 @@ nub_bool_t DNBResolveExecutablePath(cons
result += path;
struct stat s;
if (stat(result.c_str(), &s) == 0) {
- ::strncpy(resolved_path, result.c_str(), resolved_path_size);
+ ::strlcpy(resolved_path, result.c_str(), resolved_path_size);
return result.size() + 1 < resolved_path_size;
}
}
Modified: lldb/trunk/tools/debugserver/source/DNBRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNBRegisterInfo.cpp?rev=320242&r1=320241&r2=320242&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNBRegisterInfo.cpp (original)
+++ lldb/trunk/tools/debugserver/source/DNBRegisterInfo.cpp Fri Dec 8 19:37:09 2017
@@ -35,7 +35,7 @@ bool DNBRegisterValueClass::IsValid() co
do { \
if (pos < end) { \
if (i > 0) { \
- strncpy(pos, ", ", end - pos); \
+ strlcpy(pos, ", ", end - pos); \
pos += 2; \
} \
} \
@@ -69,7 +69,7 @@ void DNBRegisterValueClass::Dump(const c
value.v_uint64[1]);
break;
default:
- strncpy(str, "0x", 3);
+ strlcpy(str, "0x", 3);
pos = str + 2;
for (uint32_t i = 0; i < info.size; ++i) {
if (pos < end)
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp?rev=320242&r1=320241&r2=320242&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Fri Dec 8 19:37:09 2017
@@ -164,15 +164,15 @@ const char *MachThread::GetBasicInfoAsSt
// size_t run_state_str_size = sizeof(run_state_str);
// switch (basicInfo.run_state)
// {
- // case TH_STATE_RUNNING: strncpy(run_state_str, "running",
+ // case TH_STATE_RUNNING: strlcpy(run_state_str, "running",
// run_state_str_size); break;
- // case TH_STATE_STOPPED: strncpy(run_state_str, "stopped",
+ // case TH_STATE_STOPPED: strlcpy(run_state_str, "stopped",
// run_state_str_size); break;
- // case TH_STATE_WAITING: strncpy(run_state_str, "waiting",
+ // case TH_STATE_WAITING: strlcpy(run_state_str, "waiting",
// run_state_str_size); break;
- // case TH_STATE_UNINTERRUPTIBLE: strncpy(run_state_str,
+ // case TH_STATE_UNINTERRUPTIBLE: strlcpy(run_state_str,
// "uninterruptible", run_state_str_size); break;
- // case TH_STATE_HALTED: strncpy(run_state_str, "halted",
+ // case TH_STATE_HALTED: strlcpy(run_state_str, "halted",
// run_state_str_size); break;
// default: snprintf(run_state_str,
// run_state_str_size, "%d", basicInfo.run_state); break; // ???
Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=320242&r1=320241&r2=320242&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Fri Dec 8 19:37:09 2017
@@ -2247,7 +2247,7 @@ rnb_err_t set_logging(const char *p) {
continue;
}
char *fn = (char *) alloca (c - p + 1);
- strncpy (fn, p, c - p);
+ strlcpy (fn, p, c - p);
fn[c - p] = '\0';
// A file name of "asl" is special and is another way to indicate
@@ -3049,7 +3049,7 @@ rnb_err_t RNBRemote::HandlePacket_last_s
// If we have an empty exit packet, lets fill one in to be safe.
if (!pid_exited_packet[0]) {
- strncpy(pid_exited_packet, "W00", sizeof(pid_exited_packet) - 1);
+ strlcpy(pid_exited_packet, "W00", sizeof(pid_exited_packet) - 1);
pid_exited_packet[sizeof(pid_exited_packet) - 1] = '\0';
}
Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver.cpp?rev=320242&r1=320241&r2=320242&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/debugserver.cpp (original)
+++ lldb/trunk/tools/debugserver/source/debugserver.cpp Fri Dec 8 19:37:09 2017
@@ -232,7 +232,7 @@ RNBRunLoopMode RNBRunLoopLaunchInferior(
// were given and hope for the best
if (!DNBResolveExecutablePath(inferior_argv[0], resolved_path,
sizeof(resolved_path)))
- ::strncpy(resolved_path, inferior_argv[0], sizeof(resolved_path));
+ ::strlcpy(resolved_path, inferior_argv[0], sizeof(resolved_path));
char launch_err_str[PATH_MAX];
launch_err_str[0] = '\0';
@@ -676,7 +676,7 @@ static void PortWasBoundCallbackUnixSock
}
saddr_un.sun_family = AF_UNIX;
- ::strncpy(saddr_un.sun_path, unix_socket_name,
+ ::strlcpy(saddr_un.sun_path, unix_socket_name,
sizeof(saddr_un.sun_path) - 1);
saddr_un.sun_path[sizeof(saddr_un.sun_path) - 1] = '\0';
saddr_un.sun_len = SUN_LEN(&saddr_un);
@@ -1366,7 +1366,7 @@ int main(int argc, char *argv[]) {
DNBLogDebug("host = '%s' port = %i", host.c_str(), port);
} else if (argv[0][0] == '/') {
port = INT32_MAX;
- strncpy(str, argv[0], sizeof(str));
+ strlcpy(str, argv[0], sizeof(str));
} else {
show_usage_and_exit(2);
}
More information about the lldb-commits
mailing list