@@ -81,8 +81,7 @@ static int parse_subpart(struct cmdline_subpart **subpart, char *partdef)
81
81
82
82
length = min_t (int , next - partdef ,
83
83
sizeof (new_subpart -> name ) - 1 );
84
- strncpy (new_subpart -> name , partdef , length );
85
- new_subpart -> name [length ] = '\0' ;
84
+ strscpy (new_subpart -> name , partdef , length );
86
85
87
86
partdef = ++ next ;
88
87
} else
@@ -140,8 +139,7 @@ static int parse_parts(struct cmdline_parts **parts, const char *bdevdef)
140
139
}
141
140
142
141
length = min_t (int , next - bdevdef , sizeof (newparts -> name ) - 1 );
143
- strncpy (newparts -> name , bdevdef , length );
144
- newparts -> name [length ] = '\0' ;
142
+ strscpy (newparts -> name , bdevdef , length );
145
143
newparts -> nr_subparts = 0 ;
146
144
147
145
next_subpart = & newparts -> subpart ;
@@ -153,8 +151,7 @@ static int parse_parts(struct cmdline_parts **parts, const char *bdevdef)
153
151
length = (!next ) ? (sizeof (buf ) - 1 ) :
154
152
min_t (int , next - bdevdef , sizeof (buf ) - 1 );
155
153
156
- strncpy (buf , bdevdef , length );
157
- buf [length ] = '\0' ;
154
+ strscpy (buf , bdevdef , length );
158
155
159
156
ret = parse_subpart (next_subpart , buf );
160
157
if (ret )
@@ -267,8 +264,7 @@ static int add_part(int slot, struct cmdline_subpart *subpart,
267
264
268
265
label_min = min_t (int , sizeof (info -> volname ) - 1 ,
269
266
sizeof (subpart -> name ));
270
- strncpy (info -> volname , subpart -> name , label_min );
271
- info -> volname [label_min ] = '\0' ;
267
+ strscpy (info -> volname , subpart -> name , label_min );
272
268
273
269
snprintf (tmp , sizeof (tmp ), "(%s)" , info -> volname );
274
270
strlcat (state -> pp_buf , tmp , PAGE_SIZE );
0 commit comments