@@ -458,7 +458,10 @@ np_getschema_print_yang(const struct lys_module *mod, const struct lysp_submodul
458458 len = strrchr (m -> filepath , '/' ) - m -> filepath ;
459459 name = submod ? submod -> name : mod -> name ;
460460 revision = submod ? (submod -> revs ? submod -> revs [0 ].date : NULL ) : mod -> revision ;
461- asprintf (& path , "%.*s/%s%s%s.yang" , len , m -> filepath , name , revision ? "@" : "" , revision ? revision : "" );
461+ if (asprintf (& path , "%.*s/%s%s%s.yang" , len , m -> filepath , name , revision ? "@" : "" , revision ? revision : "" ) == -1 ) {
462+ reply = np_reply_err_op_failed (NULL , ctx , "Memory allocation failed." );
463+ goto cleanup ;
464+ }
462465 filepath = path ;
463466 }
464467
@@ -472,12 +475,21 @@ np_getschema_print_yang(const struct lys_module *mod, const struct lysp_submodul
472475 }
473476
474477 /* learn file size */
475- fseek (f , 0 , SEEK_END );
478+ if (fseek (f , 0 , SEEK_END ) == -1 ) {
479+ asprintf (& msg , "Failed to fseek in \"%s\" (%s)." , filepath , strerror (errno ));
480+ reply = np_reply_err_op_failed (NULL , ctx , msg );
481+ free (msg );
482+ goto cleanup ;
483+ }
476484 len = ftell (f );
477485 fseek (f , 0 , SEEK_SET );
478486
479487 /* read the data */
480488 * yang_data = malloc (len + 1 );
489+ if (!* yang_data ) {
490+ reply = np_reply_err_op_failed (NULL , ctx , "Memory allocation failed." );
491+ goto cleanup ;
492+ }
481493 fread (* yang_data , 1 , len , f );
482494 (* yang_data )[len ] = '\0' ;
483495
0 commit comments