Project

General

Profile

Actions

Bug #310

closed

String undefined

Added by iri about 13 years ago. Updated about 13 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
VM_Kernel
Target version:
-
Start date:
03/05/2011
Due date:
% Done:

0%

Estimated time:

Description

When a string is undefined in the Scol machine, it takes the value "INET".

An basic example with the function _checkpack :

Scol code (a/b/c doesn't exist) :

fun test ()=
  _fooS stringTest _checkpack "a/b/c";
  ...

C (or C++) code :

/* fun [P] S */
int stringTest (mmachine m)
{
  int p;
  p = MTOP (MMpull (m));
  Mpushstrbloc (m, MMstartstr (m, p));
  return 0;
}

The console always displays :

INET

This example use _checkpack but others strings are to be considered.

To see the reason (and never use a P argument without test)

Actions #1

Updated by arkeon about 13 years ago

This is why you need to test the param value before calling any MMfetch or MMstartstr and any MTOI, MTOP, MTOF ..
Null value exist in the Scol stack and return INET because this is the first registered element in the stack

the correct and secure code should be something like :

/* fun [P] S */
int stringTest (mmachine m)
{
  int p;
  p = MMpull (m);
  if (p == NIL)
  {
    MMpush (m, NIL);
    return 0;
  }

  Mpushstrbloc (m, MMstartstr (m, MTOP(p)));
  return 0;
}

Actions #2

Updated by iri about 13 years ago

Of course, my example was ... an example : show the result when the value is at NULL. It's not specific at _checkpack.

This "INET" return is a problem, i think. It is unsafe. So i posted. A NIL value should be better. No ?

Actions #3

Updated by arkeon about 13 years ago

I think that it will not be possible at this point, since any MMstartstr param int value are good even NIL (-1)

Actions #4

Updated by iri about 13 years ago

Hum, not MMsizestr, but Mpushstrbloc. The value should be tested and, if NULL, NIL should be pushed.

Explanation in french, sorry.
Tu as une chaîne non null. Tu lui fais passer divers traitements "anodins" (mais rien n'est jamais anodin en programmation, n'est ce pas !). À la sortie, la chaîne devrait encore avoir une valeur non null. Tu l'empiles alors sur le tas (Mpushstrbloc).
Pourtant, dans certains cas non prévus, cette chaîne se retrouve à null. Testes-tu systématiquement ta chaîne juste avant de l'empiler ? Nous devrions, c'est vrai.

L'ennui, c'est que le tas ne contient pas une chaine nulle ! Donc, lors de son utilisation future, quand tu fais :
int s = MMpull (m); if (s == NIL) ...
s ne vaut pas NIL mais a bien une valeur. Et le programme foire car le contenu de s n'est pas celui attendu ...

Si je pouvais compiler le kernel avec des outils libres, je ferais ces modifs moi-même. Comme cela m'est impossible, j'envoie le bug.

Actions #5

Updated by iri about 13 years ago

  • Status changed from New to Closed

Arf non, Mpushstrbloc teste bien la valeur et renvoie NIL sir la chaine est NULL. Je ne comprend pas ... Je ferme cette entrée.

Actions

Also available in: Atom PDF