Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Slurm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tud-zih-energy
Slurm
Commits
f9687bbc
Commit
f9687bbc
authored
7 years ago
by
Tim Wickberg
Browse files
Options
Downloads
Patches
Plain Diff
Replace strncpy with strlcpy and simplify string terminations.
parent
2acb052c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/api/pmi.c
+14
-17
14 additions, 17 deletions
src/api/pmi.c
with
14 additions
and
17 deletions
src/api/pmi.c
+
14
−
17
View file @
f9687bbc
...
@@ -97,6 +97,7 @@
...
@@ -97,6 +97,7 @@
#include
"src/api/slurm_pmi.h"
#include
"src/api/slurm_pmi.h"
#include
"src/common/macros.h"
#include
"src/common/macros.h"
#include
"src/common/strlcpy.h"
#include
"src/slurmd/slurmstepd/slurmstepd_job.h"
#include
"src/slurmd/slurmstepd/slurmstepd_job.h"
#define KVS_STATE_LOCAL 0
#define KVS_STATE_LOCAL 0
...
@@ -899,7 +900,7 @@ static void _init_kvs( char kvsname[] )
...
@@ -899,7 +900,7 @@ static void _init_kvs( char kvsname[] )
kvs_recs
[
i
].
kvs_name
=
malloc
(
PMI_MAX_KVSNAME_LEN
);
kvs_recs
[
i
].
kvs_name
=
malloc
(
PMI_MAX_KVSNAME_LEN
);
if
(
!
kvs_recs
[
i
].
kvs_name
)
if
(
!
kvs_recs
[
i
].
kvs_name
)
pmi_nomem_error
(
__FILE__
,
__LINE__
,
"_init_kvs"
);
pmi_nomem_error
(
__FILE__
,
__LINE__
,
"_init_kvs"
);
str
n
cpy
(
kvs_recs
[
i
].
kvs_name
,
kvsname
,
PMI_MAX_KVSNAME_LEN
);
str
l
cpy
(
kvs_recs
[
i
].
kvs_name
,
kvsname
,
PMI_MAX_KVSNAME_LEN
);
kvs_recs
[
i
].
kvs_state
=
KVS_STATE_LOCAL
;
kvs_recs
[
i
].
kvs_state
=
KVS_STATE_LOCAL
;
kvs_recs
[
i
].
kvs_cnt
=
0
;
kvs_recs
[
i
].
kvs_cnt
=
0
;
kvs_recs
[
i
].
kvs_inx
=
0
;
kvs_recs
[
i
].
kvs_inx
=
0
;
...
@@ -1154,7 +1155,7 @@ static int _kvs_put( const char kvsname[], const char key[], const char value[],
...
@@ -1154,7 +1155,7 @@ static int _kvs_put( const char kvsname[], const char key[], const char value[],
rc
=
PMI_FAIL
;
rc
=
PMI_FAIL
;
}
else
{
}
else
{
rc
=
PMI_SUCCESS
;
rc
=
PMI_SUCCESS
;
str
n
cpy
(
kvs_recs
[
i
].
kvs_values
[
j
],
value
,
str
l
cpy
(
kvs_recs
[
i
].
kvs_values
[
j
],
value
,
PMI_MAX_VAL_LEN
);
PMI_MAX_VAL_LEN
);
}
}
goto
fini
;
goto
fini
;
...
@@ -1188,9 +1189,9 @@ no_dup:
...
@@ -1188,9 +1189,9 @@ no_dup:
rc
=
PMI_FAIL
;
rc
=
PMI_FAIL
;
}
else
{
}
else
{
rc
=
PMI_SUCCESS
;
rc
=
PMI_SUCCESS
;
str
n
cpy
(
kvs_recs
[
i
].
kvs_values
[
j
],
value
,
str
l
cpy
(
kvs_recs
[
i
].
kvs_values
[
j
],
value
,
PMI_MAX_VAL_LEN
);
PMI_MAX_VAL_LEN
);
str
n
cpy
(
kvs_recs
[
i
].
kvs_keys
[
j
],
key
,
PMI_MAX_KEY_LEN
);
str
l
cpy
(
kvs_recs
[
i
].
kvs_keys
[
j
],
key
,
PMI_MAX_KEY_LEN
);
}
}
goto
fini
;
goto
fini
;
}
}
...
@@ -1378,7 +1379,7 @@ int PMI_KVS_Get( const char kvsname[], const char key[], char value[], int lengt
...
@@ -1378,7 +1379,7 @@ int PMI_KVS_Get( const char kvsname[], const char key[], char value[], int lengt
if
(
strlen
(
kvs_recs
[
i
].
kvs_values
[
j
])
>
(
length
-
1
))
if
(
strlen
(
kvs_recs
[
i
].
kvs_values
[
j
])
>
(
length
-
1
))
rc
=
PMI_ERR_INVALID_LENGTH
;
rc
=
PMI_ERR_INVALID_LENGTH
;
else
{
else
{
str
n
cpy
(
value
,
kvs_recs
[
i
].
kvs_values
[
j
],
str
l
cpy
(
value
,
kvs_recs
[
i
].
kvs_values
[
j
],
length
);
length
);
rc
=
PMI_SUCCESS
;
rc
=
PMI_SUCCESS
;
}
}
...
@@ -1461,8 +1462,8 @@ int PMI_KVS_Iter_first(const char kvsname[], char key[], int key_len, char val[]
...
@@ -1461,8 +1462,8 @@ int PMI_KVS_Iter_first(const char kvsname[], char key[], int key_len, char val[]
if
(
kvs_recs
[
i
].
kvs_key_states
[
j
]
==
KVS_KEY_STATE_DISABLED
)
if
(
kvs_recs
[
i
].
kvs_key_states
[
j
]
==
KVS_KEY_STATE_DISABLED
)
continue
;
continue
;
str
n
cpy
(
key
,
kvs_recs
[
i
].
kvs_keys
[
j
],
key_len
);
str
l
cpy
(
key
,
kvs_recs
[
i
].
kvs_keys
[
j
],
key_len
);
str
n
cpy
(
val
,
kvs_recs
[
i
].
kvs_values
[
j
],
val_len
);
str
l
cpy
(
val
,
kvs_recs
[
i
].
kvs_values
[
j
],
val_len
);
kvs_recs
[
i
].
kvs_inx
=
j
;
kvs_recs
[
i
].
kvs_inx
=
j
;
rc
=
PMI_SUCCESS
;
rc
=
PMI_SUCCESS
;
goto
fini
;
goto
fini
;
...
@@ -1539,8 +1540,8 @@ int PMI_KVS_Iter_next(const char kvsname[], char key[], int key_len,
...
@@ -1539,8 +1540,8 @@ int PMI_KVS_Iter_next(const char kvsname[], char key[], int key_len,
if
(
kvs_recs
[
i
].
kvs_key_states
[
j
]
==
KVS_KEY_STATE_DISABLED
)
if
(
kvs_recs
[
i
].
kvs_key_states
[
j
]
==
KVS_KEY_STATE_DISABLED
)
continue
;
continue
;
str
n
cpy
(
key
,
kvs_recs
[
i
].
kvs_keys
[
j
],
key_len
);
str
l
cpy
(
key
,
kvs_recs
[
i
].
kvs_keys
[
j
],
key_len
);
str
n
cpy
(
val
,
kvs_recs
[
i
].
kvs_values
[
j
],
val_len
);
str
l
cpy
(
val
,
kvs_recs
[
i
].
kvs_values
[
j
],
val_len
);
kvs_recs
[
i
].
kvs_inx
=
j
;
kvs_recs
[
i
].
kvs_inx
=
j
;
rc
=
PMI_SUCCESS
;
rc
=
PMI_SUCCESS
;
goto
fini
;
goto
fini
;
...
@@ -1690,8 +1691,7 @@ int PMI_Parse_option(int num_args, char *args[], int *num_parsed,
...
@@ -1690,8 +1691,7 @@ int PMI_Parse_option(int num_args, char *args[], int *num_parsed,
PMI_Free_keyvals
(
temp
,
s
);
PMI_Free_keyvals
(
temp
,
s
);
return
PMI_FAIL
;
return
PMI_FAIL
;
}
}
strncpy
(
temp
[
s
].
key
,
kp
,
len
);
strlcpy
(
temp
[
s
].
key
,
kp
,
len
);
temp
[
s
].
key
[
len
]
=
'\0'
;
if
(
!
IsPmiKey
(
temp
[
s
].
key
))
{
if
(
!
IsPmiKey
(
temp
[
s
].
key
))
{
free
(
temp
[
s
].
key
);
free
(
temp
[
s
].
key
);
temp
[
s
].
key
=
NULL
;
temp
[
s
].
key
=
NULL
;
...
@@ -1707,8 +1707,7 @@ int PMI_Parse_option(int num_args, char *args[], int *num_parsed,
...
@@ -1707,8 +1707,7 @@ int PMI_Parse_option(int num_args, char *args[], int *num_parsed,
PMI_Free_keyvals
(
temp
,
s
+
1
);
PMI_Free_keyvals
(
temp
,
s
+
1
);
return
PMI_FAIL
;
return
PMI_FAIL
;
}
}
strncpy
(
temp
[
s
].
val
,
vp
,
len
);
strlcpy
(
temp
[
s
].
val
,
vp
,
len
);
temp
[
s
].
val
[
len
]
=
'\0'
;
s
++
;
s
++
;
i
++
;
// try next args
i
++
;
// try next args
cp
=
args
[
i
];
cp
=
args
[
i
];
...
@@ -1922,8 +1921,7 @@ int PMI_Get_options(char *str, int *length)
...
@@ -1922,8 +1921,7 @@ int PMI_Get_options(char *str, int *length)
optlen
=
strlen
(
pmi_opt_str
);
optlen
=
strlen
(
pmi_opt_str
);
if
(
*
length
<=
optlen
)
{
if
(
*
length
<=
optlen
)
{
strncpy
(
str
,
pmi_opt_str
,
*
length
-
1
);
strlcpy
(
str
,
pmi_opt_str
,
*
length
);
str
[
*
length
-
1
]
=
'\0'
;
return
PMI_ERR_NOMEM
;
return
PMI_ERR_NOMEM
;
}
}
...
@@ -1937,8 +1935,7 @@ static int IsPmiKey(char * key) {
...
@@ -1937,8 +1935,7 @@ static int IsPmiKey(char * key) {
if
(
pmi_debug
)
if
(
pmi_debug
)
fprintf
(
stderr
,
"In: IsPmiKey
\n
"
);
fprintf
(
stderr
,
"In: IsPmiKey
\n
"
);
strncpy
(
strh
,
key
,
4
);
strlcpy
(
strh
,
key
,
5
);
strh
[
4
]
=
'\0'
;
if
(
!
strcmp
(
strh
,
"PMI_"
)
&&
(
strlen
(
key
)
>
4
))
{
if
(
!
strcmp
(
strh
,
"PMI_"
)
&&
(
strlen
(
key
)
>
4
))
{
return
1
;
return
1
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment