Skip to content

Commit

Permalink
fixed #1 prefix2long integer overflow on 64bit machine
Browse files Browse the repository at this point in the history
  • Loading branch information
Joungkyun committed Jul 9, 2016
1 parent 0b9365c commit 0fa2464
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Changelog

* 1.0.3

Sat, Jul 09 2016 JoungKyun.Kim <http://oops.og>
- fixed #1 prefix2long integer overflow on 64bit machine

Thu, Feb 13 2014 JoungKyun.Kim <http://oops.org>
- support native window library and binaries with MinGW
- add Code::Block workspace
Expand Down
7 changes: 6 additions & 1 deletion common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 JoungKyun.Kim <http://oops.org>
* Copyright (c) 2016 JoungKyun.Kim <http://oops.org/>. All rights reserved.
*
* This file is part of libipcalc.
*
Expand Down Expand Up @@ -64,6 +64,11 @@
#define IPCALC_VERSION "1.0.3"
#define IPCALC_UVERSION "001000003"

#ifdef UINT_MAX
#undef UINT_MAX
#endif
#define UINT_MAX 4294967296U

#endif

/*
Expand Down
23 changes: 17 additions & 6 deletions ipcalc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 JoungKyun.Kim <http://oops.org>
* Copyright (c) 2016 JoungKyun.Kim <http://oops.org/>. All rights reserved.
*
* This file is part of libipcalc.
*
Expand All @@ -24,8 +24,8 @@
* This library support API for IP calculating and subnetting.
*
* @author JoungKyun.Kim <http://oops.org>
* $Date$
* $Revision$
* $Date: $
* $Revision: $
* @attention Copyright (c) 2016 JoungKyun.Kim all rights reserved.
*/

Expand Down Expand Up @@ -149,11 +149,13 @@ IPCALC_API short long2prefix (ulong mask) { // {{{
return count;
} // }}}


/*
* convert network prefix to long mask
* from ipcalc from initscripts on redhat
*
* This is internal api and enable 32bit integer overflow!
*/
IPCALC_API ulong prefix2long (short n) { // {{{
ulong _prefix2long (short n) { // {{{
short l = 32;
short shift = 30;
ulong v = 0;
Expand All @@ -173,6 +175,15 @@ IPCALC_API ulong prefix2long (short n) { // {{{
return v;
} // }}}

/*
* convert network prefix to long mask
*/
IPCALC_API ulong prefix2long (short n) { // {{{
ulong r = _prefix2long (n);

return (r > UINT_MAX) ? r % UINT_MAX : r;
} // }}}

/*
* return netmask prefix with start ip and end ip
*/
Expand Down Expand Up @@ -202,7 +213,7 @@ IPCALC_API short guess_prefix (ulong s, ulong e) { // {{{
if ( n > 0 )
prefix--;

n = broadcast (s, prefix2long (prefix));
n = broadcast (s, _prefix2long (prefix));
}

return prefix;
Expand Down

0 comments on commit 0fa2464

Please sign in to comment.