Skip to content

Commit

Permalink
Fix snprintf sizeof() to match argument exactly
Browse files Browse the repository at this point in the history
4/5 based on a review comment by seb, 1 more caught by grep
  • Loading branch information
jepler committed Aug 20, 2022
1 parent ea48c94 commit 7b58951
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/emc/task/emctask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int emcTaskInit()
// set the user_defined_fmt string with dirname
// note the %%02d means 2 digits after the M code
// and we need two % to get the literal %
ret = snprintf(user_defined_fmt[dct], sizeof(user_defined_fmt[0]),
ret = snprintf(user_defined_fmt[dct], sizeof(user_defined_fmt[dct]),
"%s/M1%%02d", expanddir); // update global
if(ret >= sizeof(user_defined_fmt[0])){
return -EMSGSIZE; // name truncated
Expand Down
4 changes: 2 additions & 2 deletions src/emc/usr_intf/emcrsh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2939,8 +2939,8 @@ int main(int argc, char *argv[])
while((opt = getopt_long(argc, argv, "he:n:p:s:w:d:", longopts, NULL)) != - 1) {
switch(opt) {
case 'h': usage(argv[0]); exit(1);
case 'e': snprintf(enablePWD, sizeof(defaultPath), "%s", optarg); break;
case 'n': snprintf(serverName, sizeof(defaultPath), "%s", optarg); break;
case 'e': snprintf(enablePWD, sizeof(enablePWD), "%s", optarg); break;
case 'n': snprintf(serverName, sizeof(serverName), "%s", optarg); break;
case 'p': sscanf(optarg, "%d", &port); break;
case 's': sscanf(optarg, "%d", &maxSessions); break;
case 'w': snprintf(pwd, sizeof(pwd), "%s", optarg); break;
Expand Down
4 changes: 2 additions & 2 deletions src/emc/usr_intf/schedrmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1254,8 +1254,8 @@ int main(int argc, char *argv[])
// process local command line args
while((opt = getopt_long(argc, argv, "e:n:p:s:w:", longopts, NULL)) != -1) {
switch(opt) {
case 'e': snprintf(enablePWD, sizeof(defaultPath), "%s", optarg); break;
case 'n': snprintf(serverName, sizeof(defaultPath), "%s", optarg); break;
case 'e': snprintf(enablePWD, sizeof(enablePWD), "%s", optarg); break;
case 'n': snprintf(serverName, sizeof(serverName), "%s", optarg); break;
case 'p': sscanf(optarg, "%d", &port); break;
case 's': sscanf(optarg, "%d", &maxSessions); break;
case 'w': snprintf(pwd, sizeof(pwd), "%s", optarg); break;
Expand Down

0 comments on commit 7b58951

Please sign in to comment.