Skip to content

Commit c5ce59e

Browse files
committed
emclcd etc: fix overwriting errors into truncating ones
1 parent 5f74e9f commit c5ce59e

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/emc/usr_intf/emclcd.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,9 +1705,9 @@ int main(int argc, char *argv[])
17051705
while((opt = getopt_long(argc, argv, "p:d:a", longopts, NULL)) != -1) {
17061706
switch(opt) {
17071707
case 'a': autoStart = 1; break;
1708-
case 'd': strncpy(driver, optarg, strlen(optarg) + 1); break;
1708+
case 'd': snprintf(driver, sizeof(driver), "%s", optarg); break;
17091709
case 'p': sscanf(optarg, "%d", &port); break;
1710-
case 's': strncpy(server, optarg, strlen(optarg) + 1); break;
1710+
case 's': snprintf(server, sizeof(server), "%s", optarg); break;
17111711
case 'w': sscanf(optarg, "%f", &delay); break;
17121712
}
17131713
}

src/emc/usr_intf/emcrsh.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,12 +2939,12 @@ int main(int argc, char *argv[])
29392939
while((opt = getopt_long(argc, argv, "he:n:p:s:w:d:", longopts, NULL)) != - 1) {
29402940
switch(opt) {
29412941
case 'h': usage(argv[0]); exit(1);
2942-
case 'e': strncpy(enablePWD, optarg, strlen(optarg) + 1); break;
2943-
case 'n': strncpy(serverName, optarg, strlen(optarg) + 1); break;
2942+
case 'e': snprintf(enablePWD, sizeof(defaultPath), "%s", optarg); break;
2943+
case 'n': snprintf(serverName, sizeof(defaultPath), "%s", optarg); break;
29442944
case 'p': sscanf(optarg, "%d", &port); break;
29452945
case 's': sscanf(optarg, "%d", &maxSessions); break;
2946-
case 'w': strncpy(pwd, optarg, strlen(optarg) + 1); break;
2947-
case 'd': strncpy(defaultPath, optarg, strlen(optarg) + 1);
2946+
case 'w': snprintf(pwd, sizeof(pwd), "%s", optarg); break;
2947+
case 'd': snprintf(defaultPath, sizeof(defaultPath), "%s", optarg); break;
29482948
}
29492949
}
29502950

src/emc/usr_intf/schedrmt.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,12 +1254,12 @@ int main(int argc, char *argv[])
12541254
// process local command line args
12551255
while((opt = getopt_long(argc, argv, "e:n:p:s:w:", longopts, NULL)) != -1) {
12561256
switch(opt) {
1257-
case 'e': strncpy(enablePWD, optarg, strlen(optarg) + 1); break;
1258-
case 'n': strncpy(serverName, optarg, strlen(optarg) + 1); break;
1257+
case 'e': snprintf(enablePWD, sizeof(defaultPath), "%s", optarg); break;
1258+
case 'n': snprintf(serverName, sizeof(defaultPath), "%s", optarg); break;
12591259
case 'p': sscanf(optarg, "%d", &port); break;
12601260
case 's': sscanf(optarg, "%d", &maxSessions); break;
1261-
case 'w': strncpy(pwd, optarg, strlen(optarg) + 1); break;
1262-
case 'd': strncpy(defaultPath, optarg, strlen(optarg) + 1);
1261+
case 'w': snprintf(pwd, sizeof(pwd), "%s", optarg); break;
1262+
case 'd': snprintf(defaultPath, sizeof(defaultPath), "%s", optarg); break;
12631263
}
12641264
}
12651265

0 commit comments

Comments
 (0)