@@ -146,7 +146,10 @@ static int container_setup_volume(struct hyper_pod *pod,
146
146
if (hyper_mount_nfs (vol -> device , path ) < 0 )
147
147
return -1 ;
148
148
/* nfs export has implicitly included _data part of the volume */
149
- sprintf (volume , "/%s/" , path );
149
+ if (snprintf (volume , 512 , "/%s/" , path ) < strlen ("//" )) {
150
+ fprintf (stderr , "something wrong with volume generation\n" );
151
+ return -1 ;
152
+ }
150
153
} else {
151
154
fprintf (stdout , "mount %s to %s, tmp path %s\n" ,
152
155
dev , vol -> mountpoint , path );
@@ -164,7 +167,10 @@ static int container_setup_volume(struct hyper_pod *pod,
164
167
perror ("mount volume device failed" );
165
168
return -1 ;
166
169
}
167
- sprintf (volume , "/%s/_data" , path );
170
+ if (snprintf (volume , 512 , "/%s/_data" , path ) < strlen ("/_data" )) {
171
+ fprintf (stderr , "something wrong with volume generation\n" );
172
+ return -1 ;
173
+ }
168
174
}
169
175
170
176
if (container_check_volume (volume , & filevolume , & newvolume ) < 0 )
@@ -193,7 +199,10 @@ static int container_setup_volume(struct hyper_pod *pod,
193
199
perror ("create volume file failed" );
194
200
return -1 ;
195
201
}
196
- sprintf (volume , "/%s/_data/%s" , path , filevolume );
202
+ if (snprintf (volume , 512 , "/%s/_data/%s" , path , filevolume ) < strlen (path )) {
203
+ fprintf (stderr , "something wrong with volume generation\n" );
204
+ return -1 ;
205
+ }
197
206
/* 0777 so that any user can read/write the new file volume */
198
207
if (chmod (volume , 0777 ) < 0 ) {
199
208
fprintf (stderr , "fail to chmod directory %s\n" , volume );
@@ -235,7 +244,10 @@ static int container_setup_volume(struct hyper_pod *pod,
235
244
}
236
245
if (map -> docker ) {
237
246
/* converted from volume */
238
- sprintf (volume , "%s/_data" , path );
247
+ if (snprintf (volume , 512 , "%s/_data" , path ) < strlen ("/_data" )) {
248
+ fprintf (stderr , "something wrong with volume generation\n" );
249
+ return -1 ;
250
+ }
239
251
src = volume ;
240
252
if (container -> initialize &&
241
253
(container_populate_volume (mountpoint , volume ) < 0 )) {
@@ -279,7 +291,10 @@ static int container_setup_modules(struct hyper_container *container)
279
291
}
280
292
281
293
sprintf (src , "/lib/modules/%s" , uts .release );
282
- sprintf (dst , "./%s" , src );
294
+ if (snprintf (dst , 512 , "./%s" , src ) < 3 ) {
295
+ fprintf (stderr , "something wrong with dst generation\n" );
296
+ return -1 ;
297
+ }
283
298
284
299
if (stat (dst , & st ) == 0 ) {
285
300
struct dirent * * list ;
@@ -657,7 +672,10 @@ static int hyper_setup_container_rootfs(void *data)
657
672
fprintf (stdout , "root directory for container is %s/%s, init task %s\n" ,
658
673
root , container -> rootfs , container -> exec .argv [0 ]);
659
674
660
- sprintf (rootfs , "%s/%s/" , root , container -> rootfs );
675
+ if (snprintf (rootfs , 512 , "%s/%s/" , root , container -> rootfs ) < 2 ) {
676
+ fprintf (stderr , "something wrong with rootfs generation\n" );
677
+ goto fail ;
678
+ }
661
679
if (mount (rootfs , rootfs , NULL , MS_BIND |MS_REC , NULL ) < 0 ) {
662
680
perror ("failed to bind rootfs" );
663
681
goto fail ;
0 commit comments