Skip to content

Commit 1603ae5

Browse files
committed
mini: fix silent failure on meta-key insertion
fixes ElektraInitiative#4582
1 parent 6a6d1bf commit 1603ae5

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

doc/news/_preparation_next_release.md

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ The following text lists news about the [plugins](https://www.libelektra.org/plu
160160
- Add encoding test for blockresolver read _(@dtdirect)_
161161
- Refactor and restructure blockresolver _(@dtdirect)_
162162

163+
### mini
164+
165+
- Fix a bug where writing meta keys will fail silently _(Juri Schreib @Bujuhu)_
166+
- <<TODO>>
167+
- <<TODO>>
168+
163169
### mmapstorage
164170

165171
- Remove code duplication in the data block calculation _(Richard Stöckl @Eiskasten)_

src/plugins/mini/mini.c

+28
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,37 @@ int elektraMiniGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * par
317317
return parseFile (returned, parentKey);
318318
}
319319

320+
321+
static bool elektraCheckForInvalidMetaKey (Key * parentKey, KeySet * ks)
322+
{
323+
Key * cur = 0;
324+
for (elektraCursor it = 0; it < ksGetSize (ks); ++it)
325+
{
326+
cur = ksAtCursor (ks, it);
327+
const KeySet * metaKeys = keyMeta (cur);
328+
for (elektraCursor jt = 0; jt < ksGetSize (metaKeys); ++jt)
329+
{
330+
// We reach her iff we try to set a metakey. Therefore we should t
331+
const Key * meta = ksAtCursor (metaKeys, jt);
332+
const char * pos = (const char *) keyName (meta);
333+
if (elektraStrNCmp (pos, "meta:/internal/mini", 19) != 0 && elektraStrCmp (pos, "meta:/origname") && elektraStrNCmp (pos, "meta:/rename", 12) != 0 && elektraStrCmp (pos, "meta:/binary") != 0)
334+
{
335+
ELEKTRA_SET_RESOURCE_ERRORF (parentKey, "The mini storage Plugin doesn't support the met key %s", pos);
336+
return false;
337+
}
338+
}
339+
}
340+
return true;
341+
}
342+
320343
/** @see elektraDocSet */
321344
int elektraMiniSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
322345
{
346+
if (!elektraCheckForInvalidMetaKey (parentKey, returned))
347+
{
348+
return ELEKTRA_PLUGIN_STATUS_ERROR;
349+
}
350+
323351
ELEKTRA_LOG ("Write configuration data");
324352
int errorNumber = errno;
325353
FILE * destination = fopen (keyString (parentKey), "w");

src/plugins/mini/testmod_mini.c

+16
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ static void test_set (void)
113113
PLUGIN_CLOSE ();
114114
}
115115

116+
static void test_setMetaMustFail (void)
117+
{
118+
char const * const prefix = "user:/mini/tests/writeMeta";
119+
120+
Key * parentKey = keyNew (prefix, KEY_VALUE, elektraFilename (), KEY_END);
121+
KeySet * conf = ksNew (0, KS_END);
122+
KeySet * ks = ksNew (1, keyNew ("user:/mini/tests/writeMeta", KEY_VALUE, "asdf", KEY_META, "asdf", "asdf", KEY_END), KS_END);
123+
124+
PLUGIN_OPEN ("mini");
125+
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "Attempting to write a Meta Key did not fail");
126+
keyDel (parentKey);
127+
ksDel (ks);
128+
PLUGIN_CLOSE ();
129+
}
130+
116131
/* -- Main ------------------------------------------------------------------------------------------------------------------------------ */
117132

118133
int main (int argc, char ** argv)
@@ -125,6 +140,7 @@ int main (int argc, char ** argv)
125140
test_basics ();
126141
test_get ();
127142
test_set ();
143+
test_setMetaMustFail ();
128144

129145
print_result ("testmod_mini");
130146

stderr

Whitespace-only changes.

stdout

Whitespace-only changes.

0 commit comments

Comments
 (0)