@@ -1300,24 +1300,28 @@ let apply_edition ~__context ~host ~edition ~force =
13001300 apply_edition_internal ~__context ~host ~edition ~additional
13011301
13021302let license_add ~__context ~host ~contents =
1303- let license = Base64. decode contents in
1303+ let license =
1304+ try
1305+ Base64. decode contents
1306+ with _ ->
1307+ error " Base64 decoding of supplied license has failed" ;
1308+ raise Api_errors. (Server_error (license_processing_error, [] ))
1309+ in
13041310 let tmp = " /tmp/new_license" in
1305- let fd = Unix. openfile tmp [Unix. O_WRONLY ; Unix. O_CREAT ] 0o644 in
1306- let length = String. length license in
1307- let written = Unix. write fd license 0 length in
1308- Unix. close fd;
13091311 finally
13101312 (fun () ->
1311- if written <> length then begin
1312- debug " Short write!" ;
1313- raise (Api_errors. Server_error (Api_errors. license_processing_error, [] ))
1313+ begin try
1314+ Unixext. write_string_to_file tmp license
1315+ with _ ->
1316+ let s = " Failed to write temporary file." in
1317+ raise Api_errors. (Server_error (internal_error, [s]))
13141318 end ;
13151319 let edition', features, additional = V6client. apply_edition ~__context " " [" license_file" , tmp] in
13161320 Db.Host. set_edition ~__context ~self: host ~value: edition';
13171321 copy_license_to_db ~__context ~host ~features ~additional
13181322 )
13191323 (fun () ->
1320- (* The language will have been moved to a standard location if it was valid, and
1324+ (* The license will have been moved to a standard location if it was valid, and
13211325 * should be removed otherwise -> always remove the file at the tmp path, if any. *)
13221326 Unixext. unlink_safe tmp
13231327 )
0 commit comments