]> WPIA git - cassiopeia.git/blobdiff - src/util.cpp
fix: Properly check for success to create the necessary directories
[cassiopeia.git] / src / util.cpp
index f3d95c0ad522f3933ab1e7e57bf94d445a28d715..5cf30da1d2dac01576e6ce5dce6dbaa4f845add4 100644 (file)
@@ -25,10 +25,17 @@ std::string readFile( const std::string& name ) {
 }
 
 std::string writeBackFile( const std::string& serial, const std::string& cert, const std::string& keydir ) {
+    errno = 0;
+
     std::string filename = keydir;
-    mkdir( filename.c_str(), 0755 );
+    if( 0 != mkdir( filename.c_str(), 0755 ) ) {
+        return "";
+    }
+
     filename += "/crt";
-    mkdir( filename.c_str(), 0755 );
+    if( 0 != mkdir( filename.c_str(), 0755 ) ) {
+        return "";
+    }
     std::string first;
 
     if( serial.length() < 3 ) {
@@ -38,12 +45,15 @@ std::string writeBackFile( const std::string& serial, const std::string& cert, c
     }
 
     filename += "/" + first;
-    mkdir( filename.c_str(), 0755 );
+    if( 0 != mkdir( filename.c_str(), 0755 ) ) {
+        return "";
+    }
     filename += "/" + serial + ".crt";
     writeFile( filename, cert );
 
     return filename;
 }
+
 bool isDigit( char c ) {
     return ( c >= '0' ) && ( c <= '9' );
 }
@@ -78,7 +88,7 @@ std::pair<bool, time_t> parseDate( const std::string& date ) {
     std::size_t siz = strftime( check, 11, "%Y-%m-%d", &t );
 
     if( siz != 10 ) {
-        return std::pair<bool, time_t>( false, 0 );
+        return std::pair<bool, time_t>( false, 0 ); // NO-COVERAGE (by contract of strftime)
     }
 
     std::string checkS( check, siz );