@@ -325,14 +325,14 @@ static char *hyper_resolve_link(char *path)
325325 * as if we were in a chroot jail.
326326 *
327327 * @root: chroot jail path.
328- * @parent: what's already created to the target directory.
329328 * @path: target directory. It is always relative to @root even if it starts with /.
329+ * @parent: what's already created to the target directory.
330330 * @mode: directory mode.
331331 * @link_max: max number of symlinks to follow.
332332 *
333333 * Upon success, @parent is changed to point to resolved path name.
334334 */
335- static int hyper_mkdir_follow_link (char * root , char * parent , char * path ,
335+ static int hyper_mkdir_follow_link (const char * root , const char * path , char * parent ,
336336 mode_t mode , int * link_max )
337337{
338338 char * comp , * prev , * link , * dummy , * npath , * delim = "/" ;
@@ -396,7 +396,7 @@ static int hyper_mkdir_follow_link(char *root, char *parent, char *path,
396396 } else {
397397 * prev = '\0' ; /* drop current comp */
398398 }
399- if (hyper_mkdir_follow_link (root , parent , link , mode , link_max ) < 0 ) {
399+ if (hyper_mkdir_follow_link (root , link , parent , mode , link_max ) < 0 ) {
400400 free (link );
401401 goto out ;
402402 }
@@ -425,21 +425,26 @@ static int hyper_mkdir_follow_link(char *root, char *parent, char *path,
425425/*
426426 * hyper_mkdir_at() is similar to hyper_mkdir() with the exception that
427427 * when there are symlinks in the path components, it acts as if we created
428- * directories in a chroot jail. @path is always considered relative to root
429- * even if it starts with a leading stash ('/').
428+ * directories in a chroot jail. @hyper_path is always considered relative
429+ * to root even if it starts with a leading stash ('/').
430430 *
431- * Upon success, return symlink expanded result .
431+ * Upon success, @hyper_path is modified to save resolved path in chroot jail .
432432 */
433- char * hyper_mkdir_at (char * root , char * path , mode_t mode )
433+ int hyper_mkdir_at (const char * root , char * hyper_path , int size )
434434{
435435 char result [512 ];
436436 int max_link = 40 ;
437437
438438 sprintf (result , "%s" , root );
439- if (hyper_mkdir_follow_link (root , result , path , mode , & max_link ) < 0 )
440- return NULL ;
439+ if (hyper_mkdir_follow_link (root , hyper_path , result , 0755 , & max_link ) < 0 )
440+ return -1 ;
441441
442- return strdup (result );
442+ if (strlen (result ) + 1 > size ) {
443+ errno = ENAMETOOLONG ;
444+ return -1 ;
445+ }
446+ sprintf (hyper_path , "%s" , result );
447+ return 0 ;
443448}
444449
445450int hyper_mkdir (char * path , mode_t mode )
0 commit comments