Permalink
Browse files

Merge pull request #8 from mvidner/master

docs; OOM nitpicking ported from SLE
  • Loading branch information...
2 parents 693c95f + 2787659 commit 7e7f977d04c3dc98db9595f71842ce4c4fabc744 @mvidner mvidner committed Dec 19, 2012
Showing with 39 additions and 10 deletions.
  1. +1 −1 VERSION
  2. +29 −7 agent-ini/src/IniParser.cc
  3. +2 −2 agents-perl/lib/ycp.pm
  4. +7 −0 package/yast2-core.changes
View
@@ -1 +1 @@
-2.23.5
+2.23.6
View
@@ -22,6 +22,8 @@
#include <sys/types.h>
#include <glob.h>
#include <cassert>
+#include <cstdarg>
+#include <stdexcept>
#include "IniParser.h"
#include "IniFile.h"
@@ -1021,9 +1023,32 @@ int IniParser::write_file(const string & filename, IniSection & section)
return 0;
}
+/** sprintf to a std::string, throwing runtime_error on OOM */
+std::string format (const char * format, ...) {
+ // copied from y2util/stringutil.h but added the throw
+ // since we don't want to silently corrupt config files
+ char * buf = 0;
+ std::string val;
+
+ va_list ap;
+ va_start( ap, format );
+ int numprinted = vasprintf(&buf, format, ap);
+ va_end( ap );
+
+ if (numprinted >= 0) {
+ val = buf;
+ free( buf );
+ }
+ else {
+ throw std::runtime_error("vasprintf failed in ag_ini. Out of memory?");
+ }
+
+ return val;
+}
+
int IniParser::write_helper(IniSection&ini, ofstream&of, int depth)
{
- char * out_buffer;
+ string out_buffer;
string indent;
string indent2;
int readby = ini.getReadBy ();
@@ -1039,9 +1064,8 @@ int IniParser::write_helper(IniSection&ini, ofstream&of, int depth)
of << ini.getComment();
if (readby>=0 && readby < (int)sections.size ())
{
- asprintf (&out_buffer, sections[readby].begin.out.c_str (), ini.getName());
+ out_buffer = format (sections[readby].begin.out.c_str (), ini.getName());
of << indent << out_buffer << "\n";
- free (out_buffer);
}
IniIterator
@@ -1064,9 +1088,8 @@ int IniParser::write_helper(IniSection&ini, ofstream&of, int depth)
{
const string val = shell_quoted_value ? YaST::agent_ini::quote(e.getValue()) : e.getValue();
// bnc#492859, a fixed buffer is too small
- asprintf (&out_buffer, params[e.getReadBy ()].line.out.c_str (), e.getName(), val.c_str());
+ out_buffer = format (params[e.getReadBy ()].line.out.c_str (), e.getName(), val.c_str());
of << indent2 << out_buffer << "\n";
- free(out_buffer);
}
e.clean();
}
@@ -1076,9 +1099,8 @@ int IniParser::write_helper(IniSection&ini, ofstream&of, int depth)
of << indent << ini.getEndComment();
if (readby>=0 && readby < (int) sections.size () && sections[readby].end_valid)
{
- asprintf (&out_buffer, sections[readby].end.out.c_str (), ini.getName());
+ out_buffer = format (sections[readby].end.out.c_str (), ini.getName());
of << indent << out_buffer << "\n";
- free(out_buffer);
}
ini.clean();
return 0;
View
@@ -18,7 +18,6 @@
# Purpose: Call a perl script within a YCP script
#
#----------------------------------------------------------------------
-# $Id$
package ycp;
@@ -633,7 +632,8 @@ If a second argument exists and is true, all scalars are written as strings.
If a second argument exists and is false, all scalars are written as byteblocks.
To send a list, call Return(\@list), not Return(@list).
-Similarly for a map. You can use references to anonymous lists [] and hashes {}.
+Similarly for a map.
+You can produce references to anonymous lists with [] and hashes with {}.
The difference from L</ycpReturn> is that Return can return scalars directly,
strings are properly escaped if needeed and paths can be returned.
@@ -1,7 +1,14 @@
-------------------------------------------------------------------
+Mon Oct 8 16:50:38 CEST 2012 - mvidner@suse.cz
+
+- Clarified how to return lists and maps from Perl (bnc#783846).
+- 2.23.6
+
+-------------------------------------------------------------------
Wed Jul 11 14:55:26 CEST 2012 - mvidner@suse.cz
- automake incompatibility: require 1.12, to produce parser.hh
+- agent-ini: if we cannot format a string, fail loudly (bnc#763386#c10)
-------------------------------------------------------------------
Wed Jul 11 12:07:52 CEST 2012 - fehr@suse.de

0 comments on commit 7e7f977

Please sign in to comment.