Project

General

Profile

Bug #2253

subscriber create-on-demand random numbers are parsed wrongly

Added by neels over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Target version:
-
Start date:
05/12/2017
Due date:
% Done:

100%

Resolution:
Spec Reference:

Description

Numbers entered in the VTY mismatch the show running-config output.

OpenBSC(config-nitb)# subscriber-create-on-demand random 9570000000 9579999999
OpenBSC(config-nitb)# show running-config
[...]
nitb
subscriber-create-on-demand
subscriber-create-on-demand random 980065408 990065407
assign-tmsi

History

#1 Updated by neels over 3 years ago

The problem is the use of atoi() which truncates to 32bit.
9570000000 & 0xffffffff = 980065408

(even though I'm testing on a 64bit machine, I'm still seeing 32bit truncation by atoi)

#2 Updated by neels over 3 years ago

interestingly enough, atol() and atoll() show the same behavior o_O

▶ cat atoi.c
#include <stdio.h>

int main(int argc, char **argv) {
  long long int x = atoi(argv[1]);
  long long int y = atol(argv[1]);
  long long int z = atoll(argv[1]);
  long long int xx = 9570000000;
  printf("atoi %lld\n", x);
  printf("atol %lld\n", y);
  printf("atoll %lld\n", z);
  printf("xx %lld\n", xx);
  return 0;
}

▶ make atoi
cc     atoi.c   -o atoi

▶ ./atoi 9570000000
atoi 980065408
atol 980065408
atoll 980065408
xx 9570000000

#3 Updated by neels over 3 years ago

That's peculiar. atol* change their behavior depending on whether <stdlib.h> was included or not.

▶ cat atoi2.c 
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
  long long int x = atoi(argv[1]);
  long long int y = atol(argv[1]);
  long long int z = atoll(argv[1]);
  long long int xx = 9570000000;
  printf("atoi %lld\n", x);
  printf("atol %lld\n", y);
  printf("atoll %lld\n", z);
  printf("xx %lld\n", xx);
  return 0;
}

▶ make atoi2
cc     atoi2.c   -o atoi2

▶ ./atoi2 9570000000
atoi 980065408
atol 9570000000
atoll 9570000000
xx 9570000000

#4 Updated by neels over 3 years ago

When the VTY range parsing is fixed, there's more problems during subscriber creation also truncating the extension to 32bit.

#6 Updated by neels over 3 years ago

  • Status changed from New to Resolved
  • Assignee changed from Osmocom CNI Developers to neels
  • % Done changed from 0 to 100

above patches merged.

#7 Updated by laforge over 3 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)